2 * Copyright (c) 2018 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>
28 #include <dali/devel-api/adaptor-framework/key-devel.h>
31 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
32 #include <dali-toolkit/internal/text/bidirectional-support.h>
33 #include <dali-toolkit/internal/text/character-set-conversion.h>
34 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
35 #include <dali-toolkit/internal/text/markup-processor.h>
36 #include <dali-toolkit/internal/text/multi-language-support.h>
37 #include <dali-toolkit/internal/text/text-controller-impl.h>
38 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
39 #include <dali-toolkit/internal/text/text-font-style.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
48 const float MAX_FLOAT = std::numeric_limits<float>::max();
50 const std::string EMPTY_STRING("");
52 const std::string KEY_C_NAME = "c";
53 const std::string KEY_V_NAME = "v";
54 const std::string KEY_X_NAME = "x";
56 const char * const PLACEHOLDER_TEXT = "text";
57 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
58 const char * const PLACEHOLDER_COLOR = "color";
59 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
60 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
61 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
62 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
63 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 float ConvertToEven( float value )
67 int intValue(static_cast<int>( value ));
68 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
83 * @brief Adds a new font description run for the selected text.
85 * The new font parameters are added after the call to this method.
87 * @param[in] eventData The event data pointer.
88 * @param[in] logicalModel The logical model where to add the new font description run.
89 * @param[out] startOfSelectedText Index to the first selected character.
90 * @param[out] lengthOfSelectedText Number of selected characters.
92 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
93 LogicalModelPtr logicalModel,
94 CharacterIndex& startOfSelectedText,
95 Length& lengthOfSelectedText )
97 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
99 // Get start and end position of selection
100 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
101 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
104 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
105 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
107 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
109 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
110 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
112 // Recalculate the selection highlight as the metrics may have changed.
113 eventData->mUpdateLeftSelectionPosition = true;
114 eventData->mUpdateRightSelectionPosition = true;
115 eventData->mUpdateHighlightBox = true;
117 return fontDescriptionRun;
120 // public : Constructor.
122 ControllerPtr Controller::New()
124 return ControllerPtr( new Controller() );
127 ControllerPtr Controller::New( ControlInterface* controlInterface )
129 return ControllerPtr( new Controller( controlInterface ) );
132 ControllerPtr Controller::New( ControlInterface* controlInterface,
133 EditableControlInterface* editableControlInterface )
135 return ControllerPtr( new Controller( controlInterface,
136 editableControlInterface ) );
139 // public : Configure the text controller.
141 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
145 delete mImpl->mEventData;
146 mImpl->mEventData = NULL;
148 // Nothing else to do.
152 if( NULL == mImpl->mEventData )
154 mImpl->mEventData = new EventData( decorator, inputMethodContext );
158 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
160 // Metrics for bitmap & vector based glyphs are different
161 mImpl->mMetrics->SetGlyphType( glyphType );
163 // Clear the font-specific data
166 mImpl->RequestRelayout();
169 void Controller::SetMarkupProcessorEnabled( bool enable )
171 if( enable != mImpl->mMarkupProcessorEnabled )
173 //If Text was already set, call the SetText again for enabling or disabling markup
174 mImpl->mMarkupProcessorEnabled = enable;
181 bool Controller::IsMarkupProcessorEnabled() const
183 return mImpl->mMarkupProcessorEnabled;
186 void Controller::SetAutoScrollEnabled( bool enable )
188 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 );
190 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
194 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
195 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
205 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
206 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
213 mImpl->mIsAutoScrollEnabled = enable;
214 mImpl->RequestRelayout();
218 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
219 mImpl->mIsAutoScrollEnabled = false;
223 bool Controller::IsAutoScrollEnabled() const
225 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
227 return mImpl->mIsAutoScrollEnabled;
230 CharacterDirection Controller::GetAutoScrollDirection() const
232 return mImpl->mIsTextDirectionRTL;
235 float Controller::GetAutoScrollLineAlignment() const
239 if( mImpl->mModel->mVisualModel &&
240 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
242 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
248 void Controller::SetHorizontalScrollEnabled( bool enable )
250 if( ( NULL != mImpl->mEventData ) &&
251 mImpl->mEventData->mDecorator )
253 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
256 bool Controller::IsHorizontalScrollEnabled() const
258 if( ( NULL != mImpl->mEventData ) &&
259 mImpl->mEventData->mDecorator )
261 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
267 void Controller::SetVerticalScrollEnabled( bool enable )
269 if( ( NULL != mImpl->mEventData ) &&
270 mImpl->mEventData->mDecorator )
272 if( mImpl->mEventData->mDecorator )
274 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
279 bool Controller::IsVerticalScrollEnabled() const
281 if( ( NULL != mImpl->mEventData ) &&
282 mImpl->mEventData->mDecorator )
284 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
290 void Controller::SetSmoothHandlePanEnabled( bool enable )
292 if( ( NULL != mImpl->mEventData ) &&
293 mImpl->mEventData->mDecorator )
295 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
299 bool Controller::IsSmoothHandlePanEnabled() const
301 if( ( NULL != mImpl->mEventData ) &&
302 mImpl->mEventData->mDecorator )
304 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
310 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
312 mImpl->mMaximumNumberOfCharacters = maxCharacters;
315 int Controller::GetMaximumNumberOfCharacters()
317 return mImpl->mMaximumNumberOfCharacters;
320 void Controller::SetEnableCursorBlink( bool enable )
322 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
324 if( NULL != mImpl->mEventData )
326 mImpl->mEventData->mCursorBlinkEnabled = enable;
329 mImpl->mEventData->mDecorator )
331 mImpl->mEventData->mDecorator->StopCursorBlink();
336 bool Controller::GetEnableCursorBlink() const
338 if( NULL != mImpl->mEventData )
340 return mImpl->mEventData->mCursorBlinkEnabled;
346 void Controller::SetMultiLineEnabled( bool enable )
348 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
350 if( layout != mImpl->mLayoutEngine.GetLayout() )
352 // Set the layout type.
353 mImpl->mLayoutEngine.SetLayout( layout );
355 // Set the flags to redo the layout operations
356 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
361 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
362 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
364 mImpl->RequestRelayout();
368 bool Controller::IsMultiLineEnabled() const
370 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
373 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
375 if( alignment != mImpl->mModel->mHorizontalAlignment )
377 // Set the alignment.
378 mImpl->mModel->mHorizontalAlignment = alignment;
380 // Set the flag to redo the alignment operation.
381 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
383 mImpl->RequestRelayout();
387 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
389 return mImpl->mModel->mHorizontalAlignment;
392 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
394 if( alignment != mImpl->mModel->mVerticalAlignment )
396 // Set the alignment.
397 mImpl->mModel->mVerticalAlignment = alignment;
399 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
401 mImpl->RequestRelayout();
405 VerticalAlignment::Type Controller::GetVerticalAlignment() const
407 return mImpl->mModel->mVerticalAlignment;
410 bool Controller::IsIgnoreSpacesAfterText() const
412 return mImpl->mModel->mIgnoreSpacesAfterText;
415 void Controller::SetIgnoreSpacesAfterText( bool ignore )
417 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
420 bool Controller::IsMatchSystemLanguageDirection() const
422 return mImpl->mModel->mMatchSystemLanguageDirection;
425 void Controller::SetMatchSystemLanguageDirection( bool match )
427 mImpl->mModel->mMatchSystemLanguageDirection = match;
430 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
432 mImpl->mLayoutDirection = layoutDirection;
436 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
438 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
440 // Set the text wrap mode.
441 mImpl->mModel->mLineWrapMode = lineWrapMode;
444 // Update Text layout for applying wrap mode
445 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
450 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
451 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
452 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
455 mImpl->RequestRelayout();
459 Text::LineWrap::Mode Controller::GetLineWrapMode() const
461 return mImpl->mModel->mLineWrapMode;
464 void Controller::SetTextElideEnabled( bool enabled )
466 mImpl->mModel->mElideEnabled = enabled;
469 bool Controller::IsTextElideEnabled() const
471 return mImpl->mModel->mElideEnabled;
474 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
476 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
477 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
479 // Update placeholder if there is no text
480 if( mImpl->IsShowingPlaceholderText() ||
481 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
483 ShowPlaceholderText();
487 bool Controller::IsPlaceholderTextElideEnabled() const
489 return mImpl->mEventData->mIsPlaceholderElideEnabled;
492 void Controller::SetSelectionEnabled( bool enabled )
494 mImpl->mEventData->mSelectionEnabled = enabled;
497 bool Controller::IsSelectionEnabled() const
499 return mImpl->mEventData->mSelectionEnabled;
502 void Controller::SetShiftSelectionEnabled( bool enabled )
504 mImpl->mEventData->mShiftSelectionFlag = enabled;
507 bool Controller::IsShiftSelectionEnabled() const
509 return mImpl->mEventData->mShiftSelectionFlag;
512 void Controller::SetGrabHandleEnabled( bool enabled )
514 mImpl->mEventData->mGrabHandleEnabled = enabled;
517 bool Controller::IsGrabHandleEnabled() const
519 return mImpl->mEventData->mGrabHandleEnabled;
524 void Controller::SetText( const std::string& text )
526 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
528 // Reset keyboard as text changed
529 mImpl->ResetInputMethodContext();
531 // Remove the previously set text and style.
537 CharacterIndex lastCursorIndex = 0u;
539 if( NULL != mImpl->mEventData )
541 // If popup shown then hide it by switching to Editing state
542 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
543 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
544 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
545 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
547 mImpl->ChangeState( EventData::EDITING );
553 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
555 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
556 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
558 Length textSize = 0u;
559 const uint8_t* utf8 = NULL;
560 if( mImpl->mMarkupProcessorEnabled )
562 ProcessMarkupString( text, markupProcessData );
563 textSize = markupProcessData.markupProcessedText.size();
565 // This is a bit horrible but std::string returns a (signed) char*
566 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
570 textSize = text.size();
572 // This is a bit horrible but std::string returns a (signed) char*
573 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
576 // Convert text into UTF-32
577 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
578 utf32Characters.Resize( textSize );
580 // Transform a text array encoded in utf8 into an array encoded in utf32.
581 // It returns the actual number of characters.
582 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
583 utf32Characters.Resize( characterCount );
585 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
586 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
588 // The characters to be added.
589 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
591 // To reset the cursor position
592 lastCursorIndex = characterCount;
594 // Update the rest of the model during size negotiation
595 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
597 // The natural size needs to be re-calculated.
598 mImpl->mRecalculateNaturalSize = true;
600 // The text direction needs to be updated.
601 mImpl->mUpdateTextDirection = true;
603 // Apply modifications to the model
604 mImpl->mOperationsPending = ALL_OPERATIONS;
608 ShowPlaceholderText();
611 // Resets the cursor position.
612 ResetCursorPosition( lastCursorIndex );
614 // Scrolls the text to make the cursor visible.
615 ResetScrollPosition();
617 mImpl->RequestRelayout();
619 if( NULL != mImpl->mEventData )
621 // Cancel previously queued events
622 mImpl->mEventData->mEventQueue.clear();
625 // Do this last since it provides callbacks into application code.
626 if( NULL != mImpl->mEditableControlInterface )
628 mImpl->mEditableControlInterface->TextChanged();
632 void Controller::GetText( std::string& text ) const
634 if( !mImpl->IsShowingPlaceholderText() )
636 // Retrieves the text string.
637 mImpl->GetText( 0u, text );
641 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
645 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
647 if( NULL != mImpl->mEventData )
649 if( PLACEHOLDER_TYPE_INACTIVE == type )
651 mImpl->mEventData->mPlaceholderTextInactive = text;
655 mImpl->mEventData->mPlaceholderTextActive = text;
658 // Update placeholder if there is no text
659 if( mImpl->IsShowingPlaceholderText() ||
660 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
662 ShowPlaceholderText();
667 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
669 if( NULL != mImpl->mEventData )
671 if( PLACEHOLDER_TYPE_INACTIVE == type )
673 text = mImpl->mEventData->mPlaceholderTextInactive;
677 text = mImpl->mEventData->mPlaceholderTextActive;
682 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
684 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
686 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
688 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
689 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
693 mImpl->RequestRelayout();
697 // public : Default style & Input style
699 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
701 if( NULL == mImpl->mFontDefaults )
703 mImpl->mFontDefaults = new FontDefaults();
706 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
707 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
708 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
710 // Clear the font-specific data
713 mImpl->RequestRelayout();
716 const std::string& Controller::GetDefaultFontFamily() const
718 if( NULL != mImpl->mFontDefaults )
720 return mImpl->mFontDefaults->mFontDescription.family;
726 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
728 if( NULL != mImpl->mEventData )
730 if( NULL == mImpl->mEventData->mPlaceholderFont )
732 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
735 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
736 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
737 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
739 mImpl->RequestRelayout();
743 const std::string& Controller::GetPlaceholderFontFamily() const
745 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
747 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
753 void Controller::SetDefaultFontWeight( FontWeight weight )
755 if( NULL == mImpl->mFontDefaults )
757 mImpl->mFontDefaults = new FontDefaults();
760 mImpl->mFontDefaults->mFontDescription.weight = weight;
761 mImpl->mFontDefaults->weightDefined = true;
763 // Clear the font-specific data
766 mImpl->RequestRelayout();
769 bool Controller::IsDefaultFontWeightDefined() const
771 if( NULL != mImpl->mFontDefaults )
773 return mImpl->mFontDefaults->weightDefined;
779 FontWeight Controller::GetDefaultFontWeight() const
781 if( NULL != mImpl->mFontDefaults )
783 return mImpl->mFontDefaults->mFontDescription.weight;
786 return TextAbstraction::FontWeight::NORMAL;
789 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
791 if( NULL != mImpl->mEventData )
793 if( NULL == mImpl->mEventData->mPlaceholderFont )
795 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
798 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
799 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
801 mImpl->RequestRelayout();
805 bool Controller::IsPlaceholderTextFontWeightDefined() const
807 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
809 return mImpl->mEventData->mPlaceholderFont->weightDefined;
814 FontWeight Controller::GetPlaceholderTextFontWeight() const
816 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
818 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
821 return TextAbstraction::FontWeight::NORMAL;
824 void Controller::SetDefaultFontWidth( FontWidth width )
826 if( NULL == mImpl->mFontDefaults )
828 mImpl->mFontDefaults = new FontDefaults();
831 mImpl->mFontDefaults->mFontDescription.width = width;
832 mImpl->mFontDefaults->widthDefined = true;
834 // Clear the font-specific data
837 mImpl->RequestRelayout();
840 bool Controller::IsDefaultFontWidthDefined() const
842 if( NULL != mImpl->mFontDefaults )
844 return mImpl->mFontDefaults->widthDefined;
850 FontWidth Controller::GetDefaultFontWidth() const
852 if( NULL != mImpl->mFontDefaults )
854 return mImpl->mFontDefaults->mFontDescription.width;
857 return TextAbstraction::FontWidth::NORMAL;
860 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
862 if( NULL != mImpl->mEventData )
864 if( NULL == mImpl->mEventData->mPlaceholderFont )
866 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
869 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
870 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
872 mImpl->RequestRelayout();
876 bool Controller::IsPlaceholderTextFontWidthDefined() const
878 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
880 return mImpl->mEventData->mPlaceholderFont->widthDefined;
885 FontWidth Controller::GetPlaceholderTextFontWidth() const
887 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
889 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
892 return TextAbstraction::FontWidth::NORMAL;
895 void Controller::SetDefaultFontSlant( FontSlant slant )
897 if( NULL == mImpl->mFontDefaults )
899 mImpl->mFontDefaults = new FontDefaults();
902 mImpl->mFontDefaults->mFontDescription.slant = slant;
903 mImpl->mFontDefaults->slantDefined = true;
905 // Clear the font-specific data
908 mImpl->RequestRelayout();
911 bool Controller::IsDefaultFontSlantDefined() const
913 if( NULL != mImpl->mFontDefaults )
915 return mImpl->mFontDefaults->slantDefined;
920 FontSlant Controller::GetDefaultFontSlant() const
922 if( NULL != mImpl->mFontDefaults )
924 return mImpl->mFontDefaults->mFontDescription.slant;
927 return TextAbstraction::FontSlant::NORMAL;
930 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
932 if( NULL != mImpl->mEventData )
934 if( NULL == mImpl->mEventData->mPlaceholderFont )
936 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
939 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
940 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
942 mImpl->RequestRelayout();
946 bool Controller::IsPlaceholderTextFontSlantDefined() const
948 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
950 return mImpl->mEventData->mPlaceholderFont->slantDefined;
955 FontSlant Controller::GetPlaceholderTextFontSlant() const
957 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
959 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
962 return TextAbstraction::FontSlant::NORMAL;
965 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
967 if( NULL == mImpl->mFontDefaults )
969 mImpl->mFontDefaults = new FontDefaults();
976 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
977 mImpl->mFontDefaults->sizeDefined = true;
982 // Point size = Pixel size * 72.f / DPI
983 unsigned int horizontalDpi = 0u;
984 unsigned int verticalDpi = 0u;
985 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
986 fontClient.GetDpi( horizontalDpi, verticalDpi );
988 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
989 mImpl->mFontDefaults->sizeDefined = true;
994 // Clear the font-specific data
997 mImpl->RequestRelayout();
1000 float Controller::GetDefaultFontSize( FontSizeType type ) const
1003 if( NULL != mImpl->mFontDefaults )
1009 value = mImpl->mFontDefaults->mDefaultPointSize;
1014 // Pixel size = Point size * DPI / 72.f
1015 unsigned int horizontalDpi = 0u;
1016 unsigned int verticalDpi = 0u;
1017 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1018 fontClient.GetDpi( horizontalDpi, verticalDpi );
1020 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1030 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1032 if( NULL != mImpl->mEventData )
1034 if( NULL == mImpl->mEventData->mPlaceholderFont )
1036 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1043 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1044 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1045 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1050 // Point size = Pixel size * 72.f / DPI
1051 unsigned int horizontalDpi = 0u;
1052 unsigned int verticalDpi = 0u;
1053 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1054 fontClient.GetDpi( horizontalDpi, verticalDpi );
1056 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1057 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1058 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1063 mImpl->RequestRelayout();
1067 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1070 if( NULL != mImpl->mEventData )
1076 if( NULL != mImpl->mEventData->mPlaceholderFont )
1078 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1082 // If the placeholder text font size is not set, then return the default font size.
1083 value = GetDefaultFontSize( POINT_SIZE );
1089 if( NULL != mImpl->mEventData->mPlaceholderFont )
1091 // Pixel size = Point size * DPI / 72.f
1092 unsigned int horizontalDpi = 0u;
1093 unsigned int verticalDpi = 0u;
1094 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1095 fontClient.GetDpi( horizontalDpi, verticalDpi );
1097 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1101 // If the placeholder text font size is not set, then return the default font size.
1102 value = GetDefaultFontSize( PIXEL_SIZE );
1113 void Controller::SetDefaultColor( const Vector4& color )
1115 mImpl->mTextColor = color;
1117 if( !mImpl->IsShowingPlaceholderText() )
1119 mImpl->mModel->mVisualModel->SetTextColor( color );
1121 mImpl->RequestRelayout();
1125 const Vector4& Controller::GetDefaultColor() const
1127 return mImpl->mTextColor;
1130 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1132 if( NULL != mImpl->mEventData )
1134 mImpl->mEventData->mPlaceholderTextColor = textColor;
1137 if( mImpl->IsShowingPlaceholderText() )
1139 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1140 mImpl->RequestRelayout();
1144 const Vector4& Controller::GetPlaceholderTextColor() const
1146 if( NULL != mImpl->mEventData )
1148 return mImpl->mEventData->mPlaceholderTextColor;
1151 return Color::BLACK;
1154 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1156 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1158 mImpl->RequestRelayout();
1161 const Vector2& Controller::GetShadowOffset() const
1163 return mImpl->mModel->mVisualModel->GetShadowOffset();
1166 void Controller::SetShadowColor( const Vector4& shadowColor )
1168 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1170 mImpl->RequestRelayout();
1173 const Vector4& Controller::GetShadowColor() const
1175 return mImpl->mModel->mVisualModel->GetShadowColor();
1178 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1180 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1182 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1184 mImpl->RequestRelayout();
1188 const float& Controller::GetShadowBlurRadius() const
1190 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1193 void Controller::SetUnderlineColor( const Vector4& color )
1195 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1197 mImpl->RequestRelayout();
1200 const Vector4& Controller::GetUnderlineColor() const
1202 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1205 void Controller::SetUnderlineEnabled( bool enabled )
1207 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1209 mImpl->RequestRelayout();
1212 bool Controller::IsUnderlineEnabled() const
1214 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1217 void Controller::SetUnderlineHeight( float height )
1219 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1221 mImpl->RequestRelayout();
1224 float Controller::GetUnderlineHeight() const
1226 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1229 void Controller::SetOutlineColor( const Vector4& color )
1231 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1233 mImpl->RequestRelayout();
1236 const Vector4& Controller::GetOutlineColor() const
1238 return mImpl->mModel->mVisualModel->GetOutlineColor();
1241 void Controller::SetOutlineWidth( unsigned int width )
1243 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1245 mImpl->RequestRelayout();
1248 unsigned int Controller::GetOutlineWidth() const
1250 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1253 void Controller::SetBackgroundColor( const Vector4& color )
1255 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1257 mImpl->RequestRelayout();
1260 const Vector4& Controller::GetBackgroundColor() const
1262 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1265 void Controller::SetBackgroundEnabled( bool enabled )
1267 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1269 mImpl->RequestRelayout();
1272 bool Controller::IsBackgroundEnabled() const
1274 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1277 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1279 if( NULL == mImpl->mEmbossDefaults )
1281 mImpl->mEmbossDefaults = new EmbossDefaults();
1284 mImpl->mEmbossDefaults->properties = embossProperties;
1287 const std::string& Controller::GetDefaultEmbossProperties() const
1289 if( NULL != mImpl->mEmbossDefaults )
1291 return mImpl->mEmbossDefaults->properties;
1294 return EMPTY_STRING;
1297 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1299 if( NULL == mImpl->mOutlineDefaults )
1301 mImpl->mOutlineDefaults = new OutlineDefaults();
1304 mImpl->mOutlineDefaults->properties = outlineProperties;
1307 const std::string& Controller::GetDefaultOutlineProperties() const
1309 if( NULL != mImpl->mOutlineDefaults )
1311 return mImpl->mOutlineDefaults->properties;
1314 return EMPTY_STRING;
1317 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1319 if( std::abs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000 )
1321 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1322 mImpl->mRecalculateNaturalSize = true;
1328 float Controller::GetDefaultLineSpacing() const
1330 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1333 void Controller::SetInputColor( const Vector4& color )
1335 if( NULL != mImpl->mEventData )
1337 mImpl->mEventData->mInputStyle.textColor = color;
1338 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1340 if( EventData::SELECTING == mImpl->mEventData->mState )
1342 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1344 // Get start and end position of selection
1345 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1346 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1348 // Add the color run.
1349 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1350 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1352 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1353 colorRun.color = color;
1354 colorRun.characterRun.characterIndex = startOfSelectedText;
1355 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1357 // Request to relayout.
1358 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1359 mImpl->RequestRelayout();
1361 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1362 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1363 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1368 const Vector4& Controller::GetInputColor() const
1370 if( NULL != mImpl->mEventData )
1372 return mImpl->mEventData->mInputStyle.textColor;
1375 // Return the default text's color if there is no EventData.
1376 return mImpl->mTextColor;
1380 void Controller::SetInputFontFamily( const std::string& fontFamily )
1382 if( NULL != mImpl->mEventData )
1384 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1385 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1387 if( EventData::SELECTING == mImpl->mEventData->mState )
1389 CharacterIndex startOfSelectedText = 0u;
1390 Length lengthOfSelectedText = 0u;
1391 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1392 mImpl->mModel->mLogicalModel,
1393 startOfSelectedText,
1394 lengthOfSelectedText );
1396 fontDescriptionRun.familyLength = fontFamily.size();
1397 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1398 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1399 fontDescriptionRun.familyDefined = true;
1401 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1403 // Request to relayout.
1404 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1409 UPDATE_LAYOUT_SIZE |
1412 mImpl->mRecalculateNaturalSize = true;
1413 mImpl->RequestRelayout();
1415 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1416 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1417 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1419 // As the font changes, recalculate the handle positions is needed.
1420 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1421 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1422 mImpl->mEventData->mUpdateHighlightBox = true;
1423 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1428 const std::string& Controller::GetInputFontFamily() const
1430 if( NULL != mImpl->mEventData )
1432 return mImpl->mEventData->mInputStyle.familyName;
1435 // Return the default font's family if there is no EventData.
1436 return GetDefaultFontFamily();
1439 void Controller::SetInputFontWeight( FontWeight weight )
1441 if( NULL != mImpl->mEventData )
1443 mImpl->mEventData->mInputStyle.weight = weight;
1444 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1446 if( EventData::SELECTING == mImpl->mEventData->mState )
1448 CharacterIndex startOfSelectedText = 0u;
1449 Length lengthOfSelectedText = 0u;
1450 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1451 mImpl->mModel->mLogicalModel,
1452 startOfSelectedText,
1453 lengthOfSelectedText );
1455 fontDescriptionRun.weight = weight;
1456 fontDescriptionRun.weightDefined = true;
1458 // Request to relayout.
1459 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1464 UPDATE_LAYOUT_SIZE |
1467 mImpl->mRecalculateNaturalSize = true;
1468 mImpl->RequestRelayout();
1470 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1471 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1472 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1474 // As the font might change, recalculate the handle positions is needed.
1475 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1476 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1477 mImpl->mEventData->mUpdateHighlightBox = true;
1478 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1483 bool Controller::IsInputFontWeightDefined() const
1485 bool defined = false;
1487 if( NULL != mImpl->mEventData )
1489 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1495 FontWeight Controller::GetInputFontWeight() const
1497 if( NULL != mImpl->mEventData )
1499 return mImpl->mEventData->mInputStyle.weight;
1502 return GetDefaultFontWeight();
1505 void Controller::SetInputFontWidth( FontWidth width )
1507 if( NULL != mImpl->mEventData )
1509 mImpl->mEventData->mInputStyle.width = width;
1510 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1512 if( EventData::SELECTING == mImpl->mEventData->mState )
1514 CharacterIndex startOfSelectedText = 0u;
1515 Length lengthOfSelectedText = 0u;
1516 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1517 mImpl->mModel->mLogicalModel,
1518 startOfSelectedText,
1519 lengthOfSelectedText );
1521 fontDescriptionRun.width = width;
1522 fontDescriptionRun.widthDefined = true;
1524 // Request to relayout.
1525 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1530 UPDATE_LAYOUT_SIZE |
1533 mImpl->mRecalculateNaturalSize = true;
1534 mImpl->RequestRelayout();
1536 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1537 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1538 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1540 // As the font might change, recalculate the handle positions is needed.
1541 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1542 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1543 mImpl->mEventData->mUpdateHighlightBox = true;
1544 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1549 bool Controller::IsInputFontWidthDefined() const
1551 bool defined = false;
1553 if( NULL != mImpl->mEventData )
1555 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1561 FontWidth Controller::GetInputFontWidth() const
1563 if( NULL != mImpl->mEventData )
1565 return mImpl->mEventData->mInputStyle.width;
1568 return GetDefaultFontWidth();
1571 void Controller::SetInputFontSlant( FontSlant slant )
1573 if( NULL != mImpl->mEventData )
1575 mImpl->mEventData->mInputStyle.slant = slant;
1576 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1578 if( EventData::SELECTING == mImpl->mEventData->mState )
1580 CharacterIndex startOfSelectedText = 0u;
1581 Length lengthOfSelectedText = 0u;
1582 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1583 mImpl->mModel->mLogicalModel,
1584 startOfSelectedText,
1585 lengthOfSelectedText );
1587 fontDescriptionRun.slant = slant;
1588 fontDescriptionRun.slantDefined = true;
1590 // Request to relayout.
1591 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1596 UPDATE_LAYOUT_SIZE |
1599 mImpl->mRecalculateNaturalSize = true;
1600 mImpl->RequestRelayout();
1602 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1603 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1604 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1606 // As the font might change, recalculate the handle positions is needed.
1607 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1608 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1609 mImpl->mEventData->mUpdateHighlightBox = true;
1610 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1615 bool Controller::IsInputFontSlantDefined() const
1617 bool defined = false;
1619 if( NULL != mImpl->mEventData )
1621 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1627 FontSlant Controller::GetInputFontSlant() const
1629 if( NULL != mImpl->mEventData )
1631 return mImpl->mEventData->mInputStyle.slant;
1634 return GetDefaultFontSlant();
1637 void Controller::SetInputFontPointSize( float size )
1639 if( NULL != mImpl->mEventData )
1641 mImpl->mEventData->mInputStyle.size = size;
1642 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1644 if( EventData::SELECTING == mImpl->mEventData->mState )
1646 CharacterIndex startOfSelectedText = 0u;
1647 Length lengthOfSelectedText = 0u;
1648 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1649 mImpl->mModel->mLogicalModel,
1650 startOfSelectedText,
1651 lengthOfSelectedText );
1653 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1654 fontDescriptionRun.sizeDefined = true;
1656 // Request to relayout.
1657 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1662 UPDATE_LAYOUT_SIZE |
1665 mImpl->mRecalculateNaturalSize = true;
1666 mImpl->RequestRelayout();
1668 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1669 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1670 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1672 // As the font might change, recalculate the handle positions is needed.
1673 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1674 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1675 mImpl->mEventData->mUpdateHighlightBox = true;
1676 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1681 float Controller::GetInputFontPointSize() const
1683 if( NULL != mImpl->mEventData )
1685 return mImpl->mEventData->mInputStyle.size;
1688 // Return the default font's point size if there is no EventData.
1689 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1692 void Controller::SetInputLineSpacing( float lineSpacing )
1694 if( NULL != mImpl->mEventData )
1696 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1697 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1701 float Controller::GetInputLineSpacing() const
1703 if( NULL != mImpl->mEventData )
1705 return mImpl->mEventData->mInputStyle.lineSpacing;
1711 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1713 if( NULL != mImpl->mEventData )
1715 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1719 const std::string& Controller::GetInputShadowProperties() const
1721 if( NULL != mImpl->mEventData )
1723 return mImpl->mEventData->mInputStyle.shadowProperties;
1726 return EMPTY_STRING;
1729 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1731 if( NULL != mImpl->mEventData )
1733 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1737 const std::string& Controller::GetInputUnderlineProperties() const
1739 if( NULL != mImpl->mEventData )
1741 return mImpl->mEventData->mInputStyle.underlineProperties;
1744 return EMPTY_STRING;
1747 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1749 if( NULL != mImpl->mEventData )
1751 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1755 const std::string& Controller::GetInputEmbossProperties() const
1757 if( NULL != mImpl->mEventData )
1759 return mImpl->mEventData->mInputStyle.embossProperties;
1762 return GetDefaultEmbossProperties();
1765 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1767 if( NULL != mImpl->mEventData )
1769 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1773 const std::string& Controller::GetInputOutlineProperties() const
1775 if( NULL != mImpl->mEventData )
1777 return mImpl->mEventData->mInputStyle.outlineProperties;
1780 return GetDefaultOutlineProperties();
1783 void Controller::SetInputModePassword( bool passwordInput )
1785 if( NULL != mImpl->mEventData )
1787 mImpl->mEventData->mPasswordInput = passwordInput;
1791 bool Controller::IsInputModePassword()
1793 if( NULL != mImpl->mEventData )
1795 return mImpl->mEventData->mPasswordInput;
1800 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1802 if( NULL != mImpl->mEventData )
1804 mImpl->mEventData->mDoubleTapAction = action;
1808 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1810 NoTextTap::Action action = NoTextTap::NO_ACTION;
1812 if( NULL != mImpl->mEventData )
1814 action = mImpl->mEventData->mDoubleTapAction;
1820 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1822 if( NULL != mImpl->mEventData )
1824 mImpl->mEventData->mLongPressAction = action;
1828 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1830 NoTextTap::Action action = NoTextTap::NO_ACTION;
1832 if( NULL != mImpl->mEventData )
1834 action = mImpl->mEventData->mLongPressAction;
1840 bool Controller::IsUnderlineSetByString()
1842 return mImpl->mUnderlineSetByString;
1845 void Controller::UnderlineSetByString( bool setByString )
1847 mImpl->mUnderlineSetByString = setByString;
1850 bool Controller::IsShadowSetByString()
1852 return mImpl->mShadowSetByString;
1855 void Controller::ShadowSetByString( bool setByString )
1857 mImpl->mShadowSetByString = setByString;
1860 bool Controller::IsOutlineSetByString()
1862 return mImpl->mOutlineSetByString;
1865 void Controller::OutlineSetByString( bool setByString )
1867 mImpl->mOutlineSetByString = setByString;
1870 bool Controller::IsFontStyleSetByString()
1872 return mImpl->mFontStyleSetByString;
1875 void Controller::FontStyleSetByString( bool setByString )
1877 mImpl->mFontStyleSetByString = setByString;
1880 // public : Queries & retrieves.
1882 Layout::Engine& Controller::GetLayoutEngine()
1884 return mImpl->mLayoutEngine;
1887 View& Controller::GetView()
1889 return mImpl->mView;
1892 Vector3 Controller::GetNaturalSize()
1894 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1895 Vector3 naturalSize;
1897 // Make sure the model is up-to-date before layouting
1898 ProcessModifyEvents();
1900 if( mImpl->mRecalculateNaturalSize )
1902 // Operations that can be done only once until the text changes.
1903 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1910 GET_GLYPH_METRICS );
1912 // Set the update info to relayout the whole text.
1913 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1914 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1916 // Make sure the model is up-to-date before layouting
1917 mImpl->UpdateModel( onlyOnceOperations );
1919 // Layout the text for the new width.
1920 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1922 // Store the actual control's size to restore later.
1923 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1925 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1926 static_cast<OperationsMask>( onlyOnceOperations |
1928 naturalSize.GetVectorXY() );
1930 // Do not do again the only once operations.
1931 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1933 // Do the size related operations again.
1934 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1937 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1939 // Stores the natural size to avoid recalculate it again
1940 // unless the text/style changes.
1941 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1943 mImpl->mRecalculateNaturalSize = false;
1945 // Clear the update info. This info will be set the next time the text is updated.
1946 mImpl->mTextUpdateInfo.Clear();
1947 mImpl->mTextUpdateInfo.mClearAll = true;
1949 // Restore the actual control's size.
1950 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1952 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1956 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1958 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1961 naturalSize.x = ConvertToEven( naturalSize.x );
1962 naturalSize.y = ConvertToEven( naturalSize.y );
1967 float Controller::GetHeightForWidth( float width )
1969 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1970 // Make sure the model is up-to-date before layouting
1971 ProcessModifyEvents();
1974 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1975 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1976 mImpl->mTextUpdateInfo.mClearAll )
1978 // Operations that can be done only once until the text changes.
1979 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1986 GET_GLYPH_METRICS );
1988 // Set the update info to relayout the whole text.
1989 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1990 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1992 // Make sure the model is up-to-date before layouting
1993 mImpl->UpdateModel( onlyOnceOperations );
1996 // Layout the text for the new width.
1997 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1999 // Store the actual control's width.
2000 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2002 DoRelayout( Size( width, MAX_FLOAT ),
2003 static_cast<OperationsMask>( onlyOnceOperations |
2007 // Do not do again the only once operations.
2008 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2010 // Do the size related operations again.
2011 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2015 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2017 // Clear the update info. This info will be set the next time the text is updated.
2018 mImpl->mTextUpdateInfo.Clear();
2019 mImpl->mTextUpdateInfo.mClearAll = true;
2021 // Restore the actual control's width.
2022 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2024 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2028 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2029 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2032 return layoutSize.height;
2035 int Controller::GetLineCount( float width )
2037 GetHeightForWidth( width );
2038 int numberofLines = mImpl->mModel->GetNumberOfLines();
2039 return numberofLines;
2042 const ModelInterface* const Controller::GetTextModel() const
2044 return mImpl->mModel.Get();
2047 float Controller::GetScrollAmountByUserInput()
2049 float scrollAmount = 0.0f;
2051 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2053 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2054 mImpl->mEventData->mCheckScrollAmount = false;
2056 return scrollAmount;
2059 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2061 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2064 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2065 layoutHeight = layout.height;
2066 scrollPosition = mImpl->mModel->mScrollPosition.y;
2067 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2071 void Controller::SetHiddenInputOption(const Property::Map& options )
2073 if( NULL == mImpl->mHiddenInput )
2075 mImpl->mHiddenInput = new HiddenText( this );
2077 mImpl->mHiddenInput->SetProperties(options);
2080 void Controller::GetHiddenInputOption(Property::Map& options )
2082 if( NULL != mImpl->mHiddenInput )
2084 mImpl->mHiddenInput->GetProperties(options);
2088 void Controller::SetPlaceholderProperty( const Property::Map& map )
2090 const Property::Map::SizeType count = map.Count();
2092 for( Property::Map::SizeType position = 0; position < count; ++position )
2094 KeyValuePair keyValue = map.GetKeyValue( position );
2095 Property::Key& key = keyValue.first;
2096 Property::Value& value = keyValue.second;
2098 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2100 std::string text = "";
2102 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2104 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2106 std::string text = "";
2108 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2110 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2113 value.Get( textColor );
2114 if( GetPlaceholderTextColor() != textColor )
2116 SetPlaceholderTextColor( textColor );
2119 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2121 std::string fontFamily = "";
2122 value.Get( fontFamily );
2123 SetPlaceholderFontFamily( fontFamily );
2125 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2127 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2129 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2132 value.Get( pointSize );
2133 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2135 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2138 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2141 value.Get( pixelSize );
2142 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2144 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2147 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2150 value.Get( ellipsis );
2151 SetPlaceholderTextElideEnabled( ellipsis );
2156 void Controller::GetPlaceholderProperty( Property::Map& map )
2158 if( NULL != mImpl->mEventData )
2160 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2162 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2164 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2166 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2169 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2170 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2172 Property::Value fontStyleMapGet;
2173 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2174 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2176 // Choose font size : POINT_SIZE or PIXEL_SIZE
2177 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2179 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2183 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2186 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2188 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2193 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2195 // Make sure the model is up-to-date before layouting
2196 ProcessModifyEvents();
2198 if ( mImpl->mUpdateTextDirection )
2200 // Operations that can be done only once until the text changes.
2201 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2208 GET_GLYPH_METRICS );
2210 // Set the update info to relayout the whole text.
2211 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2212 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2214 // Make sure the model is up-to-date before layouting
2215 mImpl->UpdateModel( onlyOnceOperations );
2217 Vector3 naturalSize;
2218 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2219 static_cast<OperationsMask>( onlyOnceOperations |
2220 LAYOUT | REORDER | UPDATE_DIRECTION ),
2221 naturalSize.GetVectorXY() );
2223 // Do not do again the only once operations.
2224 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2226 // Clear the update info. This info will be set the next time the text is updated.
2227 mImpl->mTextUpdateInfo.Clear();
2229 mImpl->mUpdateTextDirection = false;
2232 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2235 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2237 return mImpl->mModel->GetVerticalLineAlignment();
2240 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2242 mImpl->mModel->mVerticalLineAlignment = alignment;
2245 // public : Relayout.
2247 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2249 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2251 UpdateTextType updateTextType = NONE_UPDATED;
2254 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2256 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2258 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2259 updateTextType = MODEL_UPDATED;
2262 // Clear the update info. This info will be set the next time the text is updated.
2263 mImpl->mTextUpdateInfo.Clear();
2265 // Not worth to relayout if width or height is equal to zero.
2266 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2268 return updateTextType;
2271 // Whether a new size has been set.
2272 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2276 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2278 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2279 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2280 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2282 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2285 // Layout operations that need to be done if the size changes.
2286 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2289 UPDATE_LAYOUT_SIZE |
2291 // Set the update info to relayout the whole text.
2292 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2293 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2295 // Store the size used to layout the text.
2296 mImpl->mModel->mVisualModel->mControlSize = size;
2299 // Whether there are modify events.
2300 if( 0u != mImpl->mModifyEvents.Count() )
2302 // Style operations that need to be done if the text is modified.
2303 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2307 // Set the update info to elide the text.
2308 if( mImpl->mModel->mElideEnabled ||
2309 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2311 // Update Text layout for applying elided
2312 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2315 UPDATE_LAYOUT_SIZE |
2317 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2318 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2321 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2323 // Clear the update info. This info will be set the next time the text is updated.
2324 mImpl->mTextUpdateInfo.mClearAll = true;
2325 // Apply modifications to the model
2326 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2333 mImpl->mLayoutDirection = layoutDirection;
2336 // Make sure the model is up-to-date before layouting.
2337 ProcessModifyEvents();
2338 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2342 updated = DoRelayout( size,
2343 mImpl->mOperationsPending,
2344 layoutSize ) || updated;
2348 updateTextType = MODEL_UPDATED;
2351 // Do not re-do any operation until something changes.
2352 mImpl->mOperationsPending = NO_OPERATION;
2353 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2355 // Whether the text control is editable
2356 const bool isEditable = NULL != mImpl->mEventData;
2358 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2360 if( newSize && isEditable )
2362 offset = mImpl->mModel->mScrollPosition;
2365 if( !isEditable || !IsMultiLineEnabled() )
2367 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2368 CalculateVerticalOffset( size );
2375 // If there is a new size, the scroll position needs to be clamped.
2376 mImpl->ClampHorizontalScroll( layoutSize );
2378 // Update the decorator's positions is needed if there is a new size.
2379 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2382 // Move the cursor, grab handle etc.
2383 if( mImpl->ProcessInputEvents() )
2385 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2389 // Clear the update info. This info will be set the next time the text is updated.
2390 mImpl->mTextUpdateInfo.Clear();
2391 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2393 return updateTextType;
2396 void Controller::RequestRelayout()
2398 mImpl->RequestRelayout();
2401 // public : Input style change signals.
2403 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2405 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2408 void Controller::ProcessInputStyleChangedSignals()
2410 if( NULL == mImpl->mEventData )
2416 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2417 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2421 const InputStyle::Mask mask = *it;
2423 if( NULL != mImpl->mEditableControlInterface )
2425 // Emit the input style changed signal.
2426 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2430 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2433 // public : Text-input Event Queuing.
2435 void Controller::KeyboardFocusGainEvent()
2437 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2439 if( NULL != mImpl->mEventData )
2441 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2442 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2444 mImpl->ChangeState( EventData::EDITING );
2445 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2446 mImpl->mEventData->mUpdateInputStyle = true;
2447 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2449 mImpl->NotifyInputMethodContextMultiLineStatus();
2450 if( mImpl->IsShowingPlaceholderText() )
2452 // Show alternative placeholder-text when editing
2453 ShowPlaceholderText();
2456 mImpl->RequestRelayout();
2460 void Controller::KeyboardFocusLostEvent()
2462 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2464 if( NULL != mImpl->mEventData )
2466 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2468 mImpl->ChangeState( EventData::INACTIVE );
2470 if( !mImpl->IsShowingRealText() )
2472 // Revert to regular placeholder-text when not editing
2473 ShowPlaceholderText();
2477 mImpl->RequestRelayout();
2480 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2482 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2484 bool textChanged = false;
2485 bool relayoutNeeded = false;
2487 if( ( NULL != mImpl->mEventData ) &&
2488 ( keyEvent.state == KeyEvent::Down ) )
2490 int keyCode = keyEvent.keyCode;
2491 const std::string& keyString = keyEvent.keyPressed;
2492 const std::string keyName = keyEvent.keyPressedName;
2494 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2496 // Pre-process to separate modifying events from non-modifying input events.
2499 // In some platforms arrive key events with no key code.
2503 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2508 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2509 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2510 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2511 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2513 // If don't have any text, do nothing.
2514 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2519 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2520 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2521 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2522 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2524 // Logic to determine whether this text control will lose focus or not.
2525 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2526 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2527 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2528 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2529 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2530 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2532 // Release the active highlight.
2533 if( mImpl->mEventData->mState == EventData::SELECTING )
2535 mImpl->ChangeState( EventData::EDITING );
2537 // Update selection position.
2538 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2539 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2540 mImpl->mEventData->mUpdateCursorPosition = true;
2541 mImpl->RequestRelayout();
2546 mImpl->mEventData->mCheckScrollAmount = true;
2547 Event event( Event::CURSOR_KEY_EVENT );
2548 event.p1.mInt = keyCode;
2549 event.p2.mBool = keyEvent.IsShiftModifier();
2550 mImpl->mEventData->mEventQueue.push_back( event );
2552 // Will request for relayout.
2553 relayoutNeeded = true;
2555 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2557 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2558 // If not handle it here, any selected text will be deleted
2563 else if ( keyEvent.IsCtrlModifier() )
2565 bool consumed = false;
2566 if (keyName == KEY_C_NAME)
2568 // Ctrl-C to copy the selected text
2569 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2572 else if (keyName == KEY_V_NAME)
2574 // Ctrl-V to paste the copied text
2575 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2578 else if (keyName == KEY_X_NAME)
2580 // Ctrl-X to cut the selected text
2581 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2586 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2587 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2589 textChanged = DeleteEvent( keyCode );
2591 // Will request for relayout.
2592 relayoutNeeded = true;
2594 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2595 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2596 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2598 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2599 mImpl->ChangeState( EventData::INACTIVE );
2601 // Will request for relayout.
2602 relayoutNeeded = true;
2604 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2606 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2608 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the InputMethodContext?) when the predictive text is enabled
2609 // and a character is typed after the type of a upper case latin character.
2614 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2616 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2622 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2624 // InputMethodContext is no longer handling key-events
2625 mImpl->ClearPreEditFlag();
2627 InsertText( keyString, COMMIT );
2630 // Will request for relayout.
2631 relayoutNeeded = true;
2634 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2635 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2637 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2638 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2639 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2641 // Should not change the state if the key is the shift send by the InputMethodContext.
2642 // Otherwise, when the state is SELECTING the text controller can't send the right
2643 // surrounding info to the InputMethodContext.
2644 mImpl->ChangeState( EventData::EDITING );
2646 // Will request for relayout.
2647 relayoutNeeded = true;
2650 if( relayoutNeeded )
2652 mImpl->RequestRelayout();
2657 ( NULL != mImpl->mEditableControlInterface ) )
2659 // Do this last since it provides callbacks into application code
2660 mImpl->mEditableControlInterface->TextChanged();
2666 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2668 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2670 if( NULL != mImpl->mEventData )
2672 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2673 EventData::State state( mImpl->mEventData->mState );
2674 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2676 if( mImpl->IsClipboardVisible() )
2678 if( EventData::INACTIVE == state || EventData::EDITING == state)
2680 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2682 relayoutNeeded = true;
2684 else if( 1u == tapCount )
2686 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2688 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2691 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2693 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2694 relayoutNeeded = true;
2698 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2700 // Hide placeholder text
2704 if( EventData::INACTIVE == state )
2706 mImpl->ChangeState( EventData::EDITING );
2708 else if( !mImpl->IsClipboardEmpty() )
2710 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2712 relayoutNeeded = true;
2715 else if( 2u == tapCount )
2717 if( mImpl->mEventData->mSelectionEnabled &&
2718 mImpl->IsShowingRealText() )
2720 relayoutNeeded = true;
2721 mImpl->mEventData->mIsLeftHandleSelected = true;
2722 mImpl->mEventData->mIsRightHandleSelected = true;
2726 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2727 if( relayoutNeeded )
2729 Event event( Event::TAP_EVENT );
2730 event.p1.mUint = tapCount;
2731 event.p2.mFloat = x;
2732 event.p3.mFloat = y;
2733 mImpl->mEventData->mEventQueue.push_back( event );
2735 mImpl->RequestRelayout();
2739 // Reset keyboard as tap event has occurred.
2740 mImpl->ResetInputMethodContext();
2743 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2745 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2747 if( NULL != mImpl->mEventData )
2749 Event event( Event::PAN_EVENT );
2750 event.p1.mInt = state;
2751 event.p2.mFloat = displacement.x;
2752 event.p3.mFloat = displacement.y;
2753 mImpl->mEventData->mEventQueue.push_back( event );
2755 mImpl->RequestRelayout();
2759 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2761 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2763 if( ( state == Gesture::Started ) &&
2764 ( NULL != mImpl->mEventData ) )
2766 // The 1st long-press on inactive text-field is treated as tap
2767 if( EventData::INACTIVE == mImpl->mEventData->mState )
2769 mImpl->ChangeState( EventData::EDITING );
2771 Event event( Event::TAP_EVENT );
2773 event.p2.mFloat = x;
2774 event.p3.mFloat = y;
2775 mImpl->mEventData->mEventQueue.push_back( event );
2777 mImpl->RequestRelayout();
2779 else if( !mImpl->IsShowingRealText() )
2781 Event event( Event::LONG_PRESS_EVENT );
2782 event.p1.mInt = state;
2783 event.p2.mFloat = x;
2784 event.p3.mFloat = y;
2785 mImpl->mEventData->mEventQueue.push_back( event );
2786 mImpl->RequestRelayout();
2788 else if( !mImpl->IsClipboardVisible() )
2790 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
2791 mImpl->ResetInputMethodContext();
2793 Event event( Event::LONG_PRESS_EVENT );
2794 event.p1.mInt = state;
2795 event.p2.mFloat = x;
2796 event.p3.mFloat = y;
2797 mImpl->mEventData->mEventQueue.push_back( event );
2798 mImpl->RequestRelayout();
2800 mImpl->mEventData->mIsLeftHandleSelected = true;
2801 mImpl->mEventData->mIsRightHandleSelected = true;
2806 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
2808 // Whether the text needs to be relaid-out.
2809 bool requestRelayout = false;
2811 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
2812 bool retrieveText = false;
2813 bool retrieveCursor = false;
2815 switch( inputMethodContextEvent.eventName )
2817 case InputMethodContext::COMMIT:
2819 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
2820 requestRelayout = true;
2821 retrieveCursor = true;
2824 case InputMethodContext::PRE_EDIT:
2826 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
2827 requestRelayout = true;
2828 retrieveCursor = true;
2831 case InputMethodContext::DELETE_SURROUNDING:
2833 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
2834 inputMethodContextEvent.numberOfChars,
2835 DONT_UPDATE_INPUT_STYLE );
2839 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2840 !mImpl->IsPlaceholderAvailable() )
2842 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2846 ShowPlaceholderText();
2848 mImpl->mEventData->mUpdateCursorPosition = true;
2849 mImpl->mEventData->mScrollAfterDelete = true;
2851 requestRelayout = true;
2855 case InputMethodContext::GET_SURROUNDING:
2857 retrieveText = true;
2858 retrieveCursor = true;
2861 case InputMethodContext::PRIVATE_COMMAND:
2863 // PRIVATECOMMAND event is just for getting the private command message
2864 retrieveText = true;
2865 retrieveCursor = true;
2868 case InputMethodContext::VOID:
2875 if( requestRelayout )
2877 mImpl->mOperationsPending = ALL_OPERATIONS;
2878 mImpl->RequestRelayout();
2882 CharacterIndex cursorPosition = 0u;
2883 Length numberOfWhiteSpaces = 0u;
2885 if( retrieveCursor )
2887 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2889 cursorPosition = mImpl->GetLogicalCursorPosition();
2891 if( cursorPosition < numberOfWhiteSpaces )
2893 cursorPosition = 0u;
2897 cursorPosition -= numberOfWhiteSpaces;
2903 if( !mImpl->IsShowingPlaceholderText() )
2905 // Retrieves the normal text string.
2906 mImpl->GetText( numberOfWhiteSpaces, text );
2910 // When the current text is Placeholder Text, the surrounding text should be empty string.
2911 // It means DALi should send empty string ("") to IME.
2916 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2918 if( requestRelayout &&
2919 ( NULL != mImpl->mEditableControlInterface ) )
2921 // Do this last since it provides callbacks into application code
2922 mImpl->mEditableControlInterface->TextChanged();
2925 return callbackData;
2928 void Controller::PasteClipboardItemEvent()
2930 // Retrieve the clipboard contents first
2931 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2932 std::string stringToPaste( notifier.GetContent() );
2934 // Commit the current pre-edit text; the contents of the clipboard should be appended
2935 mImpl->ResetInputMethodContext();
2937 // Temporary disable hiding clipboard
2938 mImpl->SetClipboardHideEnable( false );
2941 PasteText( stringToPaste );
2943 mImpl->SetClipboardHideEnable( true );
2946 // protected : Inherit from Text::Decorator::ControllerInterface.
2948 void Controller::GetTargetSize( Vector2& targetSize )
2950 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2953 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2955 if( NULL != mImpl->mEditableControlInterface )
2957 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2961 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2963 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2965 if( NULL != mImpl->mEventData )
2967 switch( handleType )
2971 Event event( Event::GRAB_HANDLE_EVENT );
2972 event.p1.mUint = state;
2973 event.p2.mFloat = x;
2974 event.p3.mFloat = y;
2976 mImpl->mEventData->mEventQueue.push_back( event );
2979 case LEFT_SELECTION_HANDLE:
2981 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2982 event.p1.mUint = state;
2983 event.p2.mFloat = x;
2984 event.p3.mFloat = y;
2986 mImpl->mEventData->mEventQueue.push_back( event );
2989 case RIGHT_SELECTION_HANDLE:
2991 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2992 event.p1.mUint = state;
2993 event.p2.mFloat = x;
2994 event.p3.mFloat = y;
2996 mImpl->mEventData->mEventQueue.push_back( event );
2999 case LEFT_SELECTION_HANDLE_MARKER:
3000 case RIGHT_SELECTION_HANDLE_MARKER:
3002 // Markers do not move the handles.
3005 case HANDLE_TYPE_COUNT:
3007 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3011 mImpl->RequestRelayout();
3015 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3017 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3019 if( NULL == mImpl->mEventData )
3026 case Toolkit::TextSelectionPopup::CUT:
3028 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3029 mImpl->mOperationsPending = ALL_OPERATIONS;
3031 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3032 !mImpl->IsPlaceholderAvailable() )
3034 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3038 ShowPlaceholderText();
3041 mImpl->mEventData->mUpdateCursorPosition = true;
3042 mImpl->mEventData->mScrollAfterDelete = true;
3044 mImpl->RequestRelayout();
3046 if( NULL != mImpl->mEditableControlInterface )
3048 mImpl->mEditableControlInterface->TextChanged();
3052 case Toolkit::TextSelectionPopup::COPY:
3054 mImpl->SendSelectionToClipboard( false ); // Text not modified
3056 mImpl->mEventData->mUpdateCursorPosition = true;
3058 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3061 case Toolkit::TextSelectionPopup::PASTE:
3063 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3066 case Toolkit::TextSelectionPopup::SELECT:
3068 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3070 if( mImpl->mEventData->mSelectionEnabled )
3072 // Creates a SELECT event.
3073 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3077 case Toolkit::TextSelectionPopup::SELECT_ALL:
3079 // Creates a SELECT_ALL event
3080 SelectEvent( 0.f, 0.f, true );
3083 case Toolkit::TextSelectionPopup::CLIPBOARD:
3085 mImpl->ShowClipboard();
3088 case Toolkit::TextSelectionPopup::NONE:
3096 void Controller::DisplayTimeExpired()
3098 mImpl->mEventData->mUpdateCursorPosition = true;
3099 // Apply modifications to the model
3100 mImpl->mOperationsPending = ALL_OPERATIONS;
3102 mImpl->RequestRelayout();
3105 // private : Update.
3107 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3109 bool removedPrevious = false;
3110 bool removedSelected = false;
3111 bool maxLengthReached = false;
3113 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3115 if( NULL == mImpl->mEventData )
3120 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3121 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3122 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3124 // TODO: At the moment the underline runs are only for pre-edit.
3125 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3127 // Remove the previous InputMethodContext pre-edit.
3128 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3130 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3131 mImpl->mEventData->mPreEditLength,
3132 DONT_UPDATE_INPUT_STYLE );
3134 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3135 mImpl->mEventData->mPreEditLength = 0u;
3139 // Remove the previous Selection.
3140 removedSelected = RemoveSelectedText();
3144 Vector<Character> utf32Characters;
3145 Length characterCount = 0u;
3149 // Convert text into UTF-32
3150 utf32Characters.Resize( text.size() );
3152 // This is a bit horrible but std::string returns a (signed) char*
3153 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3155 // Transform a text array encoded in utf8 into an array encoded in utf32.
3156 // It returns the actual number of characters.
3157 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3158 utf32Characters.Resize( characterCount );
3160 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3161 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3164 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3166 // The placeholder text is no longer needed
3167 if( mImpl->IsShowingPlaceholderText() )
3172 mImpl->ChangeState( EventData::EDITING );
3174 // Handle the InputMethodContext (predicitive text) state changes
3175 if( COMMIT == type )
3177 // InputMethodContext is no longer handling key-events
3178 mImpl->ClearPreEditFlag();
3182 if( !mImpl->mEventData->mPreEditFlag )
3184 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3186 // Record the start of the pre-edit text
3187 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3190 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3191 mImpl->mEventData->mPreEditFlag = true;
3193 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3196 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3198 // Restrict new text to fit within Maximum characters setting.
3199 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3200 maxLengthReached = ( characterCount > maxSizeOfNewText );
3202 // The cursor position.
3203 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3205 // Update the text's style.
3207 // Updates the text style runs by adding characters.
3208 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3210 // Get the character index from the cursor index.
3211 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3213 // Retrieve the text's style for the given index.
3215 mImpl->RetrieveDefaultInputStyle( style );
3216 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3218 // Whether to add a new text color run.
3219 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3221 // Whether to add a new font run.
3222 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3223 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3224 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3225 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3226 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3231 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3232 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3234 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3235 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3236 colorRun.characterRun.characterIndex = cursorIndex;
3237 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3240 if( addFontNameRun ||
3246 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3247 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3249 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3251 if( addFontNameRun )
3253 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3254 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3255 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3256 fontDescriptionRun.familyDefined = true;
3258 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3261 if( addFontWeightRun )
3263 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3264 fontDescriptionRun.weightDefined = true;
3267 if( addFontWidthRun )
3269 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3270 fontDescriptionRun.widthDefined = true;
3273 if( addFontSlantRun )
3275 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3276 fontDescriptionRun.slantDefined = true;
3279 if( addFontSizeRun )
3281 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3282 fontDescriptionRun.sizeDefined = true;
3285 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3286 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3289 // Insert at current cursor position.
3290 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3292 if( cursorIndex < numberOfCharactersInModel )
3294 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3298 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3301 // Mark the first paragraph to be updated.
3302 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3304 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3305 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3306 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3307 mImpl->mTextUpdateInfo.mClearAll = true;
3311 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3312 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3315 // Update the cursor index.
3316 cursorIndex += maxSizeOfNewText;
3318 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 );
3321 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3322 mImpl->IsPlaceholderAvailable() )
3324 // Show place-holder if empty after removing the pre-edit text
3325 ShowPlaceholderText();
3326 mImpl->mEventData->mUpdateCursorPosition = true;
3327 mImpl->ClearPreEditFlag();
3329 else if( removedPrevious ||
3331 ( 0 != utf32Characters.Count() ) )
3333 // Queue an inserted event
3334 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3336 mImpl->mEventData->mUpdateCursorPosition = true;
3337 if( removedSelected )
3339 mImpl->mEventData->mScrollAfterDelete = true;
3343 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3347 if( maxLengthReached )
3349 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3351 mImpl->ResetInputMethodContext();
3353 if( NULL != mImpl->mEditableControlInterface )
3355 // Do this last since it provides callbacks into application code
3356 mImpl->mEditableControlInterface->MaxLengthReached();
3361 void Controller::PasteText( const std::string& stringToPaste )
3363 InsertText( stringToPaste, Text::Controller::COMMIT );
3364 mImpl->ChangeState( EventData::EDITING );
3365 mImpl->RequestRelayout();
3367 if( NULL != mImpl->mEditableControlInterface )
3369 // Do this last since it provides callbacks into application code
3370 mImpl->mEditableControlInterface->TextChanged();
3374 bool Controller::RemoveText( int cursorOffset,
3375 int numberOfCharacters,
3376 UpdateInputStyleType type )
3378 bool removed = false;
3380 if( NULL == mImpl->mEventData )
3385 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3386 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3388 if( !mImpl->IsShowingPlaceholderText() )
3390 // Delete at current cursor position
3391 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3392 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3394 CharacterIndex cursorIndex = 0;
3396 // Validate the cursor position & number of characters
3397 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3399 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3402 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3404 numberOfCharacters = currentText.Count() - cursorIndex;
3407 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.
3408 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3410 // Mark the paragraphs to be updated.
3411 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3413 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3414 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3415 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3416 mImpl->mTextUpdateInfo.mClearAll = true;
3420 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3421 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3424 // Update the input style and remove the text's style before removing the text.
3426 if( UPDATE_INPUT_STYLE == type )
3428 // Keep a copy of the current input style.
3429 InputStyle currentInputStyle;
3430 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3432 // Set first the default input style.
3433 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3435 // Update the input style.
3436 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3438 // Compare if the input style has changed.
3439 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3441 if( hasInputStyleChanged )
3443 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3444 // Queue the input style changed signal.
3445 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3449 // Updates the text style runs by removing characters. Runs with no characters are removed.
3450 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3452 // Remove the characters.
3453 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3454 Vector<Character>::Iterator last = first + numberOfCharacters;
3456 currentText.Erase( first, last );
3458 // Cursor position retreat
3459 oldCursorIndex = cursorIndex;
3461 mImpl->mEventData->mScrollAfterDelete = true;
3463 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3471 bool Controller::RemoveSelectedText()
3473 bool textRemoved( false );
3475 if( EventData::SELECTING == mImpl->mEventData->mState )
3477 std::string removedString;
3478 mImpl->RetrieveSelection( removedString, true );
3480 if( !removedString.empty() )
3483 mImpl->ChangeState( EventData::EDITING );
3490 // private : Relayout.
3492 bool Controller::DoRelayout( const Size& size,
3493 OperationsMask operationsRequired,
3496 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3497 bool viewUpdated( false );
3499 // Calculate the operations to be done.
3500 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3502 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3503 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3505 // Get the current layout size.
3506 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3508 if( NO_OPERATION != ( LAYOUT & operations ) )
3510 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3512 // Some vectors with data needed to layout and reorder may be void
3513 // after the first time the text has been laid out.
3514 // Fill the vectors again.
3516 // Calculate the number of glyphs to layout.
3517 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3518 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3519 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3520 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3522 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3523 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3525 // Make sure the index is not out of bound
3526 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3527 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3528 ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3530 std::string currentText;
3531 GetText( currentText );
3533 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3534 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3535 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3540 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3541 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3543 if( 0u == totalNumberOfGlyphs )
3545 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3547 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3550 // Nothing else to do if there is no glyphs.
3551 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3555 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3556 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3557 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3558 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3559 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3560 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3561 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3562 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3564 // Set the layout parameters.
3565 Layout::Parameters layoutParameters( size,
3567 lineBreakInfo.Begin(),
3568 wordBreakInfo.Begin(),
3569 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3571 glyphsToCharactersMap.Begin(),
3572 charactersPerGlyph.Begin(),
3573 charactersToGlyphBuffer,
3574 glyphsPerCharacterBuffer,
3575 totalNumberOfGlyphs,
3576 mImpl->mModel->mHorizontalAlignment,
3577 mImpl->mModel->mLineWrapMode,
3579 mImpl->mModel->mIgnoreSpacesAfterText,
3580 mImpl->mModel->mMatchSystemLanguageDirection );
3582 // Resize the vector of positions to have the same size than the vector of glyphs.
3583 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3584 glyphPositions.Resize( totalNumberOfGlyphs );
3586 // Whether the last character is a new paragraph character.
3587 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3588 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3590 // The initial glyph and the number of glyphs to layout.
3591 layoutParameters.startGlyphIndex = startGlyphIndex;
3592 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3593 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3594 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3596 // Update the ellipsis
3597 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3599 if( NULL != mImpl->mEventData )
3601 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3603 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3605 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3607 // Disable ellipsis when editing
3608 elideTextEnabled = false;
3611 // Reset the scroll position in inactive state
3612 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3614 ResetScrollPosition();
3618 // Update the visual model.
3620 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3622 mImpl->mModel->mVisualModel->mLines,
3626 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3630 layoutSize = newLayoutSize;
3632 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3634 mImpl->mIsTextDirectionRTL = false;
3637 // Reorder the lines
3638 if( NO_OPERATION != ( REORDER & operations ) )
3640 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3641 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3643 // Check first if there are paragraphs with bidirectional info.
3644 if( 0u != bidirectionalInfo.Count() )
3647 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3649 // Reorder the lines.
3650 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3651 ReorderLines( bidirectionalInfo,
3653 requestedNumberOfCharacters,
3654 mImpl->mModel->mVisualModel->mLines,
3655 bidirectionalLineInfo );
3657 // Set the bidirectional info per line into the layout parameters.
3658 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3659 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3661 // Re-layout the text. Reorder those lines with right to left characters.
3662 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3664 requestedNumberOfCharacters,
3667 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3669 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3672 mImpl->mIsTextDirectionRTL = firstline->direction;
3678 // Sets the layout size.
3679 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3681 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3686 if( NO_OPERATION != ( ALIGN & operations ) )
3688 // The laid-out lines.
3689 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3691 // Need to align with the control's size as the text may contain lines
3692 // starting either with left to right text or right to left.
3693 mImpl->mLayoutEngine.Align( size,
3695 requestedNumberOfCharacters,
3696 mImpl->mModel->mHorizontalAlignment,
3698 mImpl->mModel->mAlignmentOffset,
3699 mImpl->mLayoutDirection,
3700 mImpl->mModel->mMatchSystemLanguageDirection );
3704 #if defined(DEBUG_ENABLED)
3705 std::string currentText;
3706 GetText( currentText );
3707 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3709 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3713 void Controller::CalculateVerticalOffset( const Size& controlSize )
3715 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3717 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3719 // Get the line height of the default font.
3720 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3723 switch( mImpl->mModel->mVerticalAlignment )
3725 case VerticalAlignment::TOP:
3727 mImpl->mModel->mScrollPosition.y = 0.f;
3730 case VerticalAlignment::CENTER:
3732 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3735 case VerticalAlignment::BOTTOM:
3737 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3743 // private : Events.
3745 void Controller::ProcessModifyEvents()
3747 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3749 if( 0u == events.Count() )
3755 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3756 endIt = events.End();
3760 const ModifyEvent& event = *it;
3762 if( ModifyEvent::TEXT_REPLACED == event.type )
3764 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3765 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3767 TextReplacedEvent();
3769 else if( ModifyEvent::TEXT_INSERTED == event.type )
3771 TextInsertedEvent();
3773 else if( ModifyEvent::TEXT_DELETED == event.type )
3775 // Placeholder-text cannot be deleted
3776 if( !mImpl->IsShowingPlaceholderText() )
3783 if( NULL != mImpl->mEventData )
3785 // When the text is being modified, delay cursor blinking
3786 mImpl->mEventData->mDecorator->DelayCursorBlink();
3788 // Update selection position after modifying the text
3789 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3790 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3793 // Discard temporary text
3797 void Controller::TextReplacedEvent()
3799 // The natural size needs to be re-calculated.
3800 mImpl->mRecalculateNaturalSize = true;
3802 // The text direction needs to be updated.
3803 mImpl->mUpdateTextDirection = true;
3805 // Apply modifications to the model
3806 mImpl->mOperationsPending = ALL_OPERATIONS;
3809 void Controller::TextInsertedEvent()
3811 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3813 if( NULL == mImpl->mEventData )
3818 mImpl->mEventData->mCheckScrollAmount = true;
3820 // The natural size needs to be re-calculated.
3821 mImpl->mRecalculateNaturalSize = true;
3823 // The text direction needs to be updated.
3824 mImpl->mUpdateTextDirection = true;
3826 // Apply modifications to the model; TODO - Optimize this
3827 mImpl->mOperationsPending = ALL_OPERATIONS;
3830 void Controller::TextDeletedEvent()
3832 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3834 if( NULL == mImpl->mEventData )
3839 mImpl->mEventData->mCheckScrollAmount = true;
3841 // The natural size needs to be re-calculated.
3842 mImpl->mRecalculateNaturalSize = true;
3844 // The text direction needs to be updated.
3845 mImpl->mUpdateTextDirection = true;
3847 // Apply modifications to the model; TODO - Optimize this
3848 mImpl->mOperationsPending = ALL_OPERATIONS;
3851 void Controller::SelectEvent( float x, float y, bool selectAll )
3853 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3855 if( NULL != mImpl->mEventData )
3859 Event event( Event::SELECT_ALL );
3860 mImpl->mEventData->mEventQueue.push_back( event );
3864 Event event( Event::SELECT );
3865 event.p2.mFloat = x;
3866 event.p3.mFloat = y;
3867 mImpl->mEventData->mEventQueue.push_back( event );
3870 mImpl->mEventData->mCheckScrollAmount = true;
3871 mImpl->mEventData->mIsLeftHandleSelected = true;
3872 mImpl->mEventData->mIsRightHandleSelected = true;
3873 mImpl->RequestRelayout();
3877 bool Controller::DeleteEvent( int keyCode )
3879 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3881 bool removed = false;
3883 if( NULL == mImpl->mEventData )
3888 // InputMethodContext is no longer handling key-events
3889 mImpl->ClearPreEditFlag();
3891 if( EventData::SELECTING == mImpl->mEventData->mState )
3893 removed = RemoveSelectedText();
3895 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3897 // Remove the character before the current cursor position
3898 removed = RemoveText( -1,
3900 UPDATE_INPUT_STYLE );
3902 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
3904 // Remove the character after the current cursor position
3905 removed = RemoveText( 0,
3907 UPDATE_INPUT_STYLE );
3912 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3913 !mImpl->IsPlaceholderAvailable() )
3915 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3919 ShowPlaceholderText();
3921 mImpl->mEventData->mUpdateCursorPosition = true;
3922 mImpl->mEventData->mScrollAfterDelete = true;
3928 // private : Helpers.
3930 void Controller::ResetText()
3933 mImpl->mModel->mLogicalModel->mText.Clear();
3935 // We have cleared everything including the placeholder-text
3936 mImpl->PlaceholderCleared();
3938 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3939 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3940 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3942 // Clear any previous text.
3943 mImpl->mTextUpdateInfo.mClearAll = true;
3945 // The natural size needs to be re-calculated.
3946 mImpl->mRecalculateNaturalSize = true;
3948 // The text direction needs to be updated.
3949 mImpl->mUpdateTextDirection = true;
3951 // Apply modifications to the model
3952 mImpl->mOperationsPending = ALL_OPERATIONS;
3955 void Controller::ShowPlaceholderText()
3957 if( mImpl->IsPlaceholderAvailable() )
3959 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3961 if( NULL == mImpl->mEventData )
3966 mImpl->mEventData->mIsShowingPlaceholderText = true;
3968 // Disable handles when showing place-holder text
3969 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3970 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3971 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3973 const char* text( NULL );
3976 // TODO - Switch Placeholder text when changing state
3977 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3978 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3980 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3981 size = mImpl->mEventData->mPlaceholderTextActive.size();
3985 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3986 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3989 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3990 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3992 // Reset model for showing placeholder.
3993 mImpl->mModel->mLogicalModel->mText.Clear();
3994 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3996 // Convert text into UTF-32
3997 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3998 utf32Characters.Resize( size );
4000 // This is a bit horrible but std::string returns a (signed) char*
4001 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4003 // Transform a text array encoded in utf8 into an array encoded in utf32.
4004 // It returns the actual number of characters.
4005 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4006 utf32Characters.Resize( characterCount );
4008 // The characters to be added.
4009 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4011 // Reset the cursor position
4012 mImpl->mEventData->mPrimaryCursorPosition = 0;
4014 // The natural size needs to be re-calculated.
4015 mImpl->mRecalculateNaturalSize = true;
4017 // The text direction needs to be updated.
4018 mImpl->mUpdateTextDirection = true;
4020 // Apply modifications to the model
4021 mImpl->mOperationsPending = ALL_OPERATIONS;
4023 // Update the rest of the model during size negotiation
4024 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4028 void Controller::ClearFontData()
4030 if( mImpl->mFontDefaults )
4032 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4035 // Set flags to update the model.
4036 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4037 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4038 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4040 mImpl->mTextUpdateInfo.mClearAll = true;
4041 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4042 mImpl->mRecalculateNaturalSize = true;
4044 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4050 UPDATE_LAYOUT_SIZE |
4055 void Controller::ClearStyleData()
4057 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4058 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4061 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4063 // Reset the cursor position
4064 if( NULL != mImpl->mEventData )
4066 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4068 // Update the cursor if it's in editing mode.
4069 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4071 mImpl->mEventData->mUpdateCursorPosition = true;
4076 void Controller::ResetScrollPosition()
4078 if( NULL != mImpl->mEventData )
4080 // Reset the scroll position.
4081 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4082 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4086 void Controller::SetControlInterface( ControlInterface* controlInterface )
4088 mImpl->mControlInterface = controlInterface;
4091 bool Controller::ShouldClearFocusOnEscape() const
4093 return mImpl->mShouldClearFocusOnEscape;
4096 // private : Private contructors & copy operator.
4098 Controller::Controller()
4101 mImpl = new Controller::Impl( NULL, NULL );
4104 Controller::Controller( ControlInterface* controlInterface )
4106 mImpl = new Controller::Impl( controlInterface, NULL );
4109 Controller::Controller( ControlInterface* controlInterface,
4110 EditableControlInterface* editableControlInterface )
4112 mImpl = new Controller::Impl( controlInterface,
4113 editableControlInterface );
4116 // The copy constructor and operator are left unimplemented.
4118 // protected : Destructor.
4120 Controller::~Controller()
4127 } // namespace Toolkit