2 * Copyright (c) 2019 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>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
28 #include <dali/devel-api/text-abstraction/font-client.h>
29 #include <dali/devel-api/adaptor-framework/key-devel.h>
32 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
33 #include <dali-toolkit/internal/text/bidirectional-support.h>
34 #include <dali-toolkit/internal/text/character-set-conversion.h>
35 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
36 #include <dali-toolkit/internal/text/markup-processor.h>
37 #include <dali-toolkit/internal/text/multi-language-support.h>
38 #include <dali-toolkit/internal/text/text-controller-impl.h>
39 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
49 const float MAX_FLOAT = std::numeric_limits<float>::max();
51 const std::string EMPTY_STRING("");
53 const std::string KEY_C_NAME = "c";
54 const std::string KEY_V_NAME = "v";
55 const std::string KEY_X_NAME = "x";
57 const char * const PLACEHOLDER_TEXT = "text";
58 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
59 const char * const PLACEHOLDER_COLOR = "color";
60 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
61 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
62 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
63 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
64 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 const unsigned int MAX_TEXT_LENGTH = 1024u * 32u;
67 float ConvertToEven( float value )
69 int intValue(static_cast<int>( value ));
70 return static_cast<float>( intValue + ( intValue & 1 ) );
73 int ConvertPixelToPint( float pixel )
75 unsigned int horizontalDpi = 0u;
76 unsigned int verticalDpi = 0u;
77 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
78 fontClient.GetDpi( horizontalDpi, verticalDpi );
80 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
95 * @brief Adds a new font description run for the selected text.
97 * The new font parameters are added after the call to this method.
99 * @param[in] eventData The event data pointer.
100 * @param[in] logicalModel The logical model where to add the new font description run.
101 * @param[out] startOfSelectedText Index to the first selected character.
102 * @param[out] lengthOfSelectedText Number of selected characters.
104 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
105 LogicalModelPtr logicalModel,
106 CharacterIndex& startOfSelectedText,
107 Length& lengthOfSelectedText )
109 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
111 // Get start and end position of selection
112 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
113 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
116 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
117 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
119 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
121 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
122 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
124 // Recalculate the selection highlight as the metrics may have changed.
125 eventData->mUpdateLeftSelectionPosition = true;
126 eventData->mUpdateRightSelectionPosition = true;
127 eventData->mUpdateHighlightBox = true;
129 return fontDescriptionRun;
132 // public : Constructor.
134 ControllerPtr Controller::New()
136 return ControllerPtr( new Controller() );
139 ControllerPtr Controller::New( ControlInterface* controlInterface )
141 return ControllerPtr( new Controller( controlInterface ) );
144 ControllerPtr Controller::New( ControlInterface* controlInterface,
145 EditableControlInterface* editableControlInterface )
147 return ControllerPtr( new Controller( controlInterface,
148 editableControlInterface ) );
151 // public : Configure the text controller.
153 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
157 delete mImpl->mEventData;
158 mImpl->mEventData = NULL;
160 // Nothing else to do.
164 if( NULL == mImpl->mEventData )
166 mImpl->mEventData = new EventData( decorator, inputMethodContext );
170 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
172 // Metrics for bitmap & vector based glyphs are different
173 mImpl->mMetrics->SetGlyphType( glyphType );
175 // Clear the font-specific data
178 mImpl->RequestRelayout();
181 void Controller::SetMarkupProcessorEnabled( bool enable )
183 if( enable != mImpl->mMarkupProcessorEnabled )
185 //If Text was already set, call the SetText again for enabling or disabling markup
186 mImpl->mMarkupProcessorEnabled = enable;
193 bool Controller::IsMarkupProcessorEnabled() const
195 return mImpl->mMarkupProcessorEnabled;
198 void Controller::SetAutoScrollEnabled( bool enable )
200 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
202 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
206 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
207 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
217 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
218 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
225 mImpl->mIsAutoScrollEnabled = enable;
226 mImpl->RequestRelayout();
230 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
231 mImpl->mIsAutoScrollEnabled = false;
235 bool Controller::IsAutoScrollEnabled() const
237 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
239 return mImpl->mIsAutoScrollEnabled;
242 CharacterDirection Controller::GetAutoScrollDirection() const
244 return mImpl->mIsTextDirectionRTL;
247 float Controller::GetAutoScrollLineAlignment() const
251 if( mImpl->mModel->mVisualModel &&
252 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
254 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
260 void Controller::SetHorizontalScrollEnabled( bool enable )
262 if( ( NULL != mImpl->mEventData ) &&
263 mImpl->mEventData->mDecorator )
265 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
268 bool Controller::IsHorizontalScrollEnabled() const
270 if( ( NULL != mImpl->mEventData ) &&
271 mImpl->mEventData->mDecorator )
273 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
279 void Controller::SetVerticalScrollEnabled( bool enable )
281 if( ( NULL != mImpl->mEventData ) &&
282 mImpl->mEventData->mDecorator )
284 if( mImpl->mEventData->mDecorator )
286 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
291 bool Controller::IsVerticalScrollEnabled() const
293 if( ( NULL != mImpl->mEventData ) &&
294 mImpl->mEventData->mDecorator )
296 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
302 void Controller::SetSmoothHandlePanEnabled( bool enable )
304 if( ( NULL != mImpl->mEventData ) &&
305 mImpl->mEventData->mDecorator )
307 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
311 bool Controller::IsSmoothHandlePanEnabled() const
313 if( ( NULL != mImpl->mEventData ) &&
314 mImpl->mEventData->mDecorator )
316 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
322 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
324 mImpl->mMaximumNumberOfCharacters = std::min( maxCharacters, MAX_TEXT_LENGTH );
327 int Controller::GetMaximumNumberOfCharacters()
329 return mImpl->mMaximumNumberOfCharacters;
332 void Controller::SetEnableCursorBlink( bool enable )
334 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
336 if( NULL != mImpl->mEventData )
338 mImpl->mEventData->mCursorBlinkEnabled = enable;
341 mImpl->mEventData->mDecorator )
343 mImpl->mEventData->mDecorator->StopCursorBlink();
348 bool Controller::GetEnableCursorBlink() const
350 if( NULL != mImpl->mEventData )
352 return mImpl->mEventData->mCursorBlinkEnabled;
358 void Controller::SetMultiLineEnabled( bool enable )
360 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
362 if( layout != mImpl->mLayoutEngine.GetLayout() )
364 // Set the layout type.
365 mImpl->mLayoutEngine.SetLayout( layout );
367 // Set the flags to redo the layout operations
368 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
373 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
374 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
376 // Need to recalculate natural size
377 mImpl->mRecalculateNaturalSize = true;
379 mImpl->RequestRelayout();
383 bool Controller::IsMultiLineEnabled() const
385 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
388 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
390 if( alignment != mImpl->mModel->mHorizontalAlignment )
392 // Set the alignment.
393 mImpl->mModel->mHorizontalAlignment = alignment;
395 // Set the flag to redo the alignment operation.
396 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
398 if( mImpl->mEventData )
400 mImpl->mEventData->mUpdateAlignment = true;
402 // Update the cursor if it's in editing mode
403 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
405 mImpl->ChangeState( EventData::EDITING );
406 mImpl->mEventData->mUpdateCursorPosition = true;
410 mImpl->RequestRelayout();
414 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
416 return mImpl->mModel->mHorizontalAlignment;
419 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
421 if( alignment != mImpl->mModel->mVerticalAlignment )
423 // Set the alignment.
424 mImpl->mModel->mVerticalAlignment = alignment;
426 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
428 mImpl->RequestRelayout();
432 VerticalAlignment::Type Controller::GetVerticalAlignment() const
434 return mImpl->mModel->mVerticalAlignment;
437 bool Controller::IsIgnoreSpacesAfterText() const
439 return mImpl->mModel->mIgnoreSpacesAfterText;
442 void Controller::SetIgnoreSpacesAfterText( bool ignore )
444 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
447 bool Controller::IsMatchSystemLanguageDirection() const
449 return mImpl->mModel->mMatchSystemLanguageDirection;
452 void Controller::SetMatchSystemLanguageDirection( bool match )
454 mImpl->mModel->mMatchSystemLanguageDirection = match;
457 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
459 mImpl->mLayoutDirection = layoutDirection;
462 bool Controller::IsShowingRealText() const
464 return mImpl->IsShowingRealText();
468 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
470 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
472 // Set the text wrap mode.
473 mImpl->mModel->mLineWrapMode = lineWrapMode;
476 // Update Text layout for applying wrap mode
477 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
482 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
483 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
484 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
487 mImpl->RequestRelayout();
491 Text::LineWrap::Mode Controller::GetLineWrapMode() const
493 return mImpl->mModel->mLineWrapMode;
496 void Controller::SetTextElideEnabled( bool enabled )
498 mImpl->mModel->mElideEnabled = enabled;
501 bool Controller::IsTextElideEnabled() const
503 return mImpl->mModel->mElideEnabled;
506 void Controller::SetTextFitEnabled(bool enabled)
508 mImpl->mTextFitEnabled = enabled;
511 bool Controller::IsTextFitEnabled() const
513 return mImpl->mTextFitEnabled;
516 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
522 mImpl->mTextFitMinSize = minSize;
527 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
533 float Controller::GetTextFitMinSize() const
535 return mImpl->mTextFitMinSize;
538 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
544 mImpl->mTextFitMaxSize = maxSize;
549 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
555 float Controller::GetTextFitMaxSize() const
557 return mImpl->mTextFitMaxSize;
560 void Controller::SetTextFitStepSize( float step, FontSizeType type )
566 mImpl->mTextFitStepSize = step;
571 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
577 float Controller::GetTextFitStepSize() const
579 return mImpl->mTextFitStepSize;
582 void Controller::SetTextFitContentSize(Vector2 size)
584 mImpl->mTextFitContentSize = size;
587 Vector2 Controller::GetTextFitContentSize() const
589 return mImpl->mTextFitContentSize;
592 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
594 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
595 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
597 // Update placeholder if there is no text
598 if( mImpl->IsShowingPlaceholderText() ||
599 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
601 ShowPlaceholderText();
605 bool Controller::IsPlaceholderTextElideEnabled() const
607 return mImpl->mEventData->mIsPlaceholderElideEnabled;
610 void Controller::SetSelectionEnabled( bool enabled )
612 mImpl->mEventData->mSelectionEnabled = enabled;
615 bool Controller::IsSelectionEnabled() const
617 return mImpl->mEventData->mSelectionEnabled;
620 void Controller::SetShiftSelectionEnabled( bool enabled )
622 mImpl->mEventData->mShiftSelectionFlag = enabled;
625 bool Controller::IsShiftSelectionEnabled() const
627 return mImpl->mEventData->mShiftSelectionFlag;
630 void Controller::SetGrabHandleEnabled( bool enabled )
632 mImpl->mEventData->mGrabHandleEnabled = enabled;
635 bool Controller::IsGrabHandleEnabled() const
637 return mImpl->mEventData->mGrabHandleEnabled;
640 void Controller::SetGrabHandlePopupEnabled(bool enabled)
642 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
645 bool Controller::IsGrabHandlePopupEnabled() const
647 return mImpl->mEventData->mGrabHandlePopupEnabled;
652 void Controller::SetText( const std::string& text )
654 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
656 // Reset keyboard as text changed
657 mImpl->ResetInputMethodContext();
659 // Remove the previously set text and style.
665 CharacterIndex lastCursorIndex = 0u;
667 if( NULL != mImpl->mEventData )
669 // If popup shown then hide it by switching to Editing state
670 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
671 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
672 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
673 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
675 mImpl->ChangeState( EventData::EDITING );
681 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
683 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
684 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
685 mImpl->mModel->mLogicalModel->mEmbeddedItems );
687 Length textSize = 0u;
688 const uint8_t* utf8 = NULL;
689 if( mImpl->mMarkupProcessorEnabled )
691 ProcessMarkupString( text, markupProcessData );
692 textSize = markupProcessData.markupProcessedText.size();
694 // This is a bit horrible but std::string returns a (signed) char*
695 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
699 textSize = text.size();
701 // This is a bit horrible but std::string returns a (signed) char*
702 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
705 // Limit the text size. If the text size is too large, crash or deadlock will occur.
706 if( textSize > MAX_TEXT_LENGTH )
708 DALI_LOG_WARNING( "The text size is too large(%d), limit the length to 32,768u\n", textSize );
709 textSize = MAX_TEXT_LENGTH;
712 // Convert text into UTF-32
713 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
714 utf32Characters.Resize( textSize );
716 // Transform a text array encoded in utf8 into an array encoded in utf32.
717 // It returns the actual number of characters.
718 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
719 utf32Characters.Resize( characterCount );
721 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
722 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
724 // The characters to be added.
725 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
727 // To reset the cursor position
728 lastCursorIndex = characterCount;
730 // Update the rest of the model during size negotiation
731 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
733 // The natural size needs to be re-calculated.
734 mImpl->mRecalculateNaturalSize = true;
736 // The text direction needs to be updated.
737 mImpl->mUpdateTextDirection = true;
739 // Apply modifications to the model
740 mImpl->mOperationsPending = ALL_OPERATIONS;
744 ShowPlaceholderText();
747 // Resets the cursor position.
748 ResetCursorPosition( lastCursorIndex );
750 // Scrolls the text to make the cursor visible.
751 ResetScrollPosition();
753 mImpl->RequestRelayout();
755 if( NULL != mImpl->mEventData )
757 // Cancel previously queued events
758 mImpl->mEventData->mEventQueue.clear();
761 // Do this last since it provides callbacks into application code.
762 if( NULL != mImpl->mEditableControlInterface )
764 mImpl->mEditableControlInterface->TextChanged();
768 void Controller::GetText( std::string& text ) const
770 if( !mImpl->IsShowingPlaceholderText() )
772 // Retrieves the text string.
773 mImpl->GetText( 0u, text );
777 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
781 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
783 if( NULL != mImpl->mEventData )
785 if( PLACEHOLDER_TYPE_INACTIVE == type )
787 mImpl->mEventData->mPlaceholderTextInactive = text;
791 mImpl->mEventData->mPlaceholderTextActive = text;
794 // Update placeholder if there is no text
795 if( mImpl->IsShowingPlaceholderText() ||
796 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
798 ShowPlaceholderText();
803 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
805 if( NULL != mImpl->mEventData )
807 if( PLACEHOLDER_TYPE_INACTIVE == type )
809 text = mImpl->mEventData->mPlaceholderTextInactive;
813 text = mImpl->mEventData->mPlaceholderTextActive;
818 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
820 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
822 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
824 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
825 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
829 mImpl->RequestRelayout();
833 // public : Default style & Input style
835 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
837 if( NULL == mImpl->mFontDefaults )
839 mImpl->mFontDefaults = new FontDefaults();
842 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
843 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
844 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
846 // Clear the font-specific data
849 mImpl->RequestRelayout();
852 const std::string& Controller::GetDefaultFontFamily() const
854 if( NULL != mImpl->mFontDefaults )
856 return mImpl->mFontDefaults->mFontDescription.family;
862 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
864 if( NULL != mImpl->mEventData )
866 if( NULL == mImpl->mEventData->mPlaceholderFont )
868 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
871 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
872 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
873 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
875 mImpl->RequestRelayout();
879 const std::string& Controller::GetPlaceholderFontFamily() const
881 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
883 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
889 void Controller::SetDefaultFontWeight( FontWeight weight )
891 if( NULL == mImpl->mFontDefaults )
893 mImpl->mFontDefaults = new FontDefaults();
896 mImpl->mFontDefaults->mFontDescription.weight = weight;
897 mImpl->mFontDefaults->weightDefined = true;
899 // Clear the font-specific data
902 mImpl->RequestRelayout();
905 bool Controller::IsDefaultFontWeightDefined() const
907 if( NULL != mImpl->mFontDefaults )
909 return mImpl->mFontDefaults->weightDefined;
915 FontWeight Controller::GetDefaultFontWeight() const
917 if( NULL != mImpl->mFontDefaults )
919 return mImpl->mFontDefaults->mFontDescription.weight;
922 return TextAbstraction::FontWeight::NORMAL;
925 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
927 if( NULL != mImpl->mEventData )
929 if( NULL == mImpl->mEventData->mPlaceholderFont )
931 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
934 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
935 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
937 mImpl->RequestRelayout();
941 bool Controller::IsPlaceholderTextFontWeightDefined() const
943 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
945 return mImpl->mEventData->mPlaceholderFont->weightDefined;
950 FontWeight Controller::GetPlaceholderTextFontWeight() const
952 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
954 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
957 return TextAbstraction::FontWeight::NORMAL;
960 void Controller::SetDefaultFontWidth( FontWidth width )
962 if( NULL == mImpl->mFontDefaults )
964 mImpl->mFontDefaults = new FontDefaults();
967 mImpl->mFontDefaults->mFontDescription.width = width;
968 mImpl->mFontDefaults->widthDefined = true;
970 // Clear the font-specific data
973 mImpl->RequestRelayout();
976 bool Controller::IsDefaultFontWidthDefined() const
978 if( NULL != mImpl->mFontDefaults )
980 return mImpl->mFontDefaults->widthDefined;
986 FontWidth Controller::GetDefaultFontWidth() const
988 if( NULL != mImpl->mFontDefaults )
990 return mImpl->mFontDefaults->mFontDescription.width;
993 return TextAbstraction::FontWidth::NORMAL;
996 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
998 if( NULL != mImpl->mEventData )
1000 if( NULL == mImpl->mEventData->mPlaceholderFont )
1002 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1005 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
1006 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
1008 mImpl->RequestRelayout();
1012 bool Controller::IsPlaceholderTextFontWidthDefined() const
1014 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1016 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1021 FontWidth Controller::GetPlaceholderTextFontWidth() const
1023 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1025 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1028 return TextAbstraction::FontWidth::NORMAL;
1031 void Controller::SetDefaultFontSlant( FontSlant slant )
1033 if( NULL == mImpl->mFontDefaults )
1035 mImpl->mFontDefaults = new FontDefaults();
1038 mImpl->mFontDefaults->mFontDescription.slant = slant;
1039 mImpl->mFontDefaults->slantDefined = true;
1041 // Clear the font-specific data
1044 mImpl->RequestRelayout();
1047 bool Controller::IsDefaultFontSlantDefined() const
1049 if( NULL != mImpl->mFontDefaults )
1051 return mImpl->mFontDefaults->slantDefined;
1056 FontSlant Controller::GetDefaultFontSlant() const
1058 if( NULL != mImpl->mFontDefaults )
1060 return mImpl->mFontDefaults->mFontDescription.slant;
1063 return TextAbstraction::FontSlant::NORMAL;
1066 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1068 if( NULL != mImpl->mEventData )
1070 if( NULL == mImpl->mEventData->mPlaceholderFont )
1072 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1075 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1076 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1078 mImpl->RequestRelayout();
1082 bool Controller::IsPlaceholderTextFontSlantDefined() const
1084 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1086 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1091 FontSlant Controller::GetPlaceholderTextFontSlant() const
1093 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1095 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1098 return TextAbstraction::FontSlant::NORMAL;
1101 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1103 if( NULL == mImpl->mFontDefaults )
1105 mImpl->mFontDefaults = new FontDefaults();
1112 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1113 mImpl->mFontDefaults->sizeDefined = true;
1118 // Point size = Pixel size * 72.f / DPI
1119 unsigned int horizontalDpi = 0u;
1120 unsigned int verticalDpi = 0u;
1121 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1122 fontClient.GetDpi( horizontalDpi, verticalDpi );
1124 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1125 mImpl->mFontDefaults->sizeDefined = true;
1130 // Clear the font-specific data
1133 mImpl->RequestRelayout();
1136 float Controller::GetDefaultFontSize( FontSizeType type ) const
1139 if( NULL != mImpl->mFontDefaults )
1145 value = mImpl->mFontDefaults->mDefaultPointSize;
1150 // Pixel size = Point size * DPI / 72.f
1151 unsigned int horizontalDpi = 0u;
1152 unsigned int verticalDpi = 0u;
1153 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1154 fontClient.GetDpi( horizontalDpi, verticalDpi );
1156 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1166 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1168 if( NULL != mImpl->mEventData )
1170 if( NULL == mImpl->mEventData->mPlaceholderFont )
1172 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1179 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1180 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1181 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1186 // Point size = Pixel size * 72.f / DPI
1187 unsigned int horizontalDpi = 0u;
1188 unsigned int verticalDpi = 0u;
1189 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1190 fontClient.GetDpi( horizontalDpi, verticalDpi );
1192 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1193 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1194 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1199 mImpl->RequestRelayout();
1203 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1206 if( NULL != mImpl->mEventData )
1212 if( NULL != mImpl->mEventData->mPlaceholderFont )
1214 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1218 // If the placeholder text font size is not set, then return the default font size.
1219 value = GetDefaultFontSize( POINT_SIZE );
1225 if( NULL != mImpl->mEventData->mPlaceholderFont )
1227 // Pixel size = Point size * DPI / 72.f
1228 unsigned int horizontalDpi = 0u;
1229 unsigned int verticalDpi = 0u;
1230 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1231 fontClient.GetDpi( horizontalDpi, verticalDpi );
1233 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1237 // If the placeholder text font size is not set, then return the default font size.
1238 value = GetDefaultFontSize( PIXEL_SIZE );
1249 void Controller::SetDefaultColor( const Vector4& color )
1251 mImpl->mTextColor = color;
1253 if( !mImpl->IsShowingPlaceholderText() )
1255 mImpl->mModel->mVisualModel->SetTextColor( color );
1257 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1259 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1261 mImpl->RequestRelayout();
1265 const Vector4& Controller::GetDefaultColor() const
1267 return mImpl->mTextColor;
1270 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1272 if( NULL != mImpl->mEventData )
1274 mImpl->mEventData->mPlaceholderTextColor = textColor;
1277 if( mImpl->IsShowingPlaceholderText() )
1279 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1280 mImpl->RequestRelayout();
1284 const Vector4& Controller::GetPlaceholderTextColor() const
1286 if( NULL != mImpl->mEventData )
1288 return mImpl->mEventData->mPlaceholderTextColor;
1291 return Color::BLACK;
1294 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1296 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1298 mImpl->RequestRelayout();
1301 const Vector2& Controller::GetShadowOffset() const
1303 return mImpl->mModel->mVisualModel->GetShadowOffset();
1306 void Controller::SetShadowColor( const Vector4& shadowColor )
1308 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1310 mImpl->RequestRelayout();
1313 const Vector4& Controller::GetShadowColor() const
1315 return mImpl->mModel->mVisualModel->GetShadowColor();
1318 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1320 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1322 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1324 mImpl->RequestRelayout();
1328 const float& Controller::GetShadowBlurRadius() const
1330 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1333 void Controller::SetUnderlineColor( const Vector4& color )
1335 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1337 mImpl->RequestRelayout();
1340 const Vector4& Controller::GetUnderlineColor() const
1342 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1345 void Controller::SetUnderlineEnabled( bool enabled )
1347 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1349 mImpl->RequestRelayout();
1352 bool Controller::IsUnderlineEnabled() const
1354 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1357 void Controller::SetUnderlineHeight( float height )
1359 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1361 mImpl->RequestRelayout();
1364 float Controller::GetUnderlineHeight() const
1366 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1369 void Controller::SetOutlineColor( const Vector4& color )
1371 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1373 mImpl->RequestRelayout();
1376 const Vector4& Controller::GetOutlineColor() const
1378 return mImpl->mModel->mVisualModel->GetOutlineColor();
1381 void Controller::SetOutlineWidth( uint16_t width )
1383 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1385 mImpl->RequestRelayout();
1388 uint16_t Controller::GetOutlineWidth() const
1390 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1393 void Controller::SetBackgroundColor( const Vector4& color )
1395 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1397 mImpl->RequestRelayout();
1400 const Vector4& Controller::GetBackgroundColor() const
1402 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1405 void Controller::SetBackgroundEnabled( bool enabled )
1407 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1409 mImpl->RequestRelayout();
1412 bool Controller::IsBackgroundEnabled() const
1414 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1417 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1419 if( NULL == mImpl->mEmbossDefaults )
1421 mImpl->mEmbossDefaults = new EmbossDefaults();
1424 mImpl->mEmbossDefaults->properties = embossProperties;
1427 const std::string& Controller::GetDefaultEmbossProperties() const
1429 if( NULL != mImpl->mEmbossDefaults )
1431 return mImpl->mEmbossDefaults->properties;
1434 return EMPTY_STRING;
1437 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1439 if( NULL == mImpl->mOutlineDefaults )
1441 mImpl->mOutlineDefaults = new OutlineDefaults();
1444 mImpl->mOutlineDefaults->properties = outlineProperties;
1447 const std::string& Controller::GetDefaultOutlineProperties() const
1449 if( NULL != mImpl->mOutlineDefaults )
1451 return mImpl->mOutlineDefaults->properties;
1454 return EMPTY_STRING;
1457 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1459 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1461 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1462 mImpl->mRecalculateNaturalSize = true;
1468 float Controller::GetDefaultLineSpacing() const
1470 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1473 void Controller::SetInputColor( const Vector4& color )
1475 if( NULL != mImpl->mEventData )
1477 mImpl->mEventData->mInputStyle.textColor = color;
1478 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1480 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1482 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1484 // Get start and end position of selection
1485 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1486 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1488 // Add the color run.
1489 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1490 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1492 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1493 colorRun.color = color;
1494 colorRun.characterRun.characterIndex = startOfSelectedText;
1495 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1497 // Request to relayout.
1498 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1499 mImpl->RequestRelayout();
1501 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1502 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1503 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1508 const Vector4& Controller::GetInputColor() const
1510 if( NULL != mImpl->mEventData )
1512 return mImpl->mEventData->mInputStyle.textColor;
1515 // Return the default text's color if there is no EventData.
1516 return mImpl->mTextColor;
1520 void Controller::SetInputFontFamily( const std::string& fontFamily )
1522 if( NULL != mImpl->mEventData )
1524 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1525 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1527 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1529 CharacterIndex startOfSelectedText = 0u;
1530 Length lengthOfSelectedText = 0u;
1531 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1532 mImpl->mModel->mLogicalModel,
1533 startOfSelectedText,
1534 lengthOfSelectedText );
1536 fontDescriptionRun.familyLength = fontFamily.size();
1537 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1538 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1539 fontDescriptionRun.familyDefined = true;
1541 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1543 // Request to relayout.
1544 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1549 UPDATE_LAYOUT_SIZE |
1552 mImpl->mRecalculateNaturalSize = true;
1553 mImpl->RequestRelayout();
1555 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1556 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1557 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1559 // As the font changes, recalculate the handle positions is needed.
1560 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1561 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1562 mImpl->mEventData->mUpdateHighlightBox = true;
1563 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1568 const std::string& Controller::GetInputFontFamily() const
1570 if( NULL != mImpl->mEventData )
1572 return mImpl->mEventData->mInputStyle.familyName;
1575 // Return the default font's family if there is no EventData.
1576 return GetDefaultFontFamily();
1579 void Controller::SetInputFontWeight( FontWeight weight )
1581 if( NULL != mImpl->mEventData )
1583 mImpl->mEventData->mInputStyle.weight = weight;
1584 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1586 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1588 CharacterIndex startOfSelectedText = 0u;
1589 Length lengthOfSelectedText = 0u;
1590 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1591 mImpl->mModel->mLogicalModel,
1592 startOfSelectedText,
1593 lengthOfSelectedText );
1595 fontDescriptionRun.weight = weight;
1596 fontDescriptionRun.weightDefined = true;
1598 // Request to relayout.
1599 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1604 UPDATE_LAYOUT_SIZE |
1607 mImpl->mRecalculateNaturalSize = true;
1608 mImpl->RequestRelayout();
1610 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1611 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1612 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1614 // As the font might change, recalculate the handle positions is needed.
1615 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1616 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1617 mImpl->mEventData->mUpdateHighlightBox = true;
1618 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1623 bool Controller::IsInputFontWeightDefined() const
1625 bool defined = false;
1627 if( NULL != mImpl->mEventData )
1629 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1635 FontWeight Controller::GetInputFontWeight() const
1637 if( NULL != mImpl->mEventData )
1639 return mImpl->mEventData->mInputStyle.weight;
1642 return GetDefaultFontWeight();
1645 void Controller::SetInputFontWidth( FontWidth width )
1647 if( NULL != mImpl->mEventData )
1649 mImpl->mEventData->mInputStyle.width = width;
1650 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1652 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1654 CharacterIndex startOfSelectedText = 0u;
1655 Length lengthOfSelectedText = 0u;
1656 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1657 mImpl->mModel->mLogicalModel,
1658 startOfSelectedText,
1659 lengthOfSelectedText );
1661 fontDescriptionRun.width = width;
1662 fontDescriptionRun.widthDefined = true;
1664 // Request to relayout.
1665 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1670 UPDATE_LAYOUT_SIZE |
1673 mImpl->mRecalculateNaturalSize = true;
1674 mImpl->RequestRelayout();
1676 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1677 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1678 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1680 // As the font might change, recalculate the handle positions is needed.
1681 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1682 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1683 mImpl->mEventData->mUpdateHighlightBox = true;
1684 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1689 bool Controller::IsInputFontWidthDefined() const
1691 bool defined = false;
1693 if( NULL != mImpl->mEventData )
1695 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1701 FontWidth Controller::GetInputFontWidth() const
1703 if( NULL != mImpl->mEventData )
1705 return mImpl->mEventData->mInputStyle.width;
1708 return GetDefaultFontWidth();
1711 void Controller::SetInputFontSlant( FontSlant slant )
1713 if( NULL != mImpl->mEventData )
1715 mImpl->mEventData->mInputStyle.slant = slant;
1716 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1718 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1720 CharacterIndex startOfSelectedText = 0u;
1721 Length lengthOfSelectedText = 0u;
1722 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1723 mImpl->mModel->mLogicalModel,
1724 startOfSelectedText,
1725 lengthOfSelectedText );
1727 fontDescriptionRun.slant = slant;
1728 fontDescriptionRun.slantDefined = true;
1730 // Request to relayout.
1731 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1736 UPDATE_LAYOUT_SIZE |
1739 mImpl->mRecalculateNaturalSize = true;
1740 mImpl->RequestRelayout();
1742 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1743 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1744 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1746 // As the font might change, recalculate the handle positions is needed.
1747 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1748 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1749 mImpl->mEventData->mUpdateHighlightBox = true;
1750 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1755 bool Controller::IsInputFontSlantDefined() const
1757 bool defined = false;
1759 if( NULL != mImpl->mEventData )
1761 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1767 FontSlant Controller::GetInputFontSlant() const
1769 if( NULL != mImpl->mEventData )
1771 return mImpl->mEventData->mInputStyle.slant;
1774 return GetDefaultFontSlant();
1777 void Controller::SetInputFontPointSize( float size )
1779 if( NULL != mImpl->mEventData )
1781 mImpl->mEventData->mInputStyle.size = size;
1782 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1784 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1786 CharacterIndex startOfSelectedText = 0u;
1787 Length lengthOfSelectedText = 0u;
1788 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1789 mImpl->mModel->mLogicalModel,
1790 startOfSelectedText,
1791 lengthOfSelectedText );
1793 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1794 fontDescriptionRun.sizeDefined = true;
1796 // Request to relayout.
1797 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1802 UPDATE_LAYOUT_SIZE |
1805 mImpl->mRecalculateNaturalSize = true;
1806 mImpl->RequestRelayout();
1808 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1809 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1810 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1812 // As the font might change, recalculate the handle positions is needed.
1813 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1814 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1815 mImpl->mEventData->mUpdateHighlightBox = true;
1816 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1821 float Controller::GetInputFontPointSize() const
1823 if( NULL != mImpl->mEventData )
1825 return mImpl->mEventData->mInputStyle.size;
1828 // Return the default font's point size if there is no EventData.
1829 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1832 void Controller::SetInputLineSpacing( float lineSpacing )
1834 if( NULL != mImpl->mEventData )
1836 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1837 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1841 float Controller::GetInputLineSpacing() const
1843 if( NULL != mImpl->mEventData )
1845 return mImpl->mEventData->mInputStyle.lineSpacing;
1851 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1853 if( NULL != mImpl->mEventData )
1855 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1859 const std::string& Controller::GetInputShadowProperties() const
1861 if( NULL != mImpl->mEventData )
1863 return mImpl->mEventData->mInputStyle.shadowProperties;
1866 return EMPTY_STRING;
1869 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1871 if( NULL != mImpl->mEventData )
1873 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1877 const std::string& Controller::GetInputUnderlineProperties() const
1879 if( NULL != mImpl->mEventData )
1881 return mImpl->mEventData->mInputStyle.underlineProperties;
1884 return EMPTY_STRING;
1887 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1889 if( NULL != mImpl->mEventData )
1891 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1895 const std::string& Controller::GetInputEmbossProperties() const
1897 if( NULL != mImpl->mEventData )
1899 return mImpl->mEventData->mInputStyle.embossProperties;
1902 return GetDefaultEmbossProperties();
1905 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1907 if( NULL != mImpl->mEventData )
1909 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1913 const std::string& Controller::GetInputOutlineProperties() const
1915 if( NULL != mImpl->mEventData )
1917 return mImpl->mEventData->mInputStyle.outlineProperties;
1920 return GetDefaultOutlineProperties();
1923 void Controller::SetInputModePassword( bool passwordInput )
1925 if( NULL != mImpl->mEventData )
1927 mImpl->mEventData->mPasswordInput = passwordInput;
1931 bool Controller::IsInputModePassword()
1933 if( NULL != mImpl->mEventData )
1935 return mImpl->mEventData->mPasswordInput;
1940 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1942 if( NULL != mImpl->mEventData )
1944 mImpl->mEventData->mDoubleTapAction = action;
1948 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1950 NoTextTap::Action action = NoTextTap::NO_ACTION;
1952 if( NULL != mImpl->mEventData )
1954 action = mImpl->mEventData->mDoubleTapAction;
1960 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1962 if( NULL != mImpl->mEventData )
1964 mImpl->mEventData->mLongPressAction = action;
1968 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1970 NoTextTap::Action action = NoTextTap::NO_ACTION;
1972 if( NULL != mImpl->mEventData )
1974 action = mImpl->mEventData->mLongPressAction;
1980 bool Controller::IsUnderlineSetByString()
1982 return mImpl->mUnderlineSetByString;
1985 void Controller::UnderlineSetByString( bool setByString )
1987 mImpl->mUnderlineSetByString = setByString;
1990 bool Controller::IsShadowSetByString()
1992 return mImpl->mShadowSetByString;
1995 void Controller::ShadowSetByString( bool setByString )
1997 mImpl->mShadowSetByString = setByString;
2000 bool Controller::IsOutlineSetByString()
2002 return mImpl->mOutlineSetByString;
2005 void Controller::OutlineSetByString( bool setByString )
2007 mImpl->mOutlineSetByString = setByString;
2010 bool Controller::IsFontStyleSetByString()
2012 return mImpl->mFontStyleSetByString;
2015 void Controller::FontStyleSetByString( bool setByString )
2017 mImpl->mFontStyleSetByString = setByString;
2020 // public : Queries & retrieves.
2022 Layout::Engine& Controller::GetLayoutEngine()
2024 return mImpl->mLayoutEngine;
2027 View& Controller::GetView()
2029 return mImpl->mView;
2032 Vector3 Controller::GetNaturalSize()
2034 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2035 Vector3 naturalSize;
2037 // Make sure the model is up-to-date before layouting
2038 ProcessModifyEvents();
2040 if( mImpl->mRecalculateNaturalSize )
2042 // Operations that can be done only once until the text changes.
2043 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2049 GET_GLYPH_METRICS );
2051 // Set the update info to relayout the whole text.
2052 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2053 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2055 // Make sure the model is up-to-date before layouting
2056 mImpl->UpdateModel( onlyOnceOperations );
2058 // Layout the text for the new width.
2059 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2061 // Store the actual control's size to restore later.
2062 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2064 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2065 static_cast<OperationsMask>( onlyOnceOperations |
2067 naturalSize.GetVectorXY() );
2069 // Do not do again the only once operations.
2070 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2072 // Do the size related operations again.
2073 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2076 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2078 // Stores the natural size to avoid recalculate it again
2079 // unless the text/style changes.
2080 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2082 mImpl->mRecalculateNaturalSize = false;
2084 // Clear the update info. This info will be set the next time the text is updated.
2085 mImpl->mTextUpdateInfo.Clear();
2086 mImpl->mTextUpdateInfo.mClearAll = true;
2088 // Restore the actual control's size.
2089 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2091 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2095 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2097 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2100 naturalSize.x = ConvertToEven( naturalSize.x );
2101 naturalSize.y = ConvertToEven( naturalSize.y );
2106 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2109 mImpl->mFontDefaults->mFitPointSize = pointSize;
2110 mImpl->mFontDefaults->sizeDefined = true;
2113 // Operations that can be done only once until the text changes.
2114 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2120 GET_GLYPH_METRICS );
2122 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2123 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2125 // Make sure the model is up-to-date before layouting
2126 mImpl->UpdateModel( onlyOnceOperations );
2128 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2129 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2132 // Clear the update info. This info will be set the next time the text is updated.
2133 mImpl->mTextUpdateInfo.Clear();
2134 mImpl->mTextUpdateInfo.mClearAll = true;
2136 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2143 void Controller::FitPointSizeforLayout( Size layoutSize )
2145 const OperationsMask operations = mImpl->mOperationsPending;
2146 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2148 bool actualellipsis = mImpl->mModel->mElideEnabled;
2149 float minPointSize = mImpl->mTextFitMinSize;
2150 float maxPointSize = mImpl->mTextFitMaxSize;
2151 float pointInterval = mImpl->mTextFitStepSize;
2153 mImpl->mModel->mElideEnabled = false;
2154 Vector<float> pointSizeArray;
2157 if( pointInterval < 1.f )
2159 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2162 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2164 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2166 pointSizeArray.PushBack( i );
2169 pointSizeArray.PushBack( maxPointSize );
2171 int bestSizeIndex = 0;
2172 int min = bestSizeIndex + 1;
2173 int max = pointSizeArray.Size() - 1;
2176 int destI = ( min + max ) / 2;
2178 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2180 bestSizeIndex = min;
2186 bestSizeIndex = max;
2190 mImpl->mModel->mElideEnabled = actualellipsis;
2191 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2192 mImpl->mFontDefaults->sizeDefined = true;
2197 float Controller::GetHeightForWidth( float width )
2199 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2200 // Make sure the model is up-to-date before layouting
2201 ProcessModifyEvents();
2204 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2205 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2206 mImpl->mTextUpdateInfo.mClearAll )
2208 // Operations that can be done only once until the text changes.
2209 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2215 GET_GLYPH_METRICS );
2217 // Set the update info to relayout the whole text.
2218 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2219 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2221 // Make sure the model is up-to-date before layouting
2222 mImpl->UpdateModel( onlyOnceOperations );
2225 // Layout the text for the new width.
2226 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2228 // Store the actual control's width.
2229 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2231 DoRelayout( Size( width, MAX_FLOAT ),
2232 static_cast<OperationsMask>( onlyOnceOperations |
2236 // Do not do again the only once operations.
2237 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2239 // Do the size related operations again.
2240 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2244 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2246 // Clear the update info. This info will be set the next time the text is updated.
2247 mImpl->mTextUpdateInfo.Clear();
2248 mImpl->mTextUpdateInfo.mClearAll = true;
2250 // Restore the actual control's width.
2251 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2253 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2257 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2258 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2261 return layoutSize.height;
2264 int Controller::GetLineCount( float width )
2266 GetHeightForWidth( width );
2267 int numberofLines = mImpl->mModel->GetNumberOfLines();
2268 return numberofLines;
2271 const ModelInterface* const Controller::GetTextModel() const
2273 return mImpl->mModel.Get();
2276 float Controller::GetScrollAmountByUserInput()
2278 float scrollAmount = 0.0f;
2280 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2282 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2283 mImpl->mEventData->mCheckScrollAmount = false;
2285 return scrollAmount;
2288 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2290 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2293 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2294 layoutHeight = layout.height;
2295 scrollPosition = mImpl->mModel->mScrollPosition.y;
2296 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2300 void Controller::SetHiddenInputOption(const Property::Map& options )
2302 if( NULL == mImpl->mHiddenInput )
2304 mImpl->mHiddenInput = new HiddenText( this );
2306 mImpl->mHiddenInput->SetProperties(options);
2309 void Controller::GetHiddenInputOption(Property::Map& options )
2311 if( NULL != mImpl->mHiddenInput )
2313 mImpl->mHiddenInput->GetProperties(options);
2317 void Controller::SetPlaceholderProperty( const Property::Map& map )
2319 const Property::Map::SizeType count = map.Count();
2321 for( Property::Map::SizeType position = 0; position < count; ++position )
2323 KeyValuePair keyValue = map.GetKeyValue( position );
2324 Property::Key& key = keyValue.first;
2325 Property::Value& value = keyValue.second;
2327 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2329 std::string text = "";
2331 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2333 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2335 std::string text = "";
2337 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2339 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2342 value.Get( textColor );
2343 if( GetPlaceholderTextColor() != textColor )
2345 SetPlaceholderTextColor( textColor );
2348 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2350 std::string fontFamily = "";
2351 value.Get( fontFamily );
2352 SetPlaceholderFontFamily( fontFamily );
2354 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2356 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2358 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2361 value.Get( pointSize );
2362 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2364 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2367 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2370 value.Get( pixelSize );
2371 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2373 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2376 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2379 value.Get( ellipsis );
2380 SetPlaceholderTextElideEnabled( ellipsis );
2385 void Controller::GetPlaceholderProperty( Property::Map& map )
2387 if( NULL != mImpl->mEventData )
2389 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2391 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2393 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2395 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2398 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2399 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2401 Property::Value fontStyleMapGet;
2402 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2403 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2405 // Choose font size : POINT_SIZE or PIXEL_SIZE
2406 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2408 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2412 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2415 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2417 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2422 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2424 // Make sure the model is up-to-date before layouting
2425 ProcessModifyEvents();
2427 if ( mImpl->mUpdateTextDirection )
2429 // Operations that can be done only once until the text changes.
2430 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2436 GET_GLYPH_METRICS );
2438 // Set the update info to relayout the whole text.
2439 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2440 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2442 // Make sure the model is up-to-date before layouting
2443 mImpl->UpdateModel( onlyOnceOperations );
2445 Vector3 naturalSize;
2446 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2447 static_cast<OperationsMask>( onlyOnceOperations |
2448 LAYOUT | REORDER | UPDATE_DIRECTION ),
2449 naturalSize.GetVectorXY() );
2451 // Do not do again the only once operations.
2452 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2454 // Clear the update info. This info will be set the next time the text is updated.
2455 mImpl->mTextUpdateInfo.Clear();
2457 mImpl->mUpdateTextDirection = false;
2460 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2463 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2465 return mImpl->mModel->GetVerticalLineAlignment();
2468 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2470 mImpl->mModel->mVerticalLineAlignment = alignment;
2473 // public : Relayout.
2475 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2477 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2479 UpdateTextType updateTextType = NONE_UPDATED;
2481 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2483 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2485 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2486 updateTextType = MODEL_UPDATED;
2489 // Clear the update info. This info will be set the next time the text is updated.
2490 mImpl->mTextUpdateInfo.Clear();
2492 // Not worth to relayout if width or height is equal to zero.
2493 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2495 return updateTextType;
2498 // Whether a new size has been set.
2499 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2503 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2505 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2506 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2507 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2509 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2512 // Layout operations that need to be done if the size changes.
2513 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2516 UPDATE_LAYOUT_SIZE |
2518 // Set the update info to relayout the whole text.
2519 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2520 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2522 // Store the size used to layout the text.
2523 mImpl->mModel->mVisualModel->mControlSize = size;
2526 // Whether there are modify events.
2527 if( 0u != mImpl->mModifyEvents.Count() )
2529 // Style operations that need to be done if the text is modified.
2530 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2534 // Set the update info to elide the text.
2535 if( mImpl->mModel->mElideEnabled ||
2536 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2538 // Update Text layout for applying elided
2539 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2542 UPDATE_LAYOUT_SIZE |
2544 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2545 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2548 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2550 // Clear the update info. This info will be set the next time the text is updated.
2551 mImpl->mTextUpdateInfo.mClearAll = true;
2552 // Apply modifications to the model
2553 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2554 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2561 mImpl->mLayoutDirection = layoutDirection;
2564 // Make sure the model is up-to-date before layouting.
2565 ProcessModifyEvents();
2566 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2570 updated = DoRelayout( size,
2571 mImpl->mOperationsPending,
2572 layoutSize ) || updated;
2577 updateTextType = MODEL_UPDATED;
2580 // Do not re-do any operation until something changes.
2581 mImpl->mOperationsPending = NO_OPERATION;
2582 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2584 // Whether the text control is editable
2585 const bool isEditable = NULL != mImpl->mEventData;
2587 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2589 if( newSize && isEditable )
2591 offset = mImpl->mModel->mScrollPosition;
2594 if( !isEditable || !IsMultiLineEnabled() )
2596 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2597 CalculateVerticalOffset( size );
2604 // If there is a new size, the scroll position needs to be clamped.
2605 mImpl->ClampHorizontalScroll( layoutSize );
2607 // Update the decorator's positions is needed if there is a new size.
2608 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2611 // Move the cursor, grab handle etc.
2612 if( mImpl->ProcessInputEvents() )
2614 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2618 // Clear the update info. This info will be set the next time the text is updated.
2619 mImpl->mTextUpdateInfo.Clear();
2620 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2622 return updateTextType;
2625 void Controller::RequestRelayout()
2627 mImpl->RequestRelayout();
2630 // public : Input style change signals.
2632 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2634 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2637 void Controller::ProcessInputStyleChangedSignals()
2639 if( NULL == mImpl->mEventData )
2645 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2646 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2650 const InputStyle::Mask mask = *it;
2652 if( NULL != mImpl->mEditableControlInterface )
2654 // Emit the input style changed signal.
2655 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2659 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2662 // public : Text-input Event Queuing.
2664 void Controller::KeyboardFocusGainEvent()
2666 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2668 if( NULL != mImpl->mEventData )
2670 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2671 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2673 mImpl->ChangeState( EventData::EDITING );
2674 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2675 mImpl->mEventData->mUpdateInputStyle = true;
2676 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2678 mImpl->NotifyInputMethodContextMultiLineStatus();
2679 if( mImpl->IsShowingPlaceholderText() )
2681 // Show alternative placeholder-text when editing
2682 ShowPlaceholderText();
2685 mImpl->RequestRelayout();
2689 void Controller::KeyboardFocusLostEvent()
2691 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2693 if( NULL != mImpl->mEventData )
2695 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2697 mImpl->ChangeState( EventData::INACTIVE );
2699 if( !mImpl->IsShowingRealText() )
2701 // Revert to regular placeholder-text when not editing
2702 ShowPlaceholderText();
2706 mImpl->RequestRelayout();
2709 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2711 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2713 bool textChanged = false;
2714 bool relayoutNeeded = false;
2716 if( ( NULL != mImpl->mEventData ) &&
2717 ( keyEvent.state == KeyEvent::Down ) )
2719 int keyCode = keyEvent.keyCode;
2720 const std::string& keyString = keyEvent.keyPressed;
2721 const std::string keyName = keyEvent.keyPressedName;
2723 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2725 // Pre-process to separate modifying events from non-modifying input events.
2728 // In some platforms arrive key events with no key code.
2732 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2737 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2738 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2739 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2740 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2742 // If don't have any text, do nothing.
2743 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2748 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2749 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2750 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2751 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2753 // Logic to determine whether this text control will lose focus or not.
2754 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2755 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2756 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2757 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2758 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2759 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2761 // Release the active highlight.
2762 if( mImpl->mEventData->mState == EventData::SELECTING )
2764 mImpl->ChangeState( EventData::EDITING );
2766 // Update selection position.
2767 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2768 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2769 mImpl->mEventData->mUpdateCursorPosition = true;
2770 mImpl->RequestRelayout();
2775 mImpl->mEventData->mCheckScrollAmount = true;
2776 Event event( Event::CURSOR_KEY_EVENT );
2777 event.p1.mInt = keyCode;
2778 event.p2.mBool = keyEvent.IsShiftModifier();
2779 mImpl->mEventData->mEventQueue.push_back( event );
2781 // Will request for relayout.
2782 relayoutNeeded = true;
2784 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2786 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2787 // If not handle it here, any selected text will be deleted
2792 else if ( keyEvent.IsCtrlModifier() )
2794 bool consumed = false;
2795 if (keyName == KEY_C_NAME)
2797 // Ctrl-C to copy the selected text
2798 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2801 else if (keyName == KEY_V_NAME)
2803 // Ctrl-V to paste the copied text
2804 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2807 else if (keyName == KEY_X_NAME)
2809 // Ctrl-X to cut the selected text
2810 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2815 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2816 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2818 textChanged = DeleteEvent( keyCode );
2820 // Will request for relayout.
2821 relayoutNeeded = true;
2823 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2824 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2825 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2827 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2828 mImpl->ChangeState( EventData::INACTIVE );
2830 // Will request for relayout.
2831 relayoutNeeded = true;
2833 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2835 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2837 // DALI_KEY_SHIFT_LEFT or DALI_KEY_SHIFT_RIGHT is the key code for Shift. It's sent (by the InputMethodContext?) when the predictive text is enabled
2838 // and a character is typed after the type of a upper case latin character.
2843 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2845 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2851 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2853 if( !keyString.empty() )
2855 // InputMethodContext is no longer handling key-events
2856 mImpl->ClearPreEditFlag();
2858 InsertText( keyString, COMMIT );
2862 // Will request for relayout.
2863 relayoutNeeded = true;
2868 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2869 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2871 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2872 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2873 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2874 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2876 // Should not change the state if the key is the shift send by the InputMethodContext.
2877 // Otherwise, when the state is SELECTING the text controller can't send the right
2878 // surrounding info to the InputMethodContext.
2879 mImpl->ChangeState( EventData::EDITING );
2881 // Will request for relayout.
2882 relayoutNeeded = true;
2885 if( relayoutNeeded )
2887 mImpl->RequestRelayout();
2892 ( NULL != mImpl->mEditableControlInterface ) )
2894 // Do this last since it provides callbacks into application code
2895 mImpl->mEditableControlInterface->TextChanged();
2901 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2903 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2905 if( NULL != mImpl->mEventData )
2907 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2908 EventData::State state( mImpl->mEventData->mState );
2909 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2911 if( mImpl->IsClipboardVisible() )
2913 if( EventData::INACTIVE == state || EventData::EDITING == state)
2915 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2917 relayoutNeeded = true;
2919 else if( 1u == tapCount )
2921 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2923 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2926 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2928 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2929 relayoutNeeded = true;
2933 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2935 // Hide placeholder text
2939 if( EventData::INACTIVE == state )
2941 mImpl->ChangeState( EventData::EDITING );
2943 else if( !mImpl->IsClipboardEmpty() )
2945 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2947 relayoutNeeded = true;
2950 else if( 2u == tapCount )
2952 if( mImpl->mEventData->mSelectionEnabled &&
2953 mImpl->IsShowingRealText() )
2955 relayoutNeeded = true;
2956 mImpl->mEventData->mIsLeftHandleSelected = true;
2957 mImpl->mEventData->mIsRightHandleSelected = true;
2961 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2962 if( relayoutNeeded )
2964 Event event( Event::TAP_EVENT );
2965 event.p1.mUint = tapCount;
2966 event.p2.mFloat = x;
2967 event.p3.mFloat = y;
2968 mImpl->mEventData->mEventQueue.push_back( event );
2970 mImpl->RequestRelayout();
2974 // Reset keyboard as tap event has occurred.
2975 mImpl->ResetInputMethodContext();
2978 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2980 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2982 if( NULL != mImpl->mEventData )
2984 Event event( Event::PAN_EVENT );
2985 event.p1.mInt = state;
2986 event.p2.mFloat = displacement.x;
2987 event.p3.mFloat = displacement.y;
2988 mImpl->mEventData->mEventQueue.push_back( event );
2990 mImpl->RequestRelayout();
2994 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2996 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2998 if( ( state == Gesture::Started ) &&
2999 ( NULL != mImpl->mEventData ) )
3001 // The 1st long-press on inactive text-field is treated as tap
3002 if( EventData::INACTIVE == mImpl->mEventData->mState )
3004 mImpl->ChangeState( EventData::EDITING );
3006 Event event( Event::TAP_EVENT );
3008 event.p2.mFloat = x;
3009 event.p3.mFloat = y;
3010 mImpl->mEventData->mEventQueue.push_back( event );
3012 mImpl->RequestRelayout();
3014 else if( !mImpl->IsShowingRealText() )
3016 Event event( Event::LONG_PRESS_EVENT );
3017 event.p1.mInt = state;
3018 event.p2.mFloat = x;
3019 event.p3.mFloat = y;
3020 mImpl->mEventData->mEventQueue.push_back( event );
3021 mImpl->RequestRelayout();
3023 else if( !mImpl->IsClipboardVisible() )
3025 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3026 mImpl->ResetInputMethodContext();
3028 Event event( Event::LONG_PRESS_EVENT );
3029 event.p1.mInt = state;
3030 event.p2.mFloat = x;
3031 event.p3.mFloat = y;
3032 mImpl->mEventData->mEventQueue.push_back( event );
3033 mImpl->RequestRelayout();
3035 mImpl->mEventData->mIsLeftHandleSelected = true;
3036 mImpl->mEventData->mIsRightHandleSelected = true;
3041 void Controller::SelectEvent( float x, float y, bool selectAll )
3043 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3045 if( NULL != mImpl->mEventData )
3049 Event event( Event::SELECT_ALL );
3050 mImpl->mEventData->mEventQueue.push_back( event );
3054 Event event( Event::SELECT );
3055 event.p2.mFloat = x;
3056 event.p3.mFloat = y;
3057 mImpl->mEventData->mEventQueue.push_back( event );
3060 mImpl->mEventData->mCheckScrollAmount = true;
3061 mImpl->mEventData->mIsLeftHandleSelected = true;
3062 mImpl->mEventData->mIsRightHandleSelected = true;
3063 mImpl->RequestRelayout();
3067 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3069 // Whether the text needs to be relaid-out.
3070 bool requestRelayout = false;
3072 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3073 bool retrieveText = false;
3074 bool retrieveCursor = false;
3076 switch( inputMethodContextEvent.eventName )
3078 case InputMethodContext::COMMIT:
3080 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3081 requestRelayout = true;
3082 retrieveCursor = true;
3085 case InputMethodContext::PRE_EDIT:
3087 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3088 requestRelayout = true;
3089 retrieveCursor = true;
3092 case InputMethodContext::DELETE_SURROUNDING:
3094 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3095 inputMethodContextEvent.numberOfChars,
3096 DONT_UPDATE_INPUT_STYLE );
3100 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3101 !mImpl->IsPlaceholderAvailable() )
3103 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3107 ShowPlaceholderText();
3109 mImpl->mEventData->mUpdateCursorPosition = true;
3110 mImpl->mEventData->mScrollAfterDelete = true;
3112 requestRelayout = true;
3116 case InputMethodContext::GET_SURROUNDING:
3118 retrieveText = true;
3119 retrieveCursor = true;
3122 case InputMethodContext::PRIVATE_COMMAND:
3124 // PRIVATECOMMAND event is just for getting the private command message
3125 retrieveText = true;
3126 retrieveCursor = true;
3129 case InputMethodContext::VOID:
3136 if( requestRelayout )
3138 mImpl->mOperationsPending = ALL_OPERATIONS;
3139 mImpl->RequestRelayout();
3143 CharacterIndex cursorPosition = 0u;
3144 Length numberOfWhiteSpaces = 0u;
3146 if( retrieveCursor )
3148 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3150 cursorPosition = mImpl->GetLogicalCursorPosition();
3152 if( cursorPosition < numberOfWhiteSpaces )
3154 cursorPosition = 0u;
3158 cursorPosition -= numberOfWhiteSpaces;
3164 if( !mImpl->IsShowingPlaceholderText() )
3166 // Retrieves the normal text string.
3167 mImpl->GetText( numberOfWhiteSpaces, text );
3171 // When the current text is Placeholder Text, the surrounding text should be empty string.
3172 // It means DALi should send empty string ("") to IME.
3177 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3179 if( requestRelayout &&
3180 ( NULL != mImpl->mEditableControlInterface ) )
3182 // Do this last since it provides callbacks into application code
3183 mImpl->mEditableControlInterface->TextChanged();
3186 return callbackData;
3189 void Controller::PasteClipboardItemEvent()
3191 // Retrieve the clipboard contents first
3192 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3193 std::string stringToPaste( notifier.GetContent() );
3195 // Commit the current pre-edit text; the contents of the clipboard should be appended
3196 mImpl->ResetInputMethodContext();
3198 // Temporary disable hiding clipboard
3199 mImpl->SetClipboardHideEnable( false );
3202 PasteText( stringToPaste );
3204 mImpl->SetClipboardHideEnable( true );
3207 // protected : Inherit from Text::Decorator::ControllerInterface.
3209 void Controller::GetTargetSize( Vector2& targetSize )
3211 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3214 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3216 if( NULL != mImpl->mEditableControlInterface )
3218 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3222 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3224 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3226 if( NULL != mImpl->mEventData )
3228 switch( handleType )
3232 Event event( Event::GRAB_HANDLE_EVENT );
3233 event.p1.mUint = state;
3234 event.p2.mFloat = x;
3235 event.p3.mFloat = y;
3237 mImpl->mEventData->mEventQueue.push_back( event );
3240 case LEFT_SELECTION_HANDLE:
3242 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3243 event.p1.mUint = state;
3244 event.p2.mFloat = x;
3245 event.p3.mFloat = y;
3247 mImpl->mEventData->mEventQueue.push_back( event );
3250 case RIGHT_SELECTION_HANDLE:
3252 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3253 event.p1.mUint = state;
3254 event.p2.mFloat = x;
3255 event.p3.mFloat = y;
3257 mImpl->mEventData->mEventQueue.push_back( event );
3260 case LEFT_SELECTION_HANDLE_MARKER:
3261 case RIGHT_SELECTION_HANDLE_MARKER:
3263 // Markers do not move the handles.
3266 case HANDLE_TYPE_COUNT:
3268 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3272 mImpl->RequestRelayout();
3276 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3278 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3280 if( NULL == mImpl->mEventData )
3287 case Toolkit::TextSelectionPopup::CUT:
3289 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3290 mImpl->mOperationsPending = ALL_OPERATIONS;
3292 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3293 !mImpl->IsPlaceholderAvailable() )
3295 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3299 ShowPlaceholderText();
3302 mImpl->mEventData->mUpdateCursorPosition = true;
3303 mImpl->mEventData->mScrollAfterDelete = true;
3305 mImpl->RequestRelayout();
3307 if( NULL != mImpl->mEditableControlInterface )
3309 mImpl->mEditableControlInterface->TextChanged();
3313 case Toolkit::TextSelectionPopup::COPY:
3315 mImpl->SendSelectionToClipboard( false ); // Text not modified
3317 mImpl->mEventData->mUpdateCursorPosition = true;
3319 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3322 case Toolkit::TextSelectionPopup::PASTE:
3324 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3327 case Toolkit::TextSelectionPopup::SELECT:
3329 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3331 if( mImpl->mEventData->mSelectionEnabled )
3333 // Creates a SELECT event.
3334 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3338 case Toolkit::TextSelectionPopup::SELECT_ALL:
3340 // Creates a SELECT_ALL event
3341 SelectEvent( 0.f, 0.f, true );
3344 case Toolkit::TextSelectionPopup::CLIPBOARD:
3346 mImpl->ShowClipboard();
3349 case Toolkit::TextSelectionPopup::NONE:
3357 void Controller::DisplayTimeExpired()
3359 mImpl->mEventData->mUpdateCursorPosition = true;
3360 // Apply modifications to the model
3361 mImpl->mOperationsPending = ALL_OPERATIONS;
3363 mImpl->RequestRelayout();
3366 // private : Update.
3368 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3370 bool removedPrevious = false;
3371 bool removedSelected = false;
3372 bool maxLengthReached = false;
3374 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3376 if( NULL == mImpl->mEventData )
3381 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3382 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3383 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3385 // TODO: At the moment the underline runs are only for pre-edit.
3386 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3388 // Remove the previous InputMethodContext pre-edit.
3389 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3391 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3392 mImpl->mEventData->mPreEditLength,
3393 DONT_UPDATE_INPUT_STYLE );
3395 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3396 mImpl->mEventData->mPreEditLength = 0u;
3400 // Remove the previous Selection.
3401 removedSelected = RemoveSelectedText();
3405 Vector<Character> utf32Characters;
3406 Length characterCount = 0u;
3410 // Convert text into UTF-32
3411 utf32Characters.Resize( text.size() );
3413 // This is a bit horrible but std::string returns a (signed) char*
3414 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3416 // Transform a text array encoded in utf8 into an array encoded in utf32.
3417 // It returns the actual number of characters.
3418 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3419 utf32Characters.Resize( characterCount );
3421 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3422 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3425 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3427 // The placeholder text is no longer needed
3428 if( mImpl->IsShowingPlaceholderText() )
3433 mImpl->ChangeState( EventData::EDITING );
3435 // Handle the InputMethodContext (predicitive text) state changes
3436 if( COMMIT == type )
3438 // InputMethodContext is no longer handling key-events
3439 mImpl->ClearPreEditFlag();
3443 if( !mImpl->mEventData->mPreEditFlag )
3445 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3447 // Record the start of the pre-edit text
3448 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3451 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3452 mImpl->mEventData->mPreEditFlag = true;
3454 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3457 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3459 // Restrict new text to fit within Maximum characters setting.
3460 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3461 maxLengthReached = ( characterCount > maxSizeOfNewText );
3463 // The cursor position.
3464 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3466 // Update the text's style.
3468 // Updates the text style runs by adding characters.
3469 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3471 // Get the character index from the cursor index.
3472 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3474 // Retrieve the text's style for the given index.
3476 mImpl->RetrieveDefaultInputStyle( style );
3477 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3479 // Whether to add a new text color run.
3480 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3482 // Whether to add a new font run.
3483 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3484 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3485 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3486 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3487 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3492 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3493 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3495 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3496 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3497 colorRun.characterRun.characterIndex = cursorIndex;
3498 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3501 if( addFontNameRun ||
3507 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3508 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3510 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3512 if( addFontNameRun )
3514 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3515 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3516 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3517 fontDescriptionRun.familyDefined = true;
3519 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3522 if( addFontWeightRun )
3524 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3525 fontDescriptionRun.weightDefined = true;
3528 if( addFontWidthRun )
3530 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3531 fontDescriptionRun.widthDefined = true;
3534 if( addFontSlantRun )
3536 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3537 fontDescriptionRun.slantDefined = true;
3540 if( addFontSizeRun )
3542 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3543 fontDescriptionRun.sizeDefined = true;
3546 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3547 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3550 // Insert at current cursor position.
3551 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3553 if( cursorIndex < numberOfCharactersInModel )
3555 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3559 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3562 // Mark the first paragraph to be updated.
3563 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3565 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3566 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3567 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3568 mImpl->mTextUpdateInfo.mClearAll = true;
3572 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3573 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3576 // Update the cursor index.
3577 cursorIndex += maxSizeOfNewText;
3579 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 );
3582 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3583 mImpl->IsPlaceholderAvailable() )
3585 // Show place-holder if empty after removing the pre-edit text
3586 ShowPlaceholderText();
3587 mImpl->mEventData->mUpdateCursorPosition = true;
3588 mImpl->ClearPreEditFlag();
3590 else if( removedPrevious ||
3592 ( 0 != utf32Characters.Count() ) )
3594 // Queue an inserted event
3595 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3597 mImpl->mEventData->mUpdateCursorPosition = true;
3598 if( removedSelected )
3600 mImpl->mEventData->mScrollAfterDelete = true;
3604 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3608 if( maxLengthReached )
3610 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3612 mImpl->ResetInputMethodContext();
3614 if( NULL != mImpl->mEditableControlInterface )
3616 // Do this last since it provides callbacks into application code
3617 mImpl->mEditableControlInterface->MaxLengthReached();
3622 void Controller::PasteText( const std::string& stringToPaste )
3624 InsertText( stringToPaste, Text::Controller::COMMIT );
3625 mImpl->ChangeState( EventData::EDITING );
3626 mImpl->RequestRelayout();
3628 if( NULL != mImpl->mEditableControlInterface )
3630 // Do this last since it provides callbacks into application code
3631 mImpl->mEditableControlInterface->TextChanged();
3635 bool Controller::RemoveText( int cursorOffset,
3636 int numberOfCharacters,
3637 UpdateInputStyleType type )
3639 bool removed = false;
3641 if( NULL == mImpl->mEventData )
3646 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3647 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3649 if( !mImpl->IsShowingPlaceholderText() )
3651 // Delete at current cursor position
3652 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3653 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3655 CharacterIndex cursorIndex = 0;
3657 // Validate the cursor position & number of characters
3658 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3660 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3663 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3665 numberOfCharacters = currentText.Count() - cursorIndex;
3668 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.
3669 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3671 // Mark the paragraphs to be updated.
3672 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3674 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3675 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3676 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3677 mImpl->mTextUpdateInfo.mClearAll = true;
3681 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3682 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3685 // Update the input style and remove the text's style before removing the text.
3687 if( UPDATE_INPUT_STYLE == type )
3689 // Keep a copy of the current input style.
3690 InputStyle currentInputStyle;
3691 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3693 // Set first the default input style.
3694 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3696 // Update the input style.
3697 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3699 // Compare if the input style has changed.
3700 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3702 if( hasInputStyleChanged )
3704 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3705 // Queue the input style changed signal.
3706 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3710 // If the number of current text and the number of characters to be deleted are same,
3711 // it means all texts should be removed and all Preedit variables should be initialized.
3712 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
3714 if( mImpl->mEventData )
3716 mImpl->mEventData->mPreEditStartPosition = 0;
3717 mImpl->mEventData->mPreEditLength = 0;
3721 // Updates the text style runs by removing characters. Runs with no characters are removed.
3722 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3724 // Remove the characters.
3725 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3726 Vector<Character>::Iterator last = first + numberOfCharacters;
3728 currentText.Erase( first, last );
3730 // Cursor position retreat
3731 oldCursorIndex = cursorIndex;
3733 mImpl->mEventData->mScrollAfterDelete = true;
3735 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3743 bool Controller::RemoveSelectedText()
3745 bool textRemoved( false );
3747 if( EventData::SELECTING == mImpl->mEventData->mState )
3749 std::string removedString;
3750 mImpl->RetrieveSelection( removedString, true );
3752 if( !removedString.empty() )
3755 mImpl->ChangeState( EventData::EDITING );
3762 // private : Relayout.
3764 bool Controller::DoRelayout( const Size& size,
3765 OperationsMask operationsRequired,
3768 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3769 bool viewUpdated( false );
3771 // Calculate the operations to be done.
3772 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3774 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3775 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3777 // Get the current layout size.
3778 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3780 if( NO_OPERATION != ( LAYOUT & operations ) )
3782 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3784 // Some vectors with data needed to layout and reorder may be void
3785 // after the first time the text has been laid out.
3786 // Fill the vectors again.
3788 // Calculate the number of glyphs to layout.
3789 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3790 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3791 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3792 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3794 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3795 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3797 // Make sure the index is not out of bound
3798 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3799 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3800 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3802 std::string currentText;
3803 GetText( currentText );
3805 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3806 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3807 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3812 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3813 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3815 if( 0u == totalNumberOfGlyphs )
3817 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3819 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3822 // Nothing else to do if there is no glyphs.
3823 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3827 // Set the layout parameters.
3828 Layout::Parameters layoutParameters( size,
3831 // Resize the vector of positions to have the same size than the vector of glyphs.
3832 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3833 glyphPositions.Resize( totalNumberOfGlyphs );
3835 // Whether the last character is a new paragraph character.
3836 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3837 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3838 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3840 // The initial glyph and the number of glyphs to layout.
3841 layoutParameters.startGlyphIndex = startGlyphIndex;
3842 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3843 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3844 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3846 // Update the ellipsis
3847 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3849 if( NULL != mImpl->mEventData )
3851 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3853 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3855 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3857 // Disable ellipsis when editing
3858 elideTextEnabled = false;
3861 // Reset the scroll position in inactive state
3862 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3864 ResetScrollPosition();
3868 // Update the visual model.
3869 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3871 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3874 isAutoScrollEnabled );
3875 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3877 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3881 layoutSize = newLayoutSize;
3883 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3885 mImpl->mIsTextDirectionRTL = false;
3888 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !mImpl->mModel->mVisualModel->mLines.Empty() )
3890 mImpl->mIsTextDirectionRTL = mImpl->mModel->mVisualModel->mLines[0u].direction;
3893 // Sets the layout size.
3894 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3896 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3901 if( NO_OPERATION != ( ALIGN & operations ) )
3903 // The laid-out lines.
3904 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3906 CharacterIndex alignStartIndex = startIndex;
3907 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
3909 // the whole text needs to be full aligned.
3910 // If you do not do a full aligned, only the last line of the multiline input is aligned.
3911 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
3913 alignStartIndex = 0u;
3914 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
3915 mImpl->mEventData->mUpdateAlignment = false;
3918 // Need to align with the control's size as the text may contain lines
3919 // starting either with left to right text or right to left.
3920 mImpl->mLayoutEngine.Align( size,
3922 alignRequestedNumberOfCharacters,
3923 mImpl->mModel->mHorizontalAlignment,
3925 mImpl->mModel->mAlignmentOffset,
3926 mImpl->mLayoutDirection,
3927 mImpl->mModel->mMatchSystemLanguageDirection );
3931 #if defined(DEBUG_ENABLED)
3932 std::string currentText;
3933 GetText( currentText );
3934 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3936 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3940 void Controller::CalculateVerticalOffset( const Size& controlSize )
3942 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3944 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3946 // Get the line height of the default font.
3947 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3950 switch( mImpl->mModel->mVerticalAlignment )
3952 case VerticalAlignment::TOP:
3954 mImpl->mModel->mScrollPosition.y = 0.f;
3957 case VerticalAlignment::CENTER:
3959 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3962 case VerticalAlignment::BOTTOM:
3964 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3970 // private : Events.
3972 void Controller::ProcessModifyEvents()
3974 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3976 if( 0u == events.Count() )
3982 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3983 endIt = events.End();
3987 const ModifyEvent& event = *it;
3989 if( ModifyEvent::TEXT_REPLACED == event.type )
3991 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3992 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3994 TextReplacedEvent();
3996 else if( ModifyEvent::TEXT_INSERTED == event.type )
3998 TextInsertedEvent();
4000 else if( ModifyEvent::TEXT_DELETED == event.type )
4002 // Placeholder-text cannot be deleted
4003 if( !mImpl->IsShowingPlaceholderText() )
4010 if( NULL != mImpl->mEventData )
4012 // When the text is being modified, delay cursor blinking
4013 mImpl->mEventData->mDecorator->DelayCursorBlink();
4015 // Update selection position after modifying the text
4016 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4017 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4020 // Discard temporary text
4024 void Controller::TextReplacedEvent()
4026 // The natural size needs to be re-calculated.
4027 mImpl->mRecalculateNaturalSize = true;
4029 // The text direction needs to be updated.
4030 mImpl->mUpdateTextDirection = true;
4032 // Apply modifications to the model
4033 mImpl->mOperationsPending = ALL_OPERATIONS;
4036 void Controller::TextInsertedEvent()
4038 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4040 if( NULL == mImpl->mEventData )
4045 mImpl->mEventData->mCheckScrollAmount = true;
4047 // The natural size needs to be re-calculated.
4048 mImpl->mRecalculateNaturalSize = true;
4050 // The text direction needs to be updated.
4051 mImpl->mUpdateTextDirection = true;
4053 // Apply modifications to the model; TODO - Optimize this
4054 mImpl->mOperationsPending = ALL_OPERATIONS;
4057 void Controller::TextDeletedEvent()
4059 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4061 if( NULL == mImpl->mEventData )
4066 mImpl->mEventData->mCheckScrollAmount = true;
4068 // The natural size needs to be re-calculated.
4069 mImpl->mRecalculateNaturalSize = true;
4071 // The text direction needs to be updated.
4072 mImpl->mUpdateTextDirection = true;
4074 // Apply modifications to the model; TODO - Optimize this
4075 mImpl->mOperationsPending = ALL_OPERATIONS;
4078 bool Controller::DeleteEvent( int keyCode )
4080 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4082 bool removed = false;
4084 if( NULL == mImpl->mEventData )
4089 // InputMethodContext is no longer handling key-events
4090 mImpl->ClearPreEditFlag();
4092 if( EventData::SELECTING == mImpl->mEventData->mState )
4094 removed = RemoveSelectedText();
4096 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4098 // Remove the character before the current cursor position
4099 removed = RemoveText( -1,
4101 UPDATE_INPUT_STYLE );
4103 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4105 // Remove the character after the current cursor position
4106 removed = RemoveText( 0,
4108 UPDATE_INPUT_STYLE );
4113 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4114 !mImpl->IsPlaceholderAvailable() )
4116 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4120 ShowPlaceholderText();
4122 mImpl->mEventData->mUpdateCursorPosition = true;
4123 mImpl->mEventData->mScrollAfterDelete = true;
4129 // private : Helpers.
4131 void Controller::ResetText()
4134 mImpl->mModel->mLogicalModel->mText.Clear();
4136 // Reset the embedded images buffer.
4137 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4139 // We have cleared everything including the placeholder-text
4140 mImpl->PlaceholderCleared();
4142 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4143 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4144 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4146 // Clear any previous text.
4147 mImpl->mTextUpdateInfo.mClearAll = true;
4149 // The natural size needs to be re-calculated.
4150 mImpl->mRecalculateNaturalSize = true;
4152 // The text direction needs to be updated.
4153 mImpl->mUpdateTextDirection = true;
4155 // Apply modifications to the model
4156 mImpl->mOperationsPending = ALL_OPERATIONS;
4159 void Controller::ShowPlaceholderText()
4161 if( mImpl->IsPlaceholderAvailable() )
4163 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4165 if( NULL == mImpl->mEventData )
4170 mImpl->mEventData->mIsShowingPlaceholderText = true;
4172 // Disable handles when showing place-holder text
4173 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4174 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4175 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4177 const char* text( NULL );
4180 // TODO - Switch Placeholder text when changing state
4181 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4182 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4184 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4185 size = mImpl->mEventData->mPlaceholderTextActive.size();
4189 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4190 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4193 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4194 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4196 // Reset model for showing placeholder.
4197 mImpl->mModel->mLogicalModel->mText.Clear();
4198 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4200 // Convert text into UTF-32
4201 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4202 utf32Characters.Resize( size );
4204 // This is a bit horrible but std::string returns a (signed) char*
4205 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4207 // Transform a text array encoded in utf8 into an array encoded in utf32.
4208 // It returns the actual number of characters.
4209 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4210 utf32Characters.Resize( characterCount );
4212 // The characters to be added.
4213 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4215 // Reset the cursor position
4216 mImpl->mEventData->mPrimaryCursorPosition = 0;
4218 // The natural size needs to be re-calculated.
4219 mImpl->mRecalculateNaturalSize = true;
4221 // The text direction needs to be updated.
4222 mImpl->mUpdateTextDirection = true;
4224 // Apply modifications to the model
4225 mImpl->mOperationsPending = ALL_OPERATIONS;
4227 // Update the rest of the model during size negotiation
4228 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4232 void Controller::ClearFontData()
4234 if( mImpl->mFontDefaults )
4236 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4239 // Set flags to update the model.
4240 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4241 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4242 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4244 mImpl->mTextUpdateInfo.mClearAll = true;
4245 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4246 mImpl->mRecalculateNaturalSize = true;
4248 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4254 UPDATE_LAYOUT_SIZE |
4259 void Controller::ClearStyleData()
4261 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4262 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4265 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4267 // Reset the cursor position
4268 if( NULL != mImpl->mEventData )
4270 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4272 // Update the cursor if it's in editing mode.
4273 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4275 mImpl->mEventData->mUpdateCursorPosition = true;
4280 void Controller::ResetScrollPosition()
4282 if( NULL != mImpl->mEventData )
4284 // Reset the scroll position.
4285 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4286 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4290 void Controller::SetControlInterface( ControlInterface* controlInterface )
4292 mImpl->mControlInterface = controlInterface;
4295 bool Controller::ShouldClearFocusOnEscape() const
4297 return mImpl->mShouldClearFocusOnEscape;
4300 // private : Private contructors & copy operator.
4302 Controller::Controller()
4305 mImpl = new Controller::Impl( NULL, NULL );
4308 Controller::Controller( ControlInterface* controlInterface )
4310 mImpl = new Controller::Impl( controlInterface, NULL );
4313 Controller::Controller( ControlInterface* controlInterface,
4314 EditableControlInterface* editableControlInterface )
4316 mImpl = new Controller::Impl( controlInterface,
4317 editableControlInterface );
4320 // The copy constructor and operator are left unimplemented.
4322 // protected : Destructor.
4324 Controller::~Controller()
4331 } // namespace Toolkit