2 * Copyright (c) 2020 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";
66 float ConvertToEven( float value )
68 int intValue(static_cast<int>( value ));
69 return static_cast<float>( intValue + ( intValue & 1 ) );
72 int ConvertPixelToPint( float pixel )
74 unsigned int horizontalDpi = 0u;
75 unsigned int verticalDpi = 0u;
76 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
77 fontClient.GetDpi( horizontalDpi, verticalDpi );
79 return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
94 * @brief Adds a new font description run for the selected text.
96 * The new font parameters are added after the call to this method.
98 * @param[in] eventData The event data pointer.
99 * @param[in] logicalModel The logical model where to add the new font description run.
100 * @param[out] startOfSelectedText Index to the first selected character.
101 * @param[out] lengthOfSelectedText Number of selected characters.
103 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
104 LogicalModelPtr logicalModel,
105 CharacterIndex& startOfSelectedText,
106 Length& lengthOfSelectedText )
108 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
110 // Get start and end position of selection
111 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
112 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
115 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
116 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
118 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
120 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
121 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
123 // Recalculate the selection highlight as the metrics may have changed.
124 eventData->mUpdateLeftSelectionPosition = true;
125 eventData->mUpdateRightSelectionPosition = true;
126 eventData->mUpdateHighlightBox = true;
128 return fontDescriptionRun;
131 // public : Constructor.
133 ControllerPtr Controller::New()
135 return ControllerPtr( new Controller() );
138 ControllerPtr Controller::New( ControlInterface* controlInterface )
140 return ControllerPtr( new Controller( controlInterface ) );
143 ControllerPtr Controller::New( ControlInterface* controlInterface,
144 EditableControlInterface* editableControlInterface )
146 return ControllerPtr( new Controller( controlInterface,
147 editableControlInterface ) );
150 // public : Configure the text controller.
152 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
156 delete mImpl->mEventData;
157 mImpl->mEventData = NULL;
159 // Nothing else to do.
163 if( NULL == mImpl->mEventData )
165 mImpl->mEventData = new EventData( decorator, inputMethodContext );
169 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
171 // Metrics for bitmap & vector based glyphs are different
172 mImpl->mMetrics->SetGlyphType( glyphType );
174 // Clear the font-specific data
177 mImpl->RequestRelayout();
180 void Controller::SetMarkupProcessorEnabled( bool enable )
182 if( enable != mImpl->mMarkupProcessorEnabled )
184 //If Text was already set, call the SetText again for enabling or disabling markup
185 mImpl->mMarkupProcessorEnabled = enable;
192 bool Controller::IsMarkupProcessorEnabled() const
194 return mImpl->mMarkupProcessorEnabled;
197 void Controller::SetAutoScrollEnabled( bool enable )
199 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 );
201 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
205 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
206 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
216 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
217 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
224 mImpl->mIsAutoScrollEnabled = enable;
225 mImpl->RequestRelayout();
229 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
230 mImpl->mIsAutoScrollEnabled = false;
234 bool Controller::IsAutoScrollEnabled() const
236 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
238 return mImpl->mIsAutoScrollEnabled;
241 CharacterDirection Controller::GetAutoScrollDirection() const
243 return mImpl->mIsTextDirectionRTL;
246 float Controller::GetAutoScrollLineAlignment() const
250 if( mImpl->mModel->mVisualModel &&
251 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
253 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
259 void Controller::SetHorizontalScrollEnabled( bool enable )
261 if( ( NULL != mImpl->mEventData ) &&
262 mImpl->mEventData->mDecorator )
264 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
267 bool Controller::IsHorizontalScrollEnabled() const
269 if( ( NULL != mImpl->mEventData ) &&
270 mImpl->mEventData->mDecorator )
272 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
278 void Controller::SetVerticalScrollEnabled( bool enable )
280 if( ( NULL != mImpl->mEventData ) &&
281 mImpl->mEventData->mDecorator )
283 if( mImpl->mEventData->mDecorator )
285 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
290 bool Controller::IsVerticalScrollEnabled() const
292 if( ( NULL != mImpl->mEventData ) &&
293 mImpl->mEventData->mDecorator )
295 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
301 void Controller::SetSmoothHandlePanEnabled( bool enable )
303 if( ( NULL != mImpl->mEventData ) &&
304 mImpl->mEventData->mDecorator )
306 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
310 bool Controller::IsSmoothHandlePanEnabled() const
312 if( ( NULL != mImpl->mEventData ) &&
313 mImpl->mEventData->mDecorator )
315 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
321 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
323 mImpl->mMaximumNumberOfCharacters = maxCharacters;
326 int Controller::GetMaximumNumberOfCharacters()
328 return mImpl->mMaximumNumberOfCharacters;
331 void Controller::SetEnableCursorBlink( bool enable )
333 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
335 if( NULL != mImpl->mEventData )
337 mImpl->mEventData->mCursorBlinkEnabled = enable;
340 mImpl->mEventData->mDecorator )
342 mImpl->mEventData->mDecorator->StopCursorBlink();
347 bool Controller::GetEnableCursorBlink() const
349 if( NULL != mImpl->mEventData )
351 return mImpl->mEventData->mCursorBlinkEnabled;
357 void Controller::SetMultiLineEnabled( bool enable )
359 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
361 if( layout != mImpl->mLayoutEngine.GetLayout() )
363 // Set the layout type.
364 mImpl->mLayoutEngine.SetLayout( layout );
366 // Set the flags to redo the layout operations
367 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
372 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
373 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
375 // Need to recalculate natural size
376 mImpl->mRecalculateNaturalSize = true;
378 mImpl->RequestRelayout();
382 bool Controller::IsMultiLineEnabled() const
384 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
387 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
389 if( alignment != mImpl->mModel->mHorizontalAlignment )
391 // Set the alignment.
392 mImpl->mModel->mHorizontalAlignment = alignment;
394 // Set the flag to redo the alignment operation.
395 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
397 if( mImpl->mEventData )
399 mImpl->mEventData->mUpdateAlignment = true;
401 // Update the cursor if it's in editing mode
402 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
404 mImpl->ChangeState( EventData::EDITING );
405 mImpl->mEventData->mUpdateCursorPosition = true;
409 mImpl->RequestRelayout();
413 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
415 return mImpl->mModel->mHorizontalAlignment;
418 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
420 if( alignment != mImpl->mModel->mVerticalAlignment )
422 // Set the alignment.
423 mImpl->mModel->mVerticalAlignment = alignment;
425 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
427 mImpl->RequestRelayout();
431 VerticalAlignment::Type Controller::GetVerticalAlignment() const
433 return mImpl->mModel->mVerticalAlignment;
436 bool Controller::IsIgnoreSpacesAfterText() const
438 return mImpl->mModel->mIgnoreSpacesAfterText;
441 void Controller::SetIgnoreSpacesAfterText( bool ignore )
443 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
446 bool Controller::IsMatchSystemLanguageDirection() const
448 return mImpl->mModel->mMatchSystemLanguageDirection;
451 void Controller::SetMatchSystemLanguageDirection( bool match )
453 mImpl->mModel->mMatchSystemLanguageDirection = match;
456 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
458 mImpl->mLayoutDirection = layoutDirection;
461 bool Controller::IsShowingRealText() const
463 return mImpl->IsShowingRealText();
467 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
469 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
471 // Set the text wrap mode.
472 mImpl->mModel->mLineWrapMode = lineWrapMode;
475 // Update Text layout for applying wrap mode
476 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
481 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
482 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
483 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
486 mImpl->RequestRelayout();
490 Text::LineWrap::Mode Controller::GetLineWrapMode() const
492 return mImpl->mModel->mLineWrapMode;
495 void Controller::SetTextElideEnabled( bool enabled )
497 mImpl->mModel->mElideEnabled = enabled;
500 bool Controller::IsTextElideEnabled() const
502 return mImpl->mModel->mElideEnabled;
505 void Controller::SetTextFitEnabled(bool enabled)
507 mImpl->mTextFitEnabled = enabled;
510 bool Controller::IsTextFitEnabled() const
512 return mImpl->mTextFitEnabled;
515 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
521 mImpl->mTextFitMinSize = minSize;
526 mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
532 float Controller::GetTextFitMinSize() const
534 return mImpl->mTextFitMinSize;
537 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
543 mImpl->mTextFitMaxSize = maxSize;
548 mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
554 float Controller::GetTextFitMaxSize() const
556 return mImpl->mTextFitMaxSize;
559 void Controller::SetTextFitStepSize( float step, FontSizeType type )
565 mImpl->mTextFitStepSize = step;
570 mImpl->mTextFitStepSize = ConvertPixelToPint( step );
576 float Controller::GetTextFitStepSize() const
578 return mImpl->mTextFitStepSize;
581 void Controller::SetTextFitContentSize(Vector2 size)
583 mImpl->mTextFitContentSize = size;
586 Vector2 Controller::GetTextFitContentSize() const
588 return mImpl->mTextFitContentSize;
591 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
593 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
594 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
596 // Update placeholder if there is no text
597 if( mImpl->IsShowingPlaceholderText() ||
598 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
600 ShowPlaceholderText();
604 bool Controller::IsPlaceholderTextElideEnabled() const
606 return mImpl->mEventData->mIsPlaceholderElideEnabled;
609 void Controller::SetSelectionEnabled( bool enabled )
611 mImpl->mEventData->mSelectionEnabled = enabled;
614 bool Controller::IsSelectionEnabled() const
616 return mImpl->mEventData->mSelectionEnabled;
619 void Controller::SetShiftSelectionEnabled( bool enabled )
621 mImpl->mEventData->mShiftSelectionFlag = enabled;
624 bool Controller::IsShiftSelectionEnabled() const
626 return mImpl->mEventData->mShiftSelectionFlag;
629 void Controller::SetGrabHandleEnabled( bool enabled )
631 mImpl->mEventData->mGrabHandleEnabled = enabled;
634 bool Controller::IsGrabHandleEnabled() const
636 return mImpl->mEventData->mGrabHandleEnabled;
639 void Controller::SetGrabHandlePopupEnabled(bool enabled)
641 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
644 bool Controller::IsGrabHandlePopupEnabled() const
646 return mImpl->mEventData->mGrabHandlePopupEnabled;
651 void Controller::SetText( const std::string& text )
653 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
655 // Reset keyboard as text changed
656 mImpl->ResetInputMethodContext();
658 // Remove the previously set text and style.
664 CharacterIndex lastCursorIndex = 0u;
666 if( NULL != mImpl->mEventData )
668 // If popup shown then hide it by switching to Editing state
669 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
670 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
671 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
672 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
674 mImpl->ChangeState( EventData::EDITING );
680 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
682 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
683 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
684 mImpl->mModel->mLogicalModel->mEmbeddedItems );
686 Length textSize = 0u;
687 const uint8_t* utf8 = NULL;
688 if( mImpl->mMarkupProcessorEnabled )
690 ProcessMarkupString( text, markupProcessData );
691 textSize = markupProcessData.markupProcessedText.size();
693 // This is a bit horrible but std::string returns a (signed) char*
694 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
698 textSize = text.size();
700 // This is a bit horrible but std::string returns a (signed) char*
701 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
704 // Convert text into UTF-32
705 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
706 utf32Characters.Resize( textSize );
708 // Transform a text array encoded in utf8 into an array encoded in utf32.
709 // It returns the actual number of characters.
710 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
711 utf32Characters.Resize( characterCount );
713 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
714 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
716 // The characters to be added.
717 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
719 // To reset the cursor position
720 lastCursorIndex = characterCount;
722 // Update the rest of the model during size negotiation
723 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
725 // The natural size needs to be re-calculated.
726 mImpl->mRecalculateNaturalSize = true;
728 // The text direction needs to be updated.
729 mImpl->mUpdateTextDirection = true;
731 // Apply modifications to the model
732 mImpl->mOperationsPending = ALL_OPERATIONS;
736 ShowPlaceholderText();
739 // Resets the cursor position.
740 ResetCursorPosition( lastCursorIndex );
742 // Scrolls the text to make the cursor visible.
743 ResetScrollPosition();
745 mImpl->RequestRelayout();
747 if( NULL != mImpl->mEventData )
749 // Cancel previously queued events
750 mImpl->mEventData->mEventQueue.clear();
753 // Do this last since it provides callbacks into application code.
754 if( NULL != mImpl->mEditableControlInterface )
756 mImpl->mEditableControlInterface->TextChanged();
760 void Controller::GetText( std::string& text ) const
762 if( !mImpl->IsShowingPlaceholderText() )
764 // Retrieves the text string.
765 mImpl->GetText( 0u, text );
769 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
773 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
775 if( NULL != mImpl->mEventData )
777 if( PLACEHOLDER_TYPE_INACTIVE == type )
779 mImpl->mEventData->mPlaceholderTextInactive = text;
783 mImpl->mEventData->mPlaceholderTextActive = text;
786 // Update placeholder if there is no text
787 if( mImpl->IsShowingPlaceholderText() ||
788 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
790 ShowPlaceholderText();
795 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
797 if( NULL != mImpl->mEventData )
799 if( PLACEHOLDER_TYPE_INACTIVE == type )
801 text = mImpl->mEventData->mPlaceholderTextInactive;
805 text = mImpl->mEventData->mPlaceholderTextActive;
810 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
812 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
814 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
816 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
817 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
821 mImpl->RequestRelayout();
825 // public : Default style & Input style
827 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
829 if( NULL == mImpl->mFontDefaults )
831 mImpl->mFontDefaults = new FontDefaults();
834 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
835 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
836 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
838 if( mImpl->mEventData )
840 // Update the cursor position if it's in editing mode
841 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
843 mImpl->mEventData->mDecoratorUpdated = true;
844 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font family is updated.
848 // Clear the font-specific data
851 mImpl->RequestRelayout();
854 const std::string& Controller::GetDefaultFontFamily() const
856 if( NULL != mImpl->mFontDefaults )
858 return mImpl->mFontDefaults->mFontDescription.family;
864 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
866 if( NULL != mImpl->mEventData )
868 if( NULL == mImpl->mEventData->mPlaceholderFont )
870 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
873 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
874 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
875 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
877 mImpl->RequestRelayout();
881 const std::string& Controller::GetPlaceholderFontFamily() const
883 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
885 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
891 void Controller::SetDefaultFontWeight( FontWeight weight )
893 if( NULL == mImpl->mFontDefaults )
895 mImpl->mFontDefaults = new FontDefaults();
898 mImpl->mFontDefaults->mFontDescription.weight = weight;
899 mImpl->mFontDefaults->weightDefined = true;
901 if( mImpl->mEventData )
903 // Update the cursor position if it's in editing mode
904 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
906 mImpl->mEventData->mDecoratorUpdated = true;
907 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font weight is updated.
911 // Clear the font-specific data
914 mImpl->RequestRelayout();
917 bool Controller::IsDefaultFontWeightDefined() const
919 if( NULL != mImpl->mFontDefaults )
921 return mImpl->mFontDefaults->weightDefined;
927 FontWeight Controller::GetDefaultFontWeight() const
929 if( NULL != mImpl->mFontDefaults )
931 return mImpl->mFontDefaults->mFontDescription.weight;
934 return TextAbstraction::FontWeight::NORMAL;
937 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
939 if( NULL != mImpl->mEventData )
941 if( NULL == mImpl->mEventData->mPlaceholderFont )
943 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
946 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
947 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
949 mImpl->RequestRelayout();
953 bool Controller::IsPlaceholderTextFontWeightDefined() const
955 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
957 return mImpl->mEventData->mPlaceholderFont->weightDefined;
962 FontWeight Controller::GetPlaceholderTextFontWeight() const
964 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
966 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
969 return TextAbstraction::FontWeight::NORMAL;
972 void Controller::SetDefaultFontWidth( FontWidth width )
974 if( NULL == mImpl->mFontDefaults )
976 mImpl->mFontDefaults = new FontDefaults();
979 mImpl->mFontDefaults->mFontDescription.width = width;
980 mImpl->mFontDefaults->widthDefined = true;
982 if( mImpl->mEventData )
984 // Update the cursor position if it's in editing mode
985 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
987 mImpl->mEventData->mDecoratorUpdated = true;
988 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font width is updated.
992 // Clear the font-specific data
995 mImpl->RequestRelayout();
998 bool Controller::IsDefaultFontWidthDefined() const
1000 if( NULL != mImpl->mFontDefaults )
1002 return mImpl->mFontDefaults->widthDefined;
1008 FontWidth Controller::GetDefaultFontWidth() const
1010 if( NULL != mImpl->mFontDefaults )
1012 return mImpl->mFontDefaults->mFontDescription.width;
1015 return TextAbstraction::FontWidth::NORMAL;
1018 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
1020 if( NULL != mImpl->mEventData )
1022 if( NULL == mImpl->mEventData->mPlaceholderFont )
1024 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1027 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
1028 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
1030 mImpl->RequestRelayout();
1034 bool Controller::IsPlaceholderTextFontWidthDefined() const
1036 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1038 return mImpl->mEventData->mPlaceholderFont->widthDefined;
1043 FontWidth Controller::GetPlaceholderTextFontWidth() const
1045 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1047 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1050 return TextAbstraction::FontWidth::NORMAL;
1053 void Controller::SetDefaultFontSlant( FontSlant slant )
1055 if( NULL == mImpl->mFontDefaults )
1057 mImpl->mFontDefaults = new FontDefaults();
1060 mImpl->mFontDefaults->mFontDescription.slant = slant;
1061 mImpl->mFontDefaults->slantDefined = true;
1063 if( mImpl->mEventData )
1065 // Update the cursor position if it's in editing mode
1066 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
1068 mImpl->mEventData->mDecoratorUpdated = true;
1069 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font slant is updated.
1073 // Clear the font-specific data
1076 mImpl->RequestRelayout();
1079 bool Controller::IsDefaultFontSlantDefined() const
1081 if( NULL != mImpl->mFontDefaults )
1083 return mImpl->mFontDefaults->slantDefined;
1088 FontSlant Controller::GetDefaultFontSlant() const
1090 if( NULL != mImpl->mFontDefaults )
1092 return mImpl->mFontDefaults->mFontDescription.slant;
1095 return TextAbstraction::FontSlant::NORMAL;
1098 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1100 if( NULL != mImpl->mEventData )
1102 if( NULL == mImpl->mEventData->mPlaceholderFont )
1104 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1107 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1108 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1110 mImpl->RequestRelayout();
1114 bool Controller::IsPlaceholderTextFontSlantDefined() const
1116 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1118 return mImpl->mEventData->mPlaceholderFont->slantDefined;
1123 FontSlant Controller::GetPlaceholderTextFontSlant() const
1125 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1127 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1130 return TextAbstraction::FontSlant::NORMAL;
1133 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1135 if( NULL == mImpl->mFontDefaults )
1137 mImpl->mFontDefaults = new FontDefaults();
1144 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1145 mImpl->mFontDefaults->sizeDefined = true;
1150 // Point size = Pixel size * 72.f / DPI
1151 unsigned int horizontalDpi = 0u;
1152 unsigned int verticalDpi = 0u;
1153 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1154 fontClient.GetDpi( horizontalDpi, verticalDpi );
1156 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1157 mImpl->mFontDefaults->sizeDefined = true;
1162 if( mImpl->mEventData )
1164 // Update the cursor position if it's in editing mode
1165 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
1167 mImpl->mEventData->mDecoratorUpdated = true;
1168 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
1172 // Clear the font-specific data
1175 mImpl->RequestRelayout();
1178 float Controller::GetDefaultFontSize( FontSizeType type ) const
1181 if( NULL != mImpl->mFontDefaults )
1187 value = mImpl->mFontDefaults->mDefaultPointSize;
1192 // Pixel size = Point size * DPI / 72.f
1193 unsigned int horizontalDpi = 0u;
1194 unsigned int verticalDpi = 0u;
1195 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1196 fontClient.GetDpi( horizontalDpi, verticalDpi );
1198 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1208 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1210 if( NULL != mImpl->mEventData )
1212 if( NULL == mImpl->mEventData->mPlaceholderFont )
1214 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1221 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1222 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1223 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1228 // Point size = Pixel size * 72.f / DPI
1229 unsigned int horizontalDpi = 0u;
1230 unsigned int verticalDpi = 0u;
1231 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1232 fontClient.GetDpi( horizontalDpi, verticalDpi );
1234 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1235 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1236 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1241 mImpl->RequestRelayout();
1245 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1248 if( NULL != mImpl->mEventData )
1254 if( NULL != mImpl->mEventData->mPlaceholderFont )
1256 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1260 // If the placeholder text font size is not set, then return the default font size.
1261 value = GetDefaultFontSize( POINT_SIZE );
1267 if( NULL != mImpl->mEventData->mPlaceholderFont )
1269 // Pixel size = Point size * DPI / 72.f
1270 unsigned int horizontalDpi = 0u;
1271 unsigned int verticalDpi = 0u;
1272 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1273 fontClient.GetDpi( horizontalDpi, verticalDpi );
1275 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1279 // If the placeholder text font size is not set, then return the default font size.
1280 value = GetDefaultFontSize( PIXEL_SIZE );
1291 void Controller::SetDefaultColor( const Vector4& color )
1293 mImpl->mTextColor = color;
1295 if( !mImpl->IsShowingPlaceholderText() )
1297 mImpl->mModel->mVisualModel->SetTextColor( color );
1299 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1301 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1303 mImpl->RequestRelayout();
1307 const Vector4& Controller::GetDefaultColor() const
1309 return mImpl->mTextColor;
1312 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1314 if( NULL != mImpl->mEventData )
1316 mImpl->mEventData->mPlaceholderTextColor = textColor;
1319 if( mImpl->IsShowingPlaceholderText() )
1321 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1322 mImpl->RequestRelayout();
1326 const Vector4& Controller::GetPlaceholderTextColor() const
1328 if( NULL != mImpl->mEventData )
1330 return mImpl->mEventData->mPlaceholderTextColor;
1333 return Color::BLACK;
1336 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1338 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1340 mImpl->RequestRelayout();
1343 const Vector2& Controller::GetShadowOffset() const
1345 return mImpl->mModel->mVisualModel->GetShadowOffset();
1348 void Controller::SetShadowColor( const Vector4& shadowColor )
1350 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1352 mImpl->RequestRelayout();
1355 const Vector4& Controller::GetShadowColor() const
1357 return mImpl->mModel->mVisualModel->GetShadowColor();
1360 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1362 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1364 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1366 mImpl->RequestRelayout();
1370 const float& Controller::GetShadowBlurRadius() const
1372 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1375 void Controller::SetUnderlineColor( const Vector4& color )
1377 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1379 mImpl->RequestRelayout();
1382 const Vector4& Controller::GetUnderlineColor() const
1384 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1387 void Controller::SetUnderlineEnabled( bool enabled )
1389 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1391 mImpl->RequestRelayout();
1394 bool Controller::IsUnderlineEnabled() const
1396 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1399 void Controller::SetUnderlineHeight( float height )
1401 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1403 mImpl->RequestRelayout();
1406 float Controller::GetUnderlineHeight() const
1408 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1411 void Controller::SetOutlineColor( const Vector4& color )
1413 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1415 mImpl->RequestRelayout();
1418 const Vector4& Controller::GetOutlineColor() const
1420 return mImpl->mModel->mVisualModel->GetOutlineColor();
1423 void Controller::SetOutlineWidth( uint16_t width )
1425 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1427 mImpl->RequestRelayout();
1430 uint16_t Controller::GetOutlineWidth() const
1432 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1435 void Controller::SetBackgroundColor( const Vector4& color )
1437 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1439 mImpl->RequestRelayout();
1442 const Vector4& Controller::GetBackgroundColor() const
1444 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1447 void Controller::SetBackgroundEnabled( bool enabled )
1449 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1451 mImpl->RequestRelayout();
1454 bool Controller::IsBackgroundEnabled() const
1456 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1459 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1461 if( NULL == mImpl->mEmbossDefaults )
1463 mImpl->mEmbossDefaults = new EmbossDefaults();
1466 mImpl->mEmbossDefaults->properties = embossProperties;
1469 const std::string& Controller::GetDefaultEmbossProperties() const
1471 if( NULL != mImpl->mEmbossDefaults )
1473 return mImpl->mEmbossDefaults->properties;
1476 return EMPTY_STRING;
1479 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1481 if( NULL == mImpl->mOutlineDefaults )
1483 mImpl->mOutlineDefaults = new OutlineDefaults();
1486 mImpl->mOutlineDefaults->properties = outlineProperties;
1489 const std::string& Controller::GetDefaultOutlineProperties() const
1491 if( NULL != mImpl->mOutlineDefaults )
1493 return mImpl->mOutlineDefaults->properties;
1496 return EMPTY_STRING;
1499 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1501 if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1503 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1504 mImpl->mRecalculateNaturalSize = true;
1510 float Controller::GetDefaultLineSpacing() const
1512 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1515 bool Controller::SetDefaultLineSize( float lineSize )
1517 if( std::fabs( lineSize - mImpl->mLayoutEngine.GetDefaultLineSize() ) > Math::MACHINE_EPSILON_1000 )
1519 mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
1520 mImpl->mRecalculateNaturalSize = true;
1526 float Controller::GetDefaultLineSize() const
1528 return mImpl->mLayoutEngine.GetDefaultLineSize();
1531 void Controller::SetInputColor( const Vector4& color )
1533 if( NULL != mImpl->mEventData )
1535 mImpl->mEventData->mInputStyle.textColor = color;
1536 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1538 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1540 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1542 // Get start and end position of selection
1543 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1544 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1546 // Add the color run.
1547 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1548 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1550 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1551 colorRun.color = color;
1552 colorRun.characterRun.characterIndex = startOfSelectedText;
1553 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1555 // Request to relayout.
1556 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1557 mImpl->RequestRelayout();
1559 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1560 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1561 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1566 const Vector4& Controller::GetInputColor() const
1568 if( NULL != mImpl->mEventData )
1570 return mImpl->mEventData->mInputStyle.textColor;
1573 // Return the default text's color if there is no EventData.
1574 return mImpl->mTextColor;
1578 void Controller::SetInputFontFamily( const std::string& fontFamily )
1580 if( NULL != mImpl->mEventData )
1582 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1583 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1585 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1587 CharacterIndex startOfSelectedText = 0u;
1588 Length lengthOfSelectedText = 0u;
1590 if( EventData::SELECTING == mImpl->mEventData->mState )
1592 // Update a font description run for the selecting state.
1593 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1594 mImpl->mModel->mLogicalModel,
1595 startOfSelectedText,
1596 lengthOfSelectedText );
1598 fontDescriptionRun.familyLength = fontFamily.size();
1599 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1600 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1601 fontDescriptionRun.familyDefined = true;
1603 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1605 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1606 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1607 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1611 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1612 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1613 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1616 // Request to relayout.
1617 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1622 UPDATE_LAYOUT_SIZE |
1625 mImpl->mRecalculateNaturalSize = true;
1626 mImpl->RequestRelayout();
1628 // As the font changes, recalculate the handle positions is needed.
1629 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1630 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1631 mImpl->mEventData->mUpdateHighlightBox = true;
1632 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1637 const std::string& Controller::GetInputFontFamily() const
1639 if( NULL != mImpl->mEventData )
1641 return mImpl->mEventData->mInputStyle.familyName;
1644 // Return the default font's family if there is no EventData.
1645 return GetDefaultFontFamily();
1648 void Controller::SetInputFontWeight( FontWeight weight )
1650 if( NULL != mImpl->mEventData )
1652 mImpl->mEventData->mInputStyle.weight = weight;
1653 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1655 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1657 CharacterIndex startOfSelectedText = 0u;
1658 Length lengthOfSelectedText = 0u;
1660 if( EventData::SELECTING == mImpl->mEventData->mState )
1662 // Update a font description run for the selecting state.
1663 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1664 mImpl->mModel->mLogicalModel,
1665 startOfSelectedText,
1666 lengthOfSelectedText );
1668 fontDescriptionRun.weight = weight;
1669 fontDescriptionRun.weightDefined = true;
1671 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1672 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1673 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1677 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1678 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1679 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1682 // Request to relayout.
1683 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1688 UPDATE_LAYOUT_SIZE |
1691 mImpl->mRecalculateNaturalSize = true;
1692 mImpl->RequestRelayout();
1694 // As the font might change, recalculate the handle positions is needed.
1695 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1696 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1697 mImpl->mEventData->mUpdateHighlightBox = true;
1698 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1703 bool Controller::IsInputFontWeightDefined() const
1705 bool defined = false;
1707 if( NULL != mImpl->mEventData )
1709 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1715 FontWeight Controller::GetInputFontWeight() const
1717 if( NULL != mImpl->mEventData )
1719 return mImpl->mEventData->mInputStyle.weight;
1722 return GetDefaultFontWeight();
1725 void Controller::SetInputFontWidth( FontWidth width )
1727 if( NULL != mImpl->mEventData )
1729 mImpl->mEventData->mInputStyle.width = width;
1730 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1732 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1734 CharacterIndex startOfSelectedText = 0u;
1735 Length lengthOfSelectedText = 0u;
1737 if( EventData::SELECTING == mImpl->mEventData->mState )
1739 // Update a font description run for the selecting state.
1740 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1741 mImpl->mModel->mLogicalModel,
1742 startOfSelectedText,
1743 lengthOfSelectedText );
1745 fontDescriptionRun.width = width;
1746 fontDescriptionRun.widthDefined = true;
1748 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1749 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1750 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1754 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1755 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1756 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1759 // Request to relayout.
1760 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1765 UPDATE_LAYOUT_SIZE |
1768 mImpl->mRecalculateNaturalSize = true;
1769 mImpl->RequestRelayout();
1771 // As the font might change, recalculate the handle positions is needed.
1772 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1773 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1774 mImpl->mEventData->mUpdateHighlightBox = true;
1775 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1780 bool Controller::IsInputFontWidthDefined() const
1782 bool defined = false;
1784 if( NULL != mImpl->mEventData )
1786 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1792 FontWidth Controller::GetInputFontWidth() const
1794 if( NULL != mImpl->mEventData )
1796 return mImpl->mEventData->mInputStyle.width;
1799 return GetDefaultFontWidth();
1802 void Controller::SetInputFontSlant( FontSlant slant )
1804 if( NULL != mImpl->mEventData )
1806 mImpl->mEventData->mInputStyle.slant = slant;
1807 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1809 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1811 CharacterIndex startOfSelectedText = 0u;
1812 Length lengthOfSelectedText = 0u;
1814 if( EventData::SELECTING == mImpl->mEventData->mState )
1816 // Update a font description run for the selecting state.
1817 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1818 mImpl->mModel->mLogicalModel,
1819 startOfSelectedText,
1820 lengthOfSelectedText );
1822 fontDescriptionRun.slant = slant;
1823 fontDescriptionRun.slantDefined = true;
1825 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1826 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1827 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1831 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1832 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1833 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1836 // Request to relayout.
1837 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1842 UPDATE_LAYOUT_SIZE |
1845 mImpl->mRecalculateNaturalSize = true;
1846 mImpl->RequestRelayout();
1848 // As the font might change, recalculate the handle positions is needed.
1849 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1850 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1851 mImpl->mEventData->mUpdateHighlightBox = true;
1852 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1857 bool Controller::IsInputFontSlantDefined() const
1859 bool defined = false;
1861 if( NULL != mImpl->mEventData )
1863 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1869 FontSlant Controller::GetInputFontSlant() const
1871 if( NULL != mImpl->mEventData )
1873 return mImpl->mEventData->mInputStyle.slant;
1876 return GetDefaultFontSlant();
1879 void Controller::SetInputFontPointSize( float size )
1881 if( NULL != mImpl->mEventData )
1883 mImpl->mEventData->mInputStyle.size = size;
1884 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1886 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1888 CharacterIndex startOfSelectedText = 0u;
1889 Length lengthOfSelectedText = 0u;
1891 if( EventData::SELECTING == mImpl->mEventData->mState )
1893 // Update a font description run for the selecting state.
1894 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1895 mImpl->mModel->mLogicalModel,
1896 startOfSelectedText,
1897 lengthOfSelectedText );
1899 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1900 fontDescriptionRun.sizeDefined = true;
1902 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1903 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1904 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1908 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1909 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1910 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1913 // Request to relayout.
1914 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1919 UPDATE_LAYOUT_SIZE |
1922 mImpl->mRecalculateNaturalSize = true;
1923 mImpl->RequestRelayout();
1925 // As the font might change, recalculate the handle positions is needed.
1926 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1927 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1928 mImpl->mEventData->mUpdateHighlightBox = true;
1929 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1934 float Controller::GetInputFontPointSize() const
1936 if( NULL != mImpl->mEventData )
1938 return mImpl->mEventData->mInputStyle.size;
1941 // Return the default font's point size if there is no EventData.
1942 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1945 void Controller::SetInputLineSpacing( float lineSpacing )
1947 if( NULL != mImpl->mEventData )
1949 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1950 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1954 float Controller::GetInputLineSpacing() const
1956 if( NULL != mImpl->mEventData )
1958 return mImpl->mEventData->mInputStyle.lineSpacing;
1964 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1966 if( NULL != mImpl->mEventData )
1968 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1972 const std::string& Controller::GetInputShadowProperties() const
1974 if( NULL != mImpl->mEventData )
1976 return mImpl->mEventData->mInputStyle.shadowProperties;
1979 return EMPTY_STRING;
1982 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1984 if( NULL != mImpl->mEventData )
1986 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1990 const std::string& Controller::GetInputUnderlineProperties() const
1992 if( NULL != mImpl->mEventData )
1994 return mImpl->mEventData->mInputStyle.underlineProperties;
1997 return EMPTY_STRING;
2000 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
2002 if( NULL != mImpl->mEventData )
2004 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
2008 const std::string& Controller::GetInputEmbossProperties() const
2010 if( NULL != mImpl->mEventData )
2012 return mImpl->mEventData->mInputStyle.embossProperties;
2015 return GetDefaultEmbossProperties();
2018 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
2020 if( NULL != mImpl->mEventData )
2022 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
2026 const std::string& Controller::GetInputOutlineProperties() const
2028 if( NULL != mImpl->mEventData )
2030 return mImpl->mEventData->mInputStyle.outlineProperties;
2033 return GetDefaultOutlineProperties();
2036 void Controller::SetInputModePassword( bool passwordInput )
2038 if( NULL != mImpl->mEventData )
2040 mImpl->mEventData->mPasswordInput = passwordInput;
2044 bool Controller::IsInputModePassword()
2046 if( NULL != mImpl->mEventData )
2048 return mImpl->mEventData->mPasswordInput;
2053 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
2055 if( NULL != mImpl->mEventData )
2057 mImpl->mEventData->mDoubleTapAction = action;
2061 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
2063 NoTextTap::Action action = NoTextTap::NO_ACTION;
2065 if( NULL != mImpl->mEventData )
2067 action = mImpl->mEventData->mDoubleTapAction;
2073 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
2075 if( NULL != mImpl->mEventData )
2077 mImpl->mEventData->mLongPressAction = action;
2081 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
2083 NoTextTap::Action action = NoTextTap::NO_ACTION;
2085 if( NULL != mImpl->mEventData )
2087 action = mImpl->mEventData->mLongPressAction;
2093 bool Controller::IsUnderlineSetByString()
2095 return mImpl->mUnderlineSetByString;
2098 void Controller::UnderlineSetByString( bool setByString )
2100 mImpl->mUnderlineSetByString = setByString;
2103 bool Controller::IsShadowSetByString()
2105 return mImpl->mShadowSetByString;
2108 void Controller::ShadowSetByString( bool setByString )
2110 mImpl->mShadowSetByString = setByString;
2113 bool Controller::IsOutlineSetByString()
2115 return mImpl->mOutlineSetByString;
2118 void Controller::OutlineSetByString( bool setByString )
2120 mImpl->mOutlineSetByString = setByString;
2123 bool Controller::IsFontStyleSetByString()
2125 return mImpl->mFontStyleSetByString;
2128 void Controller::FontStyleSetByString( bool setByString )
2130 mImpl->mFontStyleSetByString = setByString;
2133 // public : Queries & retrieves.
2135 Layout::Engine& Controller::GetLayoutEngine()
2137 return mImpl->mLayoutEngine;
2140 View& Controller::GetView()
2142 return mImpl->mView;
2145 Vector3 Controller::GetNaturalSize()
2147 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2148 Vector3 naturalSize;
2150 // Make sure the model is up-to-date before layouting
2151 ProcessModifyEvents();
2153 if( mImpl->mRecalculateNaturalSize )
2155 // Operations that can be done only once until the text changes.
2156 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2162 GET_GLYPH_METRICS );
2164 // Set the update info to relayout the whole text.
2165 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2166 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2168 // Make sure the model is up-to-date before layouting
2169 mImpl->UpdateModel( onlyOnceOperations );
2171 // Layout the text for the new width.
2172 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2174 // Store the actual control's size to restore later.
2175 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2177 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2178 static_cast<OperationsMask>( onlyOnceOperations |
2180 naturalSize.GetVectorXY() );
2182 // Do not do again the only once operations.
2183 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2185 // Do the size related operations again.
2186 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2189 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2191 // Stores the natural size to avoid recalculate it again
2192 // unless the text/style changes.
2193 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2195 mImpl->mRecalculateNaturalSize = false;
2197 // Clear the update info. This info will be set the next time the text is updated.
2198 mImpl->mTextUpdateInfo.Clear();
2199 mImpl->mTextUpdateInfo.mClearAll = true;
2201 // Restore the actual control's size.
2202 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2204 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2208 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2210 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2213 naturalSize.x = ConvertToEven( naturalSize.x );
2214 naturalSize.y = ConvertToEven( naturalSize.y );
2219 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2222 mImpl->mFontDefaults->mFitPointSize = pointSize;
2223 mImpl->mFontDefaults->sizeDefined = true;
2226 // Operations that can be done only once until the text changes.
2227 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2233 GET_GLYPH_METRICS );
2235 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2236 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2238 // Make sure the model is up-to-date before layouting
2239 mImpl->UpdateModel( onlyOnceOperations );
2241 DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2242 static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2245 // Clear the update info. This info will be set the next time the text is updated.
2246 mImpl->mTextUpdateInfo.Clear();
2247 mImpl->mTextUpdateInfo.mClearAll = true;
2249 if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2256 void Controller::FitPointSizeforLayout( Size layoutSize )
2258 const OperationsMask operations = mImpl->mOperationsPending;
2259 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) || mImpl->mTextFitContentSize != layoutSize )
2261 bool actualellipsis = mImpl->mModel->mElideEnabled;
2262 float minPointSize = mImpl->mTextFitMinSize;
2263 float maxPointSize = mImpl->mTextFitMaxSize;
2264 float pointInterval = mImpl->mTextFitStepSize;
2266 mImpl->mModel->mElideEnabled = false;
2267 Vector<float> pointSizeArray;
2270 if( pointInterval < 1.f )
2272 mImpl->mTextFitStepSize = pointInterval = 1.0f;
2275 pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2277 for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2279 pointSizeArray.PushBack( i );
2282 pointSizeArray.PushBack( maxPointSize );
2284 int bestSizeIndex = 0;
2285 int min = bestSizeIndex + 1;
2286 int max = pointSizeArray.Size() - 1;
2289 int destI = ( min + max ) / 2;
2291 if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2293 bestSizeIndex = min;
2299 bestSizeIndex = max;
2303 mImpl->mModel->mElideEnabled = actualellipsis;
2304 mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2305 mImpl->mFontDefaults->sizeDefined = true;
2310 float Controller::GetHeightForWidth( float width )
2312 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2313 // Make sure the model is up-to-date before layouting
2314 ProcessModifyEvents();
2317 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2318 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2319 mImpl->mTextUpdateInfo.mClearAll )
2321 // Operations that can be done only once until the text changes.
2322 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2328 GET_GLYPH_METRICS );
2330 // Set the update info to relayout the whole text.
2331 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2332 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2334 // Make sure the model is up-to-date before layouting
2335 mImpl->UpdateModel( onlyOnceOperations );
2338 // Layout the text for the new width.
2339 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2341 // Store the actual control's width.
2342 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2344 DoRelayout( Size( width, MAX_FLOAT ),
2345 static_cast<OperationsMask>( onlyOnceOperations |
2349 // Do not do again the only once operations.
2350 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2352 // Do the size related operations again.
2353 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2357 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2359 // Clear the update info. This info will be set the next time the text is updated.
2360 mImpl->mTextUpdateInfo.Clear();
2361 mImpl->mTextUpdateInfo.mClearAll = true;
2363 // Restore the actual control's width.
2364 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2366 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2370 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2371 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2374 return layoutSize.height;
2377 int Controller::GetLineCount( float width )
2379 GetHeightForWidth( width );
2380 int numberofLines = mImpl->mModel->GetNumberOfLines();
2381 return numberofLines;
2384 const ModelInterface* const Controller::GetTextModel() const
2386 return mImpl->mModel.Get();
2389 float Controller::GetScrollAmountByUserInput()
2391 float scrollAmount = 0.0f;
2393 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2395 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2396 mImpl->mEventData->mCheckScrollAmount = false;
2398 return scrollAmount;
2401 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2403 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2406 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2407 layoutHeight = layout.height;
2408 scrollPosition = mImpl->mModel->mScrollPosition.y;
2409 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2413 void Controller::SetHiddenInputOption(const Property::Map& options )
2415 if( NULL == mImpl->mHiddenInput )
2417 mImpl->mHiddenInput = new HiddenText( this );
2419 mImpl->mHiddenInput->SetProperties(options);
2422 void Controller::GetHiddenInputOption(Property::Map& options )
2424 if( NULL != mImpl->mHiddenInput )
2426 mImpl->mHiddenInput->GetProperties(options);
2430 void Controller::SetPlaceholderProperty( const Property::Map& map )
2432 const Property::Map::SizeType count = map.Count();
2434 for( Property::Map::SizeType position = 0; position < count; ++position )
2436 KeyValuePair keyValue = map.GetKeyValue( position );
2437 Property::Key& key = keyValue.first;
2438 Property::Value& value = keyValue.second;
2440 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2442 std::string text = "";
2444 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2446 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2448 std::string text = "";
2450 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2452 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2455 value.Get( textColor );
2456 if( GetPlaceholderTextColor() != textColor )
2458 SetPlaceholderTextColor( textColor );
2461 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2463 std::string fontFamily = "";
2464 value.Get( fontFamily );
2465 SetPlaceholderFontFamily( fontFamily );
2467 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2469 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2471 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2474 value.Get( pointSize );
2475 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2477 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2480 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2483 value.Get( pixelSize );
2484 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2486 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2489 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2492 value.Get( ellipsis );
2493 SetPlaceholderTextElideEnabled( ellipsis );
2498 void Controller::GetPlaceholderProperty( Property::Map& map )
2500 if( NULL != mImpl->mEventData )
2502 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2504 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2506 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2508 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2511 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2512 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2514 Property::Value fontStyleMapGet;
2515 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2516 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2518 // Choose font size : POINT_SIZE or PIXEL_SIZE
2519 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2521 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2525 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2528 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2530 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2535 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2537 // Make sure the model is up-to-date before layouting
2538 ProcessModifyEvents();
2540 if ( mImpl->mUpdateTextDirection )
2542 // Operations that can be done only once until the text changes.
2543 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2549 GET_GLYPH_METRICS );
2551 // Set the update info to relayout the whole text.
2552 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2553 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2555 // Make sure the model is up-to-date before layouting
2556 mImpl->UpdateModel( onlyOnceOperations );
2558 Vector3 naturalSize;
2559 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2560 static_cast<OperationsMask>( onlyOnceOperations |
2561 LAYOUT | REORDER | UPDATE_DIRECTION ),
2562 naturalSize.GetVectorXY() );
2564 // Do not do again the only once operations.
2565 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2567 // Clear the update info. This info will be set the next time the text is updated.
2568 mImpl->mTextUpdateInfo.Clear();
2570 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
2571 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2573 mImpl->mUpdateTextDirection = false;
2576 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2579 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2581 return mImpl->mModel->GetVerticalLineAlignment();
2584 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2586 mImpl->mModel->mVerticalLineAlignment = alignment;
2589 // public : Relayout.
2591 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2593 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2595 UpdateTextType updateTextType = NONE_UPDATED;
2597 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2599 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2601 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2602 updateTextType = MODEL_UPDATED;
2605 // Clear the update info. This info will be set the next time the text is updated.
2606 mImpl->mTextUpdateInfo.Clear();
2608 // Not worth to relayout if width or height is equal to zero.
2609 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2611 return updateTextType;
2614 // Whether a new size has been set.
2615 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2619 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2621 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2622 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2623 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2625 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2628 // Layout operations that need to be done if the size changes.
2629 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2632 UPDATE_LAYOUT_SIZE |
2634 // Set the update info to relayout the whole text.
2635 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2636 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2638 // Store the size used to layout the text.
2639 mImpl->mModel->mVisualModel->mControlSize = size;
2642 // Whether there are modify events.
2643 if( 0u != mImpl->mModifyEvents.Count() )
2645 // Style operations that need to be done if the text is modified.
2646 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2650 // Set the update info to elide the text.
2651 if( mImpl->mModel->mElideEnabled ||
2652 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2654 // Update Text layout for applying elided
2655 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2658 UPDATE_LAYOUT_SIZE |
2660 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2661 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2664 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2666 // Clear the update info. This info will be set the next time the text is updated.
2667 mImpl->mTextUpdateInfo.mClearAll = true;
2668 // Apply modifications to the model
2669 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2670 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2677 mImpl->mLayoutDirection = layoutDirection;
2680 // Make sure the model is up-to-date before layouting.
2681 ProcessModifyEvents();
2682 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2686 updated = DoRelayout( size,
2687 mImpl->mOperationsPending,
2688 layoutSize ) || updated;
2693 updateTextType = MODEL_UPDATED;
2696 // Do not re-do any operation until something changes.
2697 mImpl->mOperationsPending = NO_OPERATION;
2698 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2700 // Whether the text control is editable
2701 const bool isEditable = NULL != mImpl->mEventData;
2703 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2705 if( newSize && isEditable )
2707 offset = mImpl->mModel->mScrollPosition;
2710 if( !isEditable || !IsMultiLineEnabled() )
2712 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2713 CalculateVerticalOffset( size );
2720 // If there is a new size, the scroll position needs to be clamped.
2721 mImpl->ClampHorizontalScroll( layoutSize );
2723 // Update the decorator's positions is needed if there is a new size.
2724 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2727 // Move the cursor, grab handle etc.
2728 if( mImpl->ProcessInputEvents() )
2730 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2734 // Clear the update info. This info will be set the next time the text is updated.
2735 mImpl->mTextUpdateInfo.Clear();
2736 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2738 return updateTextType;
2741 void Controller::RequestRelayout()
2743 mImpl->RequestRelayout();
2746 // public : Input style change signals.
2748 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2750 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2753 void Controller::ProcessInputStyleChangedSignals()
2755 if( NULL == mImpl->mEventData )
2761 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2762 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2766 const InputStyle::Mask mask = *it;
2768 if( NULL != mImpl->mEditableControlInterface )
2770 // Emit the input style changed signal.
2771 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2775 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2778 // public : Text-input Event Queuing.
2780 void Controller::KeyboardFocusGainEvent()
2782 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2784 if( NULL != mImpl->mEventData )
2786 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2787 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2789 mImpl->ChangeState( EventData::EDITING );
2790 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2791 mImpl->mEventData->mUpdateInputStyle = true;
2792 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2794 mImpl->NotifyInputMethodContextMultiLineStatus();
2795 if( mImpl->IsShowingPlaceholderText() )
2797 // Show alternative placeholder-text when editing
2798 ShowPlaceholderText();
2801 mImpl->RequestRelayout();
2805 void Controller::KeyboardFocusLostEvent()
2807 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2809 if( NULL != mImpl->mEventData )
2811 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2813 mImpl->ChangeState( EventData::INACTIVE );
2815 if( !mImpl->IsShowingRealText() )
2817 // Revert to regular placeholder-text when not editing
2818 ShowPlaceholderText();
2822 mImpl->RequestRelayout();
2825 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2827 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2829 bool textChanged = false;
2830 bool relayoutNeeded = false;
2832 if( ( NULL != mImpl->mEventData ) &&
2833 ( keyEvent.GetState() == KeyEvent::DOWN ) )
2835 int keyCode = keyEvent.GetKeyCode();
2836 const std::string& keyString = keyEvent.GetKeyString();
2837 const std::string keyName = keyEvent.GetKeyName();
2839 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2841 // Pre-process to separate modifying events from non-modifying input events.
2844 // In some platforms arrive key events with no key code.
2848 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2853 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2854 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2855 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2856 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2858 // If don't have any text, do nothing.
2859 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2864 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2865 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2866 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2867 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2869 // Logic to determine whether this text control will lose focus or not.
2870 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2871 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2872 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2873 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2874 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2875 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2877 // Release the active highlight.
2878 if( mImpl->mEventData->mState == EventData::SELECTING )
2880 mImpl->ChangeState( EventData::EDITING );
2882 // Update selection position.
2883 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2884 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2885 mImpl->mEventData->mUpdateCursorPosition = true;
2886 mImpl->RequestRelayout();
2891 mImpl->mEventData->mCheckScrollAmount = true;
2892 Event event( Event::CURSOR_KEY_EVENT );
2893 event.p1.mInt = keyCode;
2894 event.p2.mBool = keyEvent.IsShiftModifier();
2895 mImpl->mEventData->mEventQueue.push_back( event );
2897 // Will request for relayout.
2898 relayoutNeeded = true;
2900 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2902 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2903 // If not handle it here, any selected text will be deleted
2908 else if ( keyEvent.IsCtrlModifier() )
2910 bool consumed = false;
2911 if (keyName == KEY_C_NAME)
2913 // Ctrl-C to copy the selected text
2914 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2917 else if (keyName == KEY_V_NAME)
2919 // Ctrl-V to paste the copied text
2920 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2923 else if (keyName == KEY_X_NAME)
2925 // Ctrl-X to cut the selected text
2926 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2931 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2932 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2934 textChanged = DeleteEvent( keyCode );
2936 // Will request for relayout.
2937 relayoutNeeded = true;
2939 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2940 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2941 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2943 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2944 mImpl->ChangeState( EventData::INACTIVE );
2946 // Will request for relayout.
2947 relayoutNeeded = true;
2949 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2951 else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2953 // 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
2954 // and a character is typed after the type of a upper case latin character.
2959 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2961 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2967 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2969 if( !keyString.empty() )
2971 // InputMethodContext is no longer handling key-events
2972 mImpl->ClearPreEditFlag();
2974 InsertText( keyString, COMMIT );
2978 // Will request for relayout.
2979 relayoutNeeded = true;
2984 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2985 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2987 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2988 ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2989 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2990 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2992 // Should not change the state if the key is the shift send by the InputMethodContext.
2993 // Otherwise, when the state is SELECTING the text controller can't send the right
2994 // surrounding info to the InputMethodContext.
2995 mImpl->ChangeState( EventData::EDITING );
2997 // Will request for relayout.
2998 relayoutNeeded = true;
3001 if( relayoutNeeded )
3003 mImpl->RequestRelayout();
3008 ( NULL != mImpl->mEditableControlInterface ) )
3010 // Do this last since it provides callbacks into application code
3011 mImpl->mEditableControlInterface->TextChanged();
3017 void Controller::TapEvent( unsigned int tapCount, float x, float y )
3019 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
3021 if( NULL != mImpl->mEventData )
3023 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
3024 EventData::State state( mImpl->mEventData->mState );
3025 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
3027 if( mImpl->IsClipboardVisible() )
3029 if( EventData::INACTIVE == state || EventData::EDITING == state)
3031 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
3033 relayoutNeeded = true;
3035 else if( 1u == tapCount )
3037 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
3039 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
3042 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
3044 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
3045 relayoutNeeded = true;
3049 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
3051 // Hide placeholder text
3055 if( EventData::INACTIVE == state )
3057 mImpl->ChangeState( EventData::EDITING );
3059 else if( !mImpl->IsClipboardEmpty() )
3061 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
3063 relayoutNeeded = true;
3066 else if( 2u == tapCount )
3068 if( mImpl->mEventData->mSelectionEnabled &&
3069 mImpl->IsShowingRealText() )
3071 relayoutNeeded = true;
3072 mImpl->mEventData->mIsLeftHandleSelected = true;
3073 mImpl->mEventData->mIsRightHandleSelected = true;
3077 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
3078 if( relayoutNeeded )
3080 Event event( Event::TAP_EVENT );
3081 event.p1.mUint = tapCount;
3082 event.p2.mFloat = x;
3083 event.p3.mFloat = y;
3084 mImpl->mEventData->mEventQueue.push_back( event );
3086 mImpl->RequestRelayout();
3090 // Reset keyboard as tap event has occurred.
3091 mImpl->ResetInputMethodContext();
3094 void Controller::PanEvent( GestureState state, const Vector2& displacement )
3096 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
3098 if( NULL != mImpl->mEventData )
3100 Event event( Event::PAN_EVENT );
3101 event.p1.mInt = static_cast<int>( state );
3102 event.p2.mFloat = displacement.x;
3103 event.p3.mFloat = displacement.y;
3104 mImpl->mEventData->mEventQueue.push_back( event );
3106 mImpl->RequestRelayout();
3110 void Controller::LongPressEvent( GestureState state, float x, float y )
3112 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
3114 if( ( state == GestureState::STARTED ) &&
3115 ( NULL != mImpl->mEventData ) )
3117 // The 1st long-press on inactive text-field is treated as tap
3118 if( EventData::INACTIVE == mImpl->mEventData->mState )
3120 mImpl->ChangeState( EventData::EDITING );
3122 Event event( Event::TAP_EVENT );
3124 event.p2.mFloat = x;
3125 event.p3.mFloat = y;
3126 mImpl->mEventData->mEventQueue.push_back( event );
3128 mImpl->RequestRelayout();
3130 else if( !mImpl->IsShowingRealText() )
3132 Event event( Event::LONG_PRESS_EVENT );
3133 event.p1.mInt = static_cast<int>( state );
3134 event.p2.mFloat = x;
3135 event.p3.mFloat = y;
3136 mImpl->mEventData->mEventQueue.push_back( event );
3137 mImpl->RequestRelayout();
3139 else if( !mImpl->IsClipboardVisible() )
3141 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3142 mImpl->ResetInputMethodContext();
3144 Event event( Event::LONG_PRESS_EVENT );
3145 event.p1.mInt = static_cast<int>( state );
3146 event.p2.mFloat = x;
3147 event.p3.mFloat = y;
3148 mImpl->mEventData->mEventQueue.push_back( event );
3149 mImpl->RequestRelayout();
3151 mImpl->mEventData->mIsLeftHandleSelected = true;
3152 mImpl->mEventData->mIsRightHandleSelected = true;
3157 void Controller::SelectEvent( float x, float y, SelectionType selectType )
3159 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3161 if( NULL != mImpl->mEventData )
3163 if( selectType == SelectionType::ALL )
3165 Event event( Event::SELECT_ALL );
3166 mImpl->mEventData->mEventQueue.push_back( event );
3168 else if( selectType == SelectionType::NONE )
3170 Event event( Event::SELECT_NONE );
3171 mImpl->mEventData->mEventQueue.push_back( event );
3175 Event event( Event::SELECT );
3176 event.p2.mFloat = x;
3177 event.p3.mFloat = y;
3178 mImpl->mEventData->mEventQueue.push_back( event );
3181 mImpl->mEventData->mCheckScrollAmount = true;
3182 mImpl->mEventData->mIsLeftHandleSelected = true;
3183 mImpl->mEventData->mIsRightHandleSelected = true;
3184 mImpl->RequestRelayout();
3188 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3190 // Whether the text needs to be relaid-out.
3191 bool requestRelayout = false;
3193 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3194 bool retrieveText = false;
3195 bool retrieveCursor = false;
3197 switch( inputMethodContextEvent.eventName )
3199 case InputMethodContext::COMMIT:
3201 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3202 requestRelayout = true;
3203 retrieveCursor = true;
3206 case InputMethodContext::PRE_EDIT:
3208 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3209 requestRelayout = true;
3210 retrieveCursor = true;
3213 case InputMethodContext::DELETE_SURROUNDING:
3215 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3216 inputMethodContextEvent.numberOfChars,
3217 DONT_UPDATE_INPUT_STYLE );
3221 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3222 !mImpl->IsPlaceholderAvailable() )
3224 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3228 ShowPlaceholderText();
3230 mImpl->mEventData->mUpdateCursorPosition = true;
3231 mImpl->mEventData->mScrollAfterDelete = true;
3233 requestRelayout = true;
3237 case InputMethodContext::GET_SURROUNDING:
3239 retrieveText = true;
3240 retrieveCursor = true;
3243 case InputMethodContext::PRIVATE_COMMAND:
3245 // PRIVATECOMMAND event is just for getting the private command message
3246 retrieveText = true;
3247 retrieveCursor = true;
3250 case InputMethodContext::VOID:
3257 if( requestRelayout )
3259 mImpl->mOperationsPending = ALL_OPERATIONS;
3260 mImpl->RequestRelayout();
3264 CharacterIndex cursorPosition = 0u;
3265 Length numberOfWhiteSpaces = 0u;
3267 if( retrieveCursor )
3269 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3271 cursorPosition = mImpl->GetLogicalCursorPosition();
3273 if( cursorPosition < numberOfWhiteSpaces )
3275 cursorPosition = 0u;
3279 cursorPosition -= numberOfWhiteSpaces;
3285 if( !mImpl->IsShowingPlaceholderText() )
3287 // Retrieves the normal text string.
3288 mImpl->GetText( numberOfWhiteSpaces, text );
3292 // When the current text is Placeholder Text, the surrounding text should be empty string.
3293 // It means DALi should send empty string ("") to IME.
3298 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3300 if( requestRelayout &&
3301 ( NULL != mImpl->mEditableControlInterface ) )
3303 // Do this last since it provides callbacks into application code
3304 mImpl->mEditableControlInterface->TextChanged();
3307 return callbackData;
3310 void Controller::PasteClipboardItemEvent()
3312 // Retrieve the clipboard contents first
3313 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3314 std::string stringToPaste( notifier.GetContent() );
3316 // Commit the current pre-edit text; the contents of the clipboard should be appended
3317 mImpl->ResetInputMethodContext();
3319 // Temporary disable hiding clipboard
3320 mImpl->SetClipboardHideEnable( false );
3323 PasteText( stringToPaste );
3325 mImpl->SetClipboardHideEnable( true );
3328 // protected : Inherit from Text::Decorator::ControllerInterface.
3330 void Controller::GetTargetSize( Vector2& targetSize )
3332 targetSize = mImpl->mModel->mVisualModel->mControlSize;
3335 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3337 if( NULL != mImpl->mEditableControlInterface )
3339 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3343 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3345 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3347 if( NULL != mImpl->mEventData )
3349 switch( handleType )
3353 Event event( Event::GRAB_HANDLE_EVENT );
3354 event.p1.mUint = state;
3355 event.p2.mFloat = x;
3356 event.p3.mFloat = y;
3358 mImpl->mEventData->mEventQueue.push_back( event );
3361 case LEFT_SELECTION_HANDLE:
3363 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3364 event.p1.mUint = state;
3365 event.p2.mFloat = x;
3366 event.p3.mFloat = y;
3368 mImpl->mEventData->mEventQueue.push_back( event );
3371 case RIGHT_SELECTION_HANDLE:
3373 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3374 event.p1.mUint = state;
3375 event.p2.mFloat = x;
3376 event.p3.mFloat = y;
3378 mImpl->mEventData->mEventQueue.push_back( event );
3381 case LEFT_SELECTION_HANDLE_MARKER:
3382 case RIGHT_SELECTION_HANDLE_MARKER:
3384 // Markers do not move the handles.
3387 case HANDLE_TYPE_COUNT:
3389 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3393 mImpl->RequestRelayout();
3397 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3399 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3401 if( NULL == mImpl->mEventData )
3408 case Toolkit::TextSelectionPopup::CUT:
3410 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3411 mImpl->mOperationsPending = ALL_OPERATIONS;
3413 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3414 !mImpl->IsPlaceholderAvailable() )
3416 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3420 ShowPlaceholderText();
3423 mImpl->mEventData->mUpdateCursorPosition = true;
3424 mImpl->mEventData->mScrollAfterDelete = true;
3426 mImpl->RequestRelayout();
3428 if( NULL != mImpl->mEditableControlInterface )
3430 mImpl->mEditableControlInterface->TextChanged();
3434 case Toolkit::TextSelectionPopup::COPY:
3436 mImpl->SendSelectionToClipboard( false ); // Text not modified
3438 mImpl->mEventData->mUpdateCursorPosition = true;
3440 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3443 case Toolkit::TextSelectionPopup::PASTE:
3445 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3448 case Toolkit::TextSelectionPopup::SELECT:
3450 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3452 if( mImpl->mEventData->mSelectionEnabled )
3454 // Creates a SELECT event.
3455 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, SelectionType::INTERACTIVE );
3459 case Toolkit::TextSelectionPopup::SELECT_ALL:
3461 // Creates a SELECT_ALL event
3462 SelectEvent( 0.f, 0.f, SelectionType::ALL );
3465 case Toolkit::TextSelectionPopup::CLIPBOARD:
3467 mImpl->ShowClipboard();
3470 case Toolkit::TextSelectionPopup::NONE:
3478 void Controller::DisplayTimeExpired()
3480 mImpl->mEventData->mUpdateCursorPosition = true;
3481 // Apply modifications to the model
3482 mImpl->mOperationsPending = ALL_OPERATIONS;
3484 mImpl->RequestRelayout();
3487 // private : Update.
3489 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3491 bool removedPrevious = false;
3492 bool removedSelected = false;
3493 bool maxLengthReached = false;
3495 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3497 if( NULL == mImpl->mEventData )
3502 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3503 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3504 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3506 // TODO: At the moment the underline runs are only for pre-edit.
3507 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3509 // Remove the previous InputMethodContext pre-edit.
3510 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3512 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3513 mImpl->mEventData->mPreEditLength,
3514 DONT_UPDATE_INPUT_STYLE );
3516 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3517 mImpl->mEventData->mPreEditLength = 0u;
3521 // Remove the previous Selection.
3522 removedSelected = RemoveSelectedText();
3526 Vector<Character> utf32Characters;
3527 Length characterCount = 0u;
3531 // Convert text into UTF-32
3532 utf32Characters.Resize( text.size() );
3534 // This is a bit horrible but std::string returns a (signed) char*
3535 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3537 // Transform a text array encoded in utf8 into an array encoded in utf32.
3538 // It returns the actual number of characters.
3539 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3540 utf32Characters.Resize( characterCount );
3542 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3543 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3546 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3548 // The placeholder text is no longer needed
3549 if( mImpl->IsShowingPlaceholderText() )
3554 mImpl->ChangeState( EventData::EDITING );
3556 // Handle the InputMethodContext (predicitive text) state changes
3557 if( COMMIT == type )
3559 // InputMethodContext is no longer handling key-events
3560 mImpl->ClearPreEditFlag();
3564 if( !mImpl->mEventData->mPreEditFlag )
3566 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3568 // Record the start of the pre-edit text
3569 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3572 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3573 mImpl->mEventData->mPreEditFlag = true;
3575 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3578 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3580 // Restrict new text to fit within Maximum characters setting.
3581 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3582 maxLengthReached = ( characterCount > maxSizeOfNewText );
3584 // The cursor position.
3585 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3587 // Update the text's style.
3589 // Updates the text style runs by adding characters.
3590 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3592 // Get the character index from the cursor index.
3593 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3595 // Retrieve the text's style for the given index.
3597 mImpl->RetrieveDefaultInputStyle( style );
3598 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3600 // Whether to add a new text color run.
3601 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3603 // Whether to add a new font run.
3604 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3605 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3606 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3607 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3608 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3613 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3614 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3616 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3617 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3618 colorRun.characterRun.characterIndex = cursorIndex;
3619 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3622 if( addFontNameRun ||
3628 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3629 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3631 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3633 if( addFontNameRun )
3635 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3636 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3637 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3638 fontDescriptionRun.familyDefined = true;
3640 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3643 if( addFontWeightRun )
3645 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3646 fontDescriptionRun.weightDefined = true;
3649 if( addFontWidthRun )
3651 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3652 fontDescriptionRun.widthDefined = true;
3655 if( addFontSlantRun )
3657 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3658 fontDescriptionRun.slantDefined = true;
3661 if( addFontSizeRun )
3663 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3664 fontDescriptionRun.sizeDefined = true;
3667 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3668 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3671 // Insert at current cursor position.
3672 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3674 if( cursorIndex < numberOfCharactersInModel )
3676 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3680 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3683 // Mark the first paragraph to be updated.
3684 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3686 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3687 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3688 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3689 mImpl->mTextUpdateInfo.mClearAll = true;
3693 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3694 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3697 // Update the cursor index.
3698 cursorIndex += maxSizeOfNewText;
3700 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 );
3703 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3704 mImpl->IsPlaceholderAvailable() )
3706 // Show place-holder if empty after removing the pre-edit text
3707 ShowPlaceholderText();
3708 mImpl->mEventData->mUpdateCursorPosition = true;
3709 mImpl->ClearPreEditFlag();
3711 else if( removedPrevious ||
3713 ( 0 != utf32Characters.Count() ) )
3715 // Queue an inserted event
3716 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3718 mImpl->mEventData->mUpdateCursorPosition = true;
3719 if( removedSelected )
3721 mImpl->mEventData->mScrollAfterDelete = true;
3725 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3729 if( maxLengthReached )
3731 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3733 mImpl->ResetInputMethodContext();
3735 if( NULL != mImpl->mEditableControlInterface )
3737 // Do this last since it provides callbacks into application code
3738 mImpl->mEditableControlInterface->MaxLengthReached();
3743 void Controller::PasteText( const std::string& stringToPaste )
3745 InsertText( stringToPaste, Text::Controller::COMMIT );
3746 mImpl->ChangeState( EventData::EDITING );
3747 mImpl->RequestRelayout();
3749 if( NULL != mImpl->mEditableControlInterface )
3751 // Do this last since it provides callbacks into application code
3752 mImpl->mEditableControlInterface->TextChanged();
3756 bool Controller::RemoveText( int cursorOffset,
3757 int numberOfCharacters,
3758 UpdateInputStyleType type )
3760 bool removed = false;
3762 if( NULL == mImpl->mEventData )
3767 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3768 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3770 if( !mImpl->IsShowingPlaceholderText() )
3772 // Delete at current cursor position
3773 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3774 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3776 CharacterIndex cursorIndex = 0;
3778 // Validate the cursor position & number of characters
3779 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3781 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3784 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3786 numberOfCharacters = currentText.Count() - cursorIndex;
3789 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.
3790 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3792 // Mark the paragraphs to be updated.
3793 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3795 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3796 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3797 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3798 mImpl->mTextUpdateInfo.mClearAll = true;
3802 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3803 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3806 // Update the input style and remove the text's style before removing the text.
3808 if( UPDATE_INPUT_STYLE == type )
3810 // Keep a copy of the current input style.
3811 InputStyle currentInputStyle;
3812 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3814 // Set first the default input style.
3815 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3817 // Update the input style.
3818 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3820 // Compare if the input style has changed.
3821 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3823 if( hasInputStyleChanged )
3825 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3826 // Queue the input style changed signal.
3827 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3831 // If the number of current text and the number of characters to be deleted are same,
3832 // it means all texts should be removed and all Preedit variables should be initialized.
3833 if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
3835 mImpl->ClearPreEditFlag();
3836 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0;
3839 // Updates the text style runs by removing characters. Runs with no characters are removed.
3840 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3842 // Remove the characters.
3843 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3844 Vector<Character>::Iterator last = first + numberOfCharacters;
3846 currentText.Erase( first, last );
3848 // Cursor position retreat
3849 oldCursorIndex = cursorIndex;
3851 mImpl->mEventData->mScrollAfterDelete = true;
3853 if( EventData::INACTIVE == mImpl->mEventData->mState )
3855 mImpl->ChangeState( EventData::EDITING );
3858 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3866 bool Controller::RemoveSelectedText()
3868 bool textRemoved( false );
3870 if( EventData::SELECTING == mImpl->mEventData->mState )
3872 std::string removedString;
3873 mImpl->RetrieveSelection( removedString, true );
3875 if( !removedString.empty() )
3878 mImpl->ChangeState( EventData::EDITING );
3885 std::string Controller::GetSelectedText()
3888 if( EventData::SELECTING == mImpl->mEventData->mState )
3890 mImpl->RetrieveSelection( text, false );
3895 // private : Relayout.
3897 bool Controller::DoRelayout( const Size& size,
3898 OperationsMask operationsRequired,
3901 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3902 bool viewUpdated( false );
3904 // Calculate the operations to be done.
3905 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3907 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3908 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3910 // Get the current layout size.
3911 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3913 if( NO_OPERATION != ( LAYOUT & operations ) )
3915 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3917 // Some vectors with data needed to layout and reorder may be void
3918 // after the first time the text has been laid out.
3919 // Fill the vectors again.
3921 // Calculate the number of glyphs to layout.
3922 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3923 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3924 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3925 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3927 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3928 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3930 // Make sure the index is not out of bound
3931 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3932 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3933 ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3935 std::string currentText;
3936 GetText( currentText );
3938 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3939 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3940 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3945 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3946 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3948 if( 0u == totalNumberOfGlyphs )
3950 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3952 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3955 // Nothing else to do if there is no glyphs.
3956 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3960 // Set the layout parameters.
3961 Layout::Parameters layoutParameters( size,
3964 // Resize the vector of positions to have the same size than the vector of glyphs.
3965 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3966 glyphPositions.Resize( totalNumberOfGlyphs );
3968 // Whether the last character is a new paragraph character.
3969 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3970 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3971 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3973 // The initial glyph and the number of glyphs to layout.
3974 layoutParameters.startGlyphIndex = startGlyphIndex;
3975 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3976 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3977 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3979 // Update the ellipsis
3980 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3982 if( NULL != mImpl->mEventData )
3984 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3986 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3988 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3990 // Disable ellipsis when editing
3991 elideTextEnabled = false;
3994 // Reset the scroll position in inactive state
3995 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3997 ResetScrollPosition();
4001 // Update the visual model.
4002 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
4004 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
4007 isAutoScrollEnabled );
4008 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
4010 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
4014 layoutSize = newLayoutSize;
4016 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
4018 mImpl->mIsTextDirectionRTL = false;
4021 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !mImpl->mModel->mVisualModel->mLines.Empty() )
4023 mImpl->mIsTextDirectionRTL = mImpl->mModel->mVisualModel->mLines[0u].direction;
4026 // Sets the layout size.
4027 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
4029 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
4034 if( NO_OPERATION != ( ALIGN & operations ) )
4036 // The laid-out lines.
4037 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
4039 CharacterIndex alignStartIndex = startIndex;
4040 Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
4042 // the whole text needs to be full aligned.
4043 // If you do not do a full aligned, only the last line of the multiline input is aligned.
4044 if( mImpl->mEventData && mImpl->mEventData->mUpdateAlignment )
4046 alignStartIndex = 0u;
4047 alignRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
4048 mImpl->mEventData->mUpdateAlignment = false;
4051 // Need to align with the control's size as the text may contain lines
4052 // starting either with left to right text or right to left.
4053 mImpl->mLayoutEngine.Align( size,
4055 alignRequestedNumberOfCharacters,
4056 mImpl->mModel->mHorizontalAlignment,
4058 mImpl->mModel->mAlignmentOffset,
4059 mImpl->mLayoutDirection,
4060 mImpl->mModel->mMatchSystemLanguageDirection );
4064 #if defined(DEBUG_ENABLED)
4065 std::string currentText;
4066 GetText( currentText );
4067 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
4069 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
4073 void Controller::CalculateVerticalOffset( const Size& controlSize )
4075 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
4077 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
4079 // Get the line height of the default font.
4080 layoutSize.height = mImpl->GetDefaultFontLineHeight();
4083 switch( mImpl->mModel->mVerticalAlignment )
4085 case VerticalAlignment::TOP:
4087 mImpl->mModel->mScrollPosition.y = 0.f;
4090 case VerticalAlignment::CENTER:
4092 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
4095 case VerticalAlignment::BOTTOM:
4097 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
4103 // private : Events.
4105 void Controller::ProcessModifyEvents()
4107 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4109 if( 0u == events.Count() )
4115 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4116 endIt = events.End();
4120 const ModifyEvent& event = *it;
4122 if( ModifyEvent::TEXT_REPLACED == event.type )
4124 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4125 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4127 TextReplacedEvent();
4129 else if( ModifyEvent::TEXT_INSERTED == event.type )
4131 TextInsertedEvent();
4133 else if( ModifyEvent::TEXT_DELETED == event.type )
4135 // Placeholder-text cannot be deleted
4136 if( !mImpl->IsShowingPlaceholderText() )
4143 if( NULL != mImpl->mEventData )
4145 // When the text is being modified, delay cursor blinking
4146 mImpl->mEventData->mDecorator->DelayCursorBlink();
4148 // Update selection position after modifying the text
4149 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4150 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4153 // DISCARD temporary text
4157 void Controller::TextReplacedEvent()
4159 // The natural size needs to be re-calculated.
4160 mImpl->mRecalculateNaturalSize = true;
4162 // The text direction needs to be updated.
4163 mImpl->mUpdateTextDirection = true;
4165 // Apply modifications to the model
4166 mImpl->mOperationsPending = ALL_OPERATIONS;
4169 void Controller::TextInsertedEvent()
4171 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4173 if( NULL == mImpl->mEventData )
4178 mImpl->mEventData->mCheckScrollAmount = true;
4180 // The natural size needs to be re-calculated.
4181 mImpl->mRecalculateNaturalSize = true;
4183 // The text direction needs to be updated.
4184 mImpl->mUpdateTextDirection = true;
4186 // Apply modifications to the model; TODO - Optimize this
4187 mImpl->mOperationsPending = ALL_OPERATIONS;
4190 void Controller::TextDeletedEvent()
4192 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4194 if( NULL == mImpl->mEventData )
4199 mImpl->mEventData->mCheckScrollAmount = true;
4201 // The natural size needs to be re-calculated.
4202 mImpl->mRecalculateNaturalSize = true;
4204 // The text direction needs to be updated.
4205 mImpl->mUpdateTextDirection = true;
4207 // Apply modifications to the model; TODO - Optimize this
4208 mImpl->mOperationsPending = ALL_OPERATIONS;
4211 bool Controller::DeleteEvent( int keyCode )
4213 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4215 bool removed = false;
4217 if( NULL == mImpl->mEventData )
4222 // InputMethodContext is no longer handling key-events
4223 mImpl->ClearPreEditFlag();
4225 if( EventData::SELECTING == mImpl->mEventData->mState )
4227 removed = RemoveSelectedText();
4229 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4231 // Remove the character before the current cursor position
4232 removed = RemoveText( -1,
4234 UPDATE_INPUT_STYLE );
4236 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4238 // Remove the character after the current cursor position
4239 removed = RemoveText( 0,
4241 UPDATE_INPUT_STYLE );
4246 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4247 !mImpl->IsPlaceholderAvailable() )
4249 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4253 ShowPlaceholderText();
4255 mImpl->mEventData->mUpdateCursorPosition = true;
4256 mImpl->mEventData->mScrollAfterDelete = true;
4262 // private : Helpers.
4264 void Controller::ResetText()
4267 mImpl->mModel->mLogicalModel->mText.Clear();
4269 // Reset the embedded images buffer.
4270 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4272 // We have cleared everything including the placeholder-text
4273 mImpl->PlaceholderCleared();
4275 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4276 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4277 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4279 // Clear any previous text.
4280 mImpl->mTextUpdateInfo.mClearAll = true;
4282 // The natural size needs to be re-calculated.
4283 mImpl->mRecalculateNaturalSize = true;
4285 // The text direction needs to be updated.
4286 mImpl->mUpdateTextDirection = true;
4288 // Apply modifications to the model
4289 mImpl->mOperationsPending = ALL_OPERATIONS;
4292 void Controller::ShowPlaceholderText()
4294 if( mImpl->IsPlaceholderAvailable() )
4296 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4298 if( NULL == mImpl->mEventData )
4303 mImpl->mEventData->mIsShowingPlaceholderText = true;
4305 // Disable handles when showing place-holder text
4306 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4307 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4308 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4310 const char* text( NULL );
4313 // TODO - Switch Placeholder text when changing state
4314 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4315 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4317 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4318 size = mImpl->mEventData->mPlaceholderTextActive.size();
4322 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4323 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4326 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4327 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4329 // Reset model for showing placeholder.
4330 mImpl->mModel->mLogicalModel->mText.Clear();
4331 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4333 // Convert text into UTF-32
4334 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4335 utf32Characters.Resize( size );
4337 // This is a bit horrible but std::string returns a (signed) char*
4338 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4340 // Transform a text array encoded in utf8 into an array encoded in utf32.
4341 // It returns the actual number of characters.
4342 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4343 utf32Characters.Resize( characterCount );
4345 // The characters to be added.
4346 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4348 // Reset the cursor position
4349 mImpl->mEventData->mPrimaryCursorPosition = 0;
4351 // The natural size needs to be re-calculated.
4352 mImpl->mRecalculateNaturalSize = true;
4354 // The text direction needs to be updated.
4355 mImpl->mUpdateTextDirection = true;
4357 // Apply modifications to the model
4358 mImpl->mOperationsPending = ALL_OPERATIONS;
4360 // Update the rest of the model during size negotiation
4361 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4365 void Controller::ClearFontData()
4367 if( mImpl->mFontDefaults )
4369 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4372 // Set flags to update the model.
4373 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4374 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4375 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4377 mImpl->mTextUpdateInfo.mClearAll = true;
4378 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4379 mImpl->mRecalculateNaturalSize = true;
4381 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4387 UPDATE_LAYOUT_SIZE |
4392 void Controller::ClearStyleData()
4394 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4395 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4398 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4400 // Reset the cursor position
4401 if( NULL != mImpl->mEventData )
4403 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4405 // Update the cursor if it's in editing mode.
4406 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4408 mImpl->mEventData->mUpdateCursorPosition = true;
4413 void Controller::ResetScrollPosition()
4415 if( NULL != mImpl->mEventData )
4417 // Reset the scroll position.
4418 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4419 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4423 void Controller::SetControlInterface( ControlInterface* controlInterface )
4425 mImpl->mControlInterface = controlInterface;
4428 bool Controller::ShouldClearFocusOnEscape() const
4430 return mImpl->mShouldClearFocusOnEscape;
4433 Actor Controller::CreateBackgroundActor()
4435 return mImpl->CreateBackgroundActor();
4438 // private : Private contructors & copy operator.
4440 Controller::Controller()
4443 mImpl = new Controller::Impl( NULL, NULL );
4446 Controller::Controller( ControlInterface* controlInterface )
4448 mImpl = new Controller::Impl( controlInterface, NULL );
4451 Controller::Controller( ControlInterface* controlInterface,
4452 EditableControlInterface* editableControlInterface )
4454 mImpl = new Controller::Impl( controlInterface,
4455 editableControlInterface );
4458 // The copy constructor and operator are left unimplemented.
4460 // protected : Destructor.
4462 Controller::~Controller()
4469 } // namespace Toolkit