2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
28 #include <dali/devel-api/adaptor-framework/key-devel.h>
31 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
32 #include <dali-toolkit/internal/text/bidirectional-support.h>
33 #include <dali-toolkit/internal/text/character-set-conversion.h>
34 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
35 #include <dali-toolkit/internal/text/markup-processor.h>
36 #include <dali-toolkit/internal/text/multi-language-support.h>
37 #include <dali-toolkit/internal/text/text-controller-impl.h>
38 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
39 #include <dali-toolkit/internal/text/text-font-style.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
48 const float MAX_FLOAT = std::numeric_limits<float>::max();
50 const std::string EMPTY_STRING("");
52 const std::string KEY_C_NAME = "c";
53 const std::string KEY_V_NAME = "v";
54 const std::string KEY_X_NAME = "x";
56 const char * const PLACEHOLDER_TEXT = "text";
57 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
58 const char * const PLACEHOLDER_COLOR = "color";
59 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
60 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
61 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
62 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
63 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 float ConvertToEven( float value )
67 int intValue(static_cast<int>( value ));
68 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
83 * @brief Adds a new font description run for the selected text.
85 * The new font parameters are added after the call to this method.
87 * @param[in] eventData The event data pointer.
88 * @param[in] logicalModel The logical model where to add the new font description run.
89 * @param[out] startOfSelectedText Index to the first selected character.
90 * @param[out] lengthOfSelectedText Number of selected characters.
92 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
93 LogicalModelPtr logicalModel,
94 CharacterIndex& startOfSelectedText,
95 Length& lengthOfSelectedText )
97 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
99 // Get start and end position of selection
100 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
101 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
104 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
105 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
107 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
109 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
110 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
112 // Recalculate the selection highlight as the metrics may have changed.
113 eventData->mUpdateLeftSelectionPosition = true;
114 eventData->mUpdateRightSelectionPosition = true;
115 eventData->mUpdateHighlightBox = true;
117 return fontDescriptionRun;
120 // public : Constructor.
122 ControllerPtr Controller::New()
124 return ControllerPtr( new Controller() );
127 ControllerPtr Controller::New( ControlInterface* controlInterface )
129 return ControllerPtr( new Controller( controlInterface ) );
132 ControllerPtr Controller::New( ControlInterface* controlInterface,
133 EditableControlInterface* editableControlInterface )
135 return ControllerPtr( new Controller( controlInterface,
136 editableControlInterface ) );
139 // public : Configure the text controller.
141 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
145 delete mImpl->mEventData;
146 mImpl->mEventData = NULL;
148 // Nothing else to do.
152 if( NULL == mImpl->mEventData )
154 mImpl->mEventData = new EventData( decorator, inputMethodContext );
158 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
160 // Metrics for bitmap & vector based glyphs are different
161 mImpl->mMetrics->SetGlyphType( glyphType );
163 // Clear the font-specific data
166 mImpl->RequestRelayout();
169 void Controller::SetMarkupProcessorEnabled( bool enable )
171 if( enable != mImpl->mMarkupProcessorEnabled )
173 //If Text was already set, call the SetText again for enabling or disabling markup
174 mImpl->mMarkupProcessorEnabled = enable;
181 bool Controller::IsMarkupProcessorEnabled() const
183 return mImpl->mMarkupProcessorEnabled;
186 void Controller::SetAutoScrollEnabled( bool enable )
188 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
190 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
194 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
195 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
205 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
206 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
213 mImpl->mIsAutoScrollEnabled = enable;
214 mImpl->RequestRelayout();
218 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
219 mImpl->mIsAutoScrollEnabled = false;
223 bool Controller::IsAutoScrollEnabled() const
225 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
227 return mImpl->mIsAutoScrollEnabled;
230 CharacterDirection Controller::GetAutoScrollDirection() const
232 return mImpl->mIsTextDirectionRTL;
235 float Controller::GetAutoScrollLineAlignment() const
239 if( mImpl->mModel->mVisualModel &&
240 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
242 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
248 void Controller::SetHorizontalScrollEnabled( bool enable )
250 if( ( NULL != mImpl->mEventData ) &&
251 mImpl->mEventData->mDecorator )
253 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
256 bool Controller::IsHorizontalScrollEnabled() const
258 if( ( NULL != mImpl->mEventData ) &&
259 mImpl->mEventData->mDecorator )
261 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
267 void Controller::SetVerticalScrollEnabled( bool enable )
269 if( ( NULL != mImpl->mEventData ) &&
270 mImpl->mEventData->mDecorator )
272 if( mImpl->mEventData->mDecorator )
274 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
279 bool Controller::IsVerticalScrollEnabled() const
281 if( ( NULL != mImpl->mEventData ) &&
282 mImpl->mEventData->mDecorator )
284 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
290 void Controller::SetSmoothHandlePanEnabled( bool enable )
292 if( ( NULL != mImpl->mEventData ) &&
293 mImpl->mEventData->mDecorator )
295 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
299 bool Controller::IsSmoothHandlePanEnabled() const
301 if( ( NULL != mImpl->mEventData ) &&
302 mImpl->mEventData->mDecorator )
304 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
310 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
312 mImpl->mMaximumNumberOfCharacters = maxCharacters;
315 int Controller::GetMaximumNumberOfCharacters()
317 return mImpl->mMaximumNumberOfCharacters;
320 void Controller::SetEnableCursorBlink( bool enable )
322 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
324 if( NULL != mImpl->mEventData )
326 mImpl->mEventData->mCursorBlinkEnabled = enable;
329 mImpl->mEventData->mDecorator )
331 mImpl->mEventData->mDecorator->StopCursorBlink();
336 bool Controller::GetEnableCursorBlink() const
338 if( NULL != mImpl->mEventData )
340 return mImpl->mEventData->mCursorBlinkEnabled;
346 void Controller::SetMultiLineEnabled( bool enable )
348 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
350 if( layout != mImpl->mLayoutEngine.GetLayout() )
352 // Set the layout type.
353 mImpl->mLayoutEngine.SetLayout( layout );
355 // Set the flags to redo the layout operations
356 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
361 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
362 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
364 mImpl->RequestRelayout();
368 bool Controller::IsMultiLineEnabled() const
370 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
373 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
375 if( alignment != mImpl->mModel->mHorizontalAlignment )
377 // Set the alignment.
378 mImpl->mModel->mHorizontalAlignment = alignment;
380 // Set the flag to redo the alignment operation.
381 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
383 mImpl->RequestRelayout();
387 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
389 return mImpl->mModel->mHorizontalAlignment;
392 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
394 if( alignment != mImpl->mModel->mVerticalAlignment )
396 // Set the alignment.
397 mImpl->mModel->mVerticalAlignment = alignment;
399 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
401 mImpl->RequestRelayout();
405 VerticalAlignment::Type Controller::GetVerticalAlignment() const
407 return mImpl->mModel->mVerticalAlignment;
410 bool Controller::IsIgnoreSpacesAfterText() const
412 return mImpl->mModel->mIgnoreSpacesAfterText;
415 void Controller::SetIgnoreSpacesAfterText( bool ignore )
417 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
420 bool Controller::IsMatchSystemLanguageDirection() const
422 return mImpl->mModel->mMatchSystemLanguageDirection;
425 void Controller::SetMatchSystemLanguageDirection( bool match )
427 mImpl->mModel->mMatchSystemLanguageDirection = match;
431 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
433 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
435 // Set the text wrap mode.
436 mImpl->mModel->mLineWrapMode = lineWrapMode;
439 // Update Text layout for applying wrap mode
440 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
445 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
446 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
447 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
450 mImpl->RequestRelayout();
454 Text::LineWrap::Mode Controller::GetLineWrapMode() const
456 return mImpl->mModel->mLineWrapMode;
459 void Controller::SetTextElideEnabled( bool enabled )
461 mImpl->mModel->mElideEnabled = enabled;
464 bool Controller::IsTextElideEnabled() const
466 return mImpl->mModel->mElideEnabled;
469 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
471 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
472 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
474 // Update placeholder if there is no text
475 if( mImpl->IsShowingPlaceholderText() ||
476 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
478 ShowPlaceholderText();
482 bool Controller::IsPlaceholderTextElideEnabled() const
484 return mImpl->mEventData->mIsPlaceholderElideEnabled;
487 void Controller::SetSelectionEnabled( bool enabled )
489 mImpl->mEventData->mSelectionEnabled = enabled;
492 bool Controller::IsSelectionEnabled() const
494 return mImpl->mEventData->mSelectionEnabled;
497 void Controller::SetShiftSelectionEnabled( bool enabled )
499 mImpl->mEventData->mShiftSelectionFlag = enabled;
502 bool Controller::IsShiftSelectionEnabled() const
504 return mImpl->mEventData->mShiftSelectionFlag;
507 void Controller::SetGrabHandleEnabled( bool enabled )
509 mImpl->mEventData->mGrabHandleEnabled = enabled;
512 bool Controller::IsGrabHandleEnabled() const
514 return mImpl->mEventData->mGrabHandleEnabled;
519 void Controller::SetText( const std::string& text )
521 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
523 // Reset keyboard as text changed
524 mImpl->ResetInputMethodContext();
526 // Remove the previously set text and style.
532 CharacterIndex lastCursorIndex = 0u;
534 if( NULL != mImpl->mEventData )
536 // If popup shown then hide it by switching to Editing state
537 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
538 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
539 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
540 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
542 mImpl->ChangeState( EventData::EDITING );
548 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
550 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
551 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
553 Length textSize = 0u;
554 const uint8_t* utf8 = NULL;
555 if( mImpl->mMarkupProcessorEnabled )
557 ProcessMarkupString( text, markupProcessData );
558 textSize = markupProcessData.markupProcessedText.size();
560 // This is a bit horrible but std::string returns a (signed) char*
561 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
565 textSize = text.size();
567 // This is a bit horrible but std::string returns a (signed) char*
568 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
571 // Convert text into UTF-32
572 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
573 utf32Characters.Resize( textSize );
575 // Transform a text array encoded in utf8 into an array encoded in utf32.
576 // It returns the actual number of characters.
577 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
578 utf32Characters.Resize( characterCount );
580 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
581 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
583 // The characters to be added.
584 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
586 // To reset the cursor position
587 lastCursorIndex = characterCount;
589 // Update the rest of the model during size negotiation
590 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
592 // The natural size needs to be re-calculated.
593 mImpl->mRecalculateNaturalSize = true;
595 // The text direction needs to be updated.
596 mImpl->mUpdateTextDirection = true;
598 // Apply modifications to the model
599 mImpl->mOperationsPending = ALL_OPERATIONS;
603 ShowPlaceholderText();
606 // Resets the cursor position.
607 ResetCursorPosition( lastCursorIndex );
609 // Scrolls the text to make the cursor visible.
610 ResetScrollPosition();
612 mImpl->RequestRelayout();
614 if( NULL != mImpl->mEventData )
616 // Cancel previously queued events
617 mImpl->mEventData->mEventQueue.clear();
620 // Do this last since it provides callbacks into application code.
621 if( NULL != mImpl->mEditableControlInterface )
623 mImpl->mEditableControlInterface->TextChanged();
627 void Controller::GetText( std::string& text ) const
629 if( !mImpl->IsShowingPlaceholderText() )
631 // Retrieves the text string.
632 mImpl->GetText( 0u, text );
636 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
640 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
642 if( NULL != mImpl->mEventData )
644 if( PLACEHOLDER_TYPE_INACTIVE == type )
646 mImpl->mEventData->mPlaceholderTextInactive = text;
650 mImpl->mEventData->mPlaceholderTextActive = text;
653 // Update placeholder if there is no text
654 if( mImpl->IsShowingPlaceholderText() ||
655 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
657 ShowPlaceholderText();
662 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
664 if( NULL != mImpl->mEventData )
666 if( PLACEHOLDER_TYPE_INACTIVE == type )
668 text = mImpl->mEventData->mPlaceholderTextInactive;
672 text = mImpl->mEventData->mPlaceholderTextActive;
677 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
679 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
681 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
683 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
684 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
688 mImpl->RequestRelayout();
692 // public : Default style & Input style
694 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
696 if( NULL == mImpl->mFontDefaults )
698 mImpl->mFontDefaults = new FontDefaults();
701 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
702 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
703 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
705 // Clear the font-specific data
708 mImpl->RequestRelayout();
711 const std::string& Controller::GetDefaultFontFamily() const
713 if( NULL != mImpl->mFontDefaults )
715 return mImpl->mFontDefaults->mFontDescription.family;
721 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
723 if( NULL != mImpl->mEventData )
725 if( NULL == mImpl->mEventData->mPlaceholderFont )
727 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
730 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
731 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
732 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
734 mImpl->RequestRelayout();
738 const std::string& Controller::GetPlaceholderFontFamily() const
740 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
742 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
748 void Controller::SetDefaultFontWeight( FontWeight weight )
750 if( NULL == mImpl->mFontDefaults )
752 mImpl->mFontDefaults = new FontDefaults();
755 mImpl->mFontDefaults->mFontDescription.weight = weight;
756 mImpl->mFontDefaults->weightDefined = true;
758 // Clear the font-specific data
761 mImpl->RequestRelayout();
764 bool Controller::IsDefaultFontWeightDefined() const
766 if( NULL != mImpl->mFontDefaults )
768 return mImpl->mFontDefaults->weightDefined;
774 FontWeight Controller::GetDefaultFontWeight() const
776 if( NULL != mImpl->mFontDefaults )
778 return mImpl->mFontDefaults->mFontDescription.weight;
781 return TextAbstraction::FontWeight::NORMAL;
784 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
786 if( NULL != mImpl->mEventData )
788 if( NULL == mImpl->mEventData->mPlaceholderFont )
790 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
793 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
794 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
796 mImpl->RequestRelayout();
800 bool Controller::IsPlaceholderTextFontWeightDefined() const
802 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
804 return mImpl->mEventData->mPlaceholderFont->weightDefined;
809 FontWeight Controller::GetPlaceholderTextFontWeight() const
811 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
813 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
816 return TextAbstraction::FontWeight::NORMAL;
819 void Controller::SetDefaultFontWidth( FontWidth width )
821 if( NULL == mImpl->mFontDefaults )
823 mImpl->mFontDefaults = new FontDefaults();
826 mImpl->mFontDefaults->mFontDescription.width = width;
827 mImpl->mFontDefaults->widthDefined = true;
829 // Clear the font-specific data
832 mImpl->RequestRelayout();
835 bool Controller::IsDefaultFontWidthDefined() const
837 if( NULL != mImpl->mFontDefaults )
839 return mImpl->mFontDefaults->widthDefined;
845 FontWidth Controller::GetDefaultFontWidth() const
847 if( NULL != mImpl->mFontDefaults )
849 return mImpl->mFontDefaults->mFontDescription.width;
852 return TextAbstraction::FontWidth::NORMAL;
855 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
857 if( NULL != mImpl->mEventData )
859 if( NULL == mImpl->mEventData->mPlaceholderFont )
861 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
864 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
865 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
867 mImpl->RequestRelayout();
871 bool Controller::IsPlaceholderTextFontWidthDefined() const
873 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
875 return mImpl->mEventData->mPlaceholderFont->widthDefined;
880 FontWidth Controller::GetPlaceholderTextFontWidth() const
882 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
884 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
887 return TextAbstraction::FontWidth::NORMAL;
890 void Controller::SetDefaultFontSlant( FontSlant slant )
892 if( NULL == mImpl->mFontDefaults )
894 mImpl->mFontDefaults = new FontDefaults();
897 mImpl->mFontDefaults->mFontDescription.slant = slant;
898 mImpl->mFontDefaults->slantDefined = true;
900 // Clear the font-specific data
903 mImpl->RequestRelayout();
906 bool Controller::IsDefaultFontSlantDefined() const
908 if( NULL != mImpl->mFontDefaults )
910 return mImpl->mFontDefaults->slantDefined;
915 FontSlant Controller::GetDefaultFontSlant() const
917 if( NULL != mImpl->mFontDefaults )
919 return mImpl->mFontDefaults->mFontDescription.slant;
922 return TextAbstraction::FontSlant::NORMAL;
925 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
927 if( NULL != mImpl->mEventData )
929 if( NULL == mImpl->mEventData->mPlaceholderFont )
931 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
934 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
935 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
937 mImpl->RequestRelayout();
941 bool Controller::IsPlaceholderTextFontSlantDefined() const
943 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
945 return mImpl->mEventData->mPlaceholderFont->slantDefined;
950 FontSlant Controller::GetPlaceholderTextFontSlant() const
952 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
954 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
957 return TextAbstraction::FontSlant::NORMAL;
960 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
962 if( NULL == mImpl->mFontDefaults )
964 mImpl->mFontDefaults = new FontDefaults();
971 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
972 mImpl->mFontDefaults->sizeDefined = true;
977 // Point size = Pixel size * 72.f / DPI
978 unsigned int horizontalDpi = 0u;
979 unsigned int verticalDpi = 0u;
980 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
981 fontClient.GetDpi( horizontalDpi, verticalDpi );
983 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
984 mImpl->mFontDefaults->sizeDefined = true;
989 // Clear the font-specific data
992 mImpl->RequestRelayout();
995 float Controller::GetDefaultFontSize( FontSizeType type ) const
998 if( NULL != mImpl->mFontDefaults )
1004 value = mImpl->mFontDefaults->mDefaultPointSize;
1009 // Pixel size = Point size * DPI / 72.f
1010 unsigned int horizontalDpi = 0u;
1011 unsigned int verticalDpi = 0u;
1012 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1013 fontClient.GetDpi( horizontalDpi, verticalDpi );
1015 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1025 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1027 if( NULL != mImpl->mEventData )
1029 if( NULL == mImpl->mEventData->mPlaceholderFont )
1031 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1038 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1039 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1040 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1045 // Point size = Pixel size * 72.f / DPI
1046 unsigned int horizontalDpi = 0u;
1047 unsigned int verticalDpi = 0u;
1048 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1049 fontClient.GetDpi( horizontalDpi, verticalDpi );
1051 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1052 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1053 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1058 mImpl->RequestRelayout();
1062 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1065 if( NULL != mImpl->mEventData )
1071 if( NULL != mImpl->mEventData->mPlaceholderFont )
1073 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1077 // If the placeholder text font size is not set, then return the default font size.
1078 value = GetDefaultFontSize( POINT_SIZE );
1084 if( NULL != mImpl->mEventData->mPlaceholderFont )
1086 // Pixel size = Point size * DPI / 72.f
1087 unsigned int horizontalDpi = 0u;
1088 unsigned int verticalDpi = 0u;
1089 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1090 fontClient.GetDpi( horizontalDpi, verticalDpi );
1092 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1096 // If the placeholder text font size is not set, then return the default font size.
1097 value = GetDefaultFontSize( PIXEL_SIZE );
1108 void Controller::SetDefaultColor( const Vector4& color )
1110 mImpl->mTextColor = color;
1112 if( !mImpl->IsShowingPlaceholderText() )
1114 mImpl->mModel->mVisualModel->SetTextColor( color );
1116 mImpl->RequestRelayout();
1120 const Vector4& Controller::GetDefaultColor() const
1122 return mImpl->mTextColor;
1125 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1127 if( NULL != mImpl->mEventData )
1129 mImpl->mEventData->mPlaceholderTextColor = textColor;
1132 if( mImpl->IsShowingPlaceholderText() )
1134 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1135 mImpl->RequestRelayout();
1139 const Vector4& Controller::GetPlaceholderTextColor() const
1141 if( NULL != mImpl->mEventData )
1143 return mImpl->mEventData->mPlaceholderTextColor;
1146 return Color::BLACK;
1149 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1151 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1153 mImpl->RequestRelayout();
1156 const Vector2& Controller::GetShadowOffset() const
1158 return mImpl->mModel->mVisualModel->GetShadowOffset();
1161 void Controller::SetShadowColor( const Vector4& shadowColor )
1163 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1165 mImpl->RequestRelayout();
1168 const Vector4& Controller::GetShadowColor() const
1170 return mImpl->mModel->mVisualModel->GetShadowColor();
1173 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1175 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1177 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1179 mImpl->RequestRelayout();
1183 const float& Controller::GetShadowBlurRadius() const
1185 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1188 void Controller::SetUnderlineColor( const Vector4& color )
1190 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1192 mImpl->RequestRelayout();
1195 const Vector4& Controller::GetUnderlineColor() const
1197 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1200 void Controller::SetUnderlineEnabled( bool enabled )
1202 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1204 mImpl->RequestRelayout();
1207 bool Controller::IsUnderlineEnabled() const
1209 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1212 void Controller::SetUnderlineHeight( float height )
1214 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1216 mImpl->RequestRelayout();
1219 float Controller::GetUnderlineHeight() const
1221 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1224 void Controller::SetOutlineColor( const Vector4& color )
1226 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1228 mImpl->RequestRelayout();
1231 const Vector4& Controller::GetOutlineColor() const
1233 return mImpl->mModel->mVisualModel->GetOutlineColor();
1236 void Controller::SetOutlineWidth( unsigned int width )
1238 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1240 mImpl->RequestRelayout();
1243 unsigned int Controller::GetOutlineWidth() const
1245 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1248 void Controller::SetBackgroundColor( const Vector4& color )
1250 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1252 mImpl->RequestRelayout();
1255 const Vector4& Controller::GetBackgroundColor() const
1257 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1260 void Controller::SetBackgroundEnabled( bool enabled )
1262 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1264 mImpl->RequestRelayout();
1267 bool Controller::IsBackgroundEnabled() const
1269 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1272 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1274 if( NULL == mImpl->mEmbossDefaults )
1276 mImpl->mEmbossDefaults = new EmbossDefaults();
1279 mImpl->mEmbossDefaults->properties = embossProperties;
1282 const std::string& Controller::GetDefaultEmbossProperties() const
1284 if( NULL != mImpl->mEmbossDefaults )
1286 return mImpl->mEmbossDefaults->properties;
1289 return EMPTY_STRING;
1292 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1294 if( NULL == mImpl->mOutlineDefaults )
1296 mImpl->mOutlineDefaults = new OutlineDefaults();
1299 mImpl->mOutlineDefaults->properties = outlineProperties;
1302 const std::string& Controller::GetDefaultOutlineProperties() const
1304 if( NULL != mImpl->mOutlineDefaults )
1306 return mImpl->mOutlineDefaults->properties;
1309 return EMPTY_STRING;
1312 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1314 if( std::abs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000 )
1316 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1317 mImpl->mRecalculateNaturalSize = true;
1323 float Controller::GetDefaultLineSpacing() const
1325 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1328 void Controller::SetInputColor( const Vector4& color )
1330 if( NULL != mImpl->mEventData )
1332 mImpl->mEventData->mInputStyle.textColor = color;
1333 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1335 if( EventData::SELECTING == mImpl->mEventData->mState )
1337 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1339 // Get start and end position of selection
1340 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1341 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1343 // Add the color run.
1344 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1345 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1347 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1348 colorRun.color = color;
1349 colorRun.characterRun.characterIndex = startOfSelectedText;
1350 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1352 // Request to relayout.
1353 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1354 mImpl->RequestRelayout();
1356 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1357 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1358 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1363 const Vector4& Controller::GetInputColor() const
1365 if( NULL != mImpl->mEventData )
1367 return mImpl->mEventData->mInputStyle.textColor;
1370 // Return the default text's color if there is no EventData.
1371 return mImpl->mTextColor;
1375 void Controller::SetInputFontFamily( const std::string& fontFamily )
1377 if( NULL != mImpl->mEventData )
1379 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1380 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1382 if( EventData::SELECTING == mImpl->mEventData->mState )
1384 CharacterIndex startOfSelectedText = 0u;
1385 Length lengthOfSelectedText = 0u;
1386 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1387 mImpl->mModel->mLogicalModel,
1388 startOfSelectedText,
1389 lengthOfSelectedText );
1391 fontDescriptionRun.familyLength = fontFamily.size();
1392 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1393 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1394 fontDescriptionRun.familyDefined = true;
1396 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1398 // Request to relayout.
1399 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1404 UPDATE_LAYOUT_SIZE |
1407 mImpl->mRecalculateNaturalSize = true;
1408 mImpl->RequestRelayout();
1410 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1411 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1412 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1414 // As the font changes, recalculate the handle positions is needed.
1415 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1416 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1417 mImpl->mEventData->mUpdateHighlightBox = true;
1418 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1423 const std::string& Controller::GetInputFontFamily() const
1425 if( NULL != mImpl->mEventData )
1427 return mImpl->mEventData->mInputStyle.familyName;
1430 // Return the default font's family if there is no EventData.
1431 return GetDefaultFontFamily();
1434 void Controller::SetInputFontWeight( FontWeight weight )
1436 if( NULL != mImpl->mEventData )
1438 mImpl->mEventData->mInputStyle.weight = weight;
1439 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1441 if( EventData::SELECTING == mImpl->mEventData->mState )
1443 CharacterIndex startOfSelectedText = 0u;
1444 Length lengthOfSelectedText = 0u;
1445 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1446 mImpl->mModel->mLogicalModel,
1447 startOfSelectedText,
1448 lengthOfSelectedText );
1450 fontDescriptionRun.weight = weight;
1451 fontDescriptionRun.weightDefined = true;
1453 // Request to relayout.
1454 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1459 UPDATE_LAYOUT_SIZE |
1462 mImpl->mRecalculateNaturalSize = true;
1463 mImpl->RequestRelayout();
1465 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1466 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1467 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1469 // As the font might change, recalculate the handle positions is needed.
1470 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1471 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1472 mImpl->mEventData->mUpdateHighlightBox = true;
1473 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1478 bool Controller::IsInputFontWeightDefined() const
1480 bool defined = false;
1482 if( NULL != mImpl->mEventData )
1484 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1490 FontWeight Controller::GetInputFontWeight() const
1492 if( NULL != mImpl->mEventData )
1494 return mImpl->mEventData->mInputStyle.weight;
1497 return GetDefaultFontWeight();
1500 void Controller::SetInputFontWidth( FontWidth width )
1502 if( NULL != mImpl->mEventData )
1504 mImpl->mEventData->mInputStyle.width = width;
1505 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1507 if( EventData::SELECTING == mImpl->mEventData->mState )
1509 CharacterIndex startOfSelectedText = 0u;
1510 Length lengthOfSelectedText = 0u;
1511 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1512 mImpl->mModel->mLogicalModel,
1513 startOfSelectedText,
1514 lengthOfSelectedText );
1516 fontDescriptionRun.width = width;
1517 fontDescriptionRun.widthDefined = true;
1519 // Request to relayout.
1520 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1525 UPDATE_LAYOUT_SIZE |
1528 mImpl->mRecalculateNaturalSize = true;
1529 mImpl->RequestRelayout();
1531 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1532 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1533 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1535 // As the font might change, recalculate the handle positions is needed.
1536 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1537 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1538 mImpl->mEventData->mUpdateHighlightBox = true;
1539 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1544 bool Controller::IsInputFontWidthDefined() const
1546 bool defined = false;
1548 if( NULL != mImpl->mEventData )
1550 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1556 FontWidth Controller::GetInputFontWidth() const
1558 if( NULL != mImpl->mEventData )
1560 return mImpl->mEventData->mInputStyle.width;
1563 return GetDefaultFontWidth();
1566 void Controller::SetInputFontSlant( FontSlant slant )
1568 if( NULL != mImpl->mEventData )
1570 mImpl->mEventData->mInputStyle.slant = slant;
1571 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1573 if( EventData::SELECTING == mImpl->mEventData->mState )
1575 CharacterIndex startOfSelectedText = 0u;
1576 Length lengthOfSelectedText = 0u;
1577 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1578 mImpl->mModel->mLogicalModel,
1579 startOfSelectedText,
1580 lengthOfSelectedText );
1582 fontDescriptionRun.slant = slant;
1583 fontDescriptionRun.slantDefined = true;
1585 // Request to relayout.
1586 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1591 UPDATE_LAYOUT_SIZE |
1594 mImpl->mRecalculateNaturalSize = true;
1595 mImpl->RequestRelayout();
1597 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1598 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1599 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1601 // As the font might change, recalculate the handle positions is needed.
1602 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1603 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1604 mImpl->mEventData->mUpdateHighlightBox = true;
1605 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1610 bool Controller::IsInputFontSlantDefined() const
1612 bool defined = false;
1614 if( NULL != mImpl->mEventData )
1616 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1622 FontSlant Controller::GetInputFontSlant() const
1624 if( NULL != mImpl->mEventData )
1626 return mImpl->mEventData->mInputStyle.slant;
1629 return GetDefaultFontSlant();
1632 void Controller::SetInputFontPointSize( float size )
1634 if( NULL != mImpl->mEventData )
1636 mImpl->mEventData->mInputStyle.size = size;
1637 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1639 if( EventData::SELECTING == mImpl->mEventData->mState )
1641 CharacterIndex startOfSelectedText = 0u;
1642 Length lengthOfSelectedText = 0u;
1643 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1644 mImpl->mModel->mLogicalModel,
1645 startOfSelectedText,
1646 lengthOfSelectedText );
1648 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1649 fontDescriptionRun.sizeDefined = true;
1651 // Request to relayout.
1652 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1657 UPDATE_LAYOUT_SIZE |
1660 mImpl->mRecalculateNaturalSize = true;
1661 mImpl->RequestRelayout();
1663 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1664 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1665 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1667 // As the font might change, recalculate the handle positions is needed.
1668 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1669 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1670 mImpl->mEventData->mUpdateHighlightBox = true;
1671 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1676 float Controller::GetInputFontPointSize() const
1678 if( NULL != mImpl->mEventData )
1680 return mImpl->mEventData->mInputStyle.size;
1683 // Return the default font's point size if there is no EventData.
1684 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1687 void Controller::SetInputLineSpacing( float lineSpacing )
1689 if( NULL != mImpl->mEventData )
1691 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1692 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1696 float Controller::GetInputLineSpacing() const
1698 if( NULL != mImpl->mEventData )
1700 return mImpl->mEventData->mInputStyle.lineSpacing;
1706 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1708 if( NULL != mImpl->mEventData )
1710 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1714 const std::string& Controller::GetInputShadowProperties() const
1716 if( NULL != mImpl->mEventData )
1718 return mImpl->mEventData->mInputStyle.shadowProperties;
1721 return EMPTY_STRING;
1724 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1726 if( NULL != mImpl->mEventData )
1728 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1732 const std::string& Controller::GetInputUnderlineProperties() const
1734 if( NULL != mImpl->mEventData )
1736 return mImpl->mEventData->mInputStyle.underlineProperties;
1739 return EMPTY_STRING;
1742 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1744 if( NULL != mImpl->mEventData )
1746 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1750 const std::string& Controller::GetInputEmbossProperties() const
1752 if( NULL != mImpl->mEventData )
1754 return mImpl->mEventData->mInputStyle.embossProperties;
1757 return GetDefaultEmbossProperties();
1760 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1762 if( NULL != mImpl->mEventData )
1764 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1768 const std::string& Controller::GetInputOutlineProperties() const
1770 if( NULL != mImpl->mEventData )
1772 return mImpl->mEventData->mInputStyle.outlineProperties;
1775 return GetDefaultOutlineProperties();
1778 void Controller::SetInputModePassword( bool passwordInput )
1780 if( NULL != mImpl->mEventData )
1782 mImpl->mEventData->mPasswordInput = passwordInput;
1786 bool Controller::IsInputModePassword()
1788 if( NULL != mImpl->mEventData )
1790 return mImpl->mEventData->mPasswordInput;
1795 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1797 if( NULL != mImpl->mEventData )
1799 mImpl->mEventData->mDoubleTapAction = action;
1803 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1805 NoTextTap::Action action = NoTextTap::NO_ACTION;
1807 if( NULL != mImpl->mEventData )
1809 action = mImpl->mEventData->mDoubleTapAction;
1815 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1817 if( NULL != mImpl->mEventData )
1819 mImpl->mEventData->mLongPressAction = action;
1823 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1825 NoTextTap::Action action = NoTextTap::NO_ACTION;
1827 if( NULL != mImpl->mEventData )
1829 action = mImpl->mEventData->mLongPressAction;
1835 bool Controller::IsUnderlineSetByString()
1837 return mImpl->mUnderlineSetByString;
1840 void Controller::UnderlineSetByString( bool setByString )
1842 mImpl->mUnderlineSetByString = setByString;
1845 bool Controller::IsShadowSetByString()
1847 return mImpl->mShadowSetByString;
1850 void Controller::ShadowSetByString( bool setByString )
1852 mImpl->mShadowSetByString = setByString;
1855 bool Controller::IsOutlineSetByString()
1857 return mImpl->mOutlineSetByString;
1860 void Controller::OutlineSetByString( bool setByString )
1862 mImpl->mOutlineSetByString = setByString;
1865 bool Controller::IsFontStyleSetByString()
1867 return mImpl->mFontStyleSetByString;
1870 void Controller::FontStyleSetByString( bool setByString )
1872 mImpl->mFontStyleSetByString = setByString;
1875 // public : Queries & retrieves.
1877 Layout::Engine& Controller::GetLayoutEngine()
1879 return mImpl->mLayoutEngine;
1882 View& Controller::GetView()
1884 return mImpl->mView;
1887 Vector3 Controller::GetNaturalSize()
1889 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1890 Vector3 naturalSize;
1892 // Make sure the model is up-to-date before layouting
1893 ProcessModifyEvents();
1895 if( mImpl->mRecalculateNaturalSize )
1897 // Operations that can be done only once until the text changes.
1898 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1905 GET_GLYPH_METRICS );
1907 // Set the update info to relayout the whole text.
1908 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1909 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1911 // Make sure the model is up-to-date before layouting
1912 mImpl->UpdateModel( onlyOnceOperations );
1914 // Layout the text for the new width.
1915 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1917 // Store the actual control's size to restore later.
1918 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1920 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1921 static_cast<OperationsMask>( onlyOnceOperations |
1923 naturalSize.GetVectorXY() );
1925 // Do not do again the only once operations.
1926 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1928 // Do the size related operations again.
1929 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1932 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1934 // Stores the natural size to avoid recalculate it again
1935 // unless the text/style changes.
1936 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1938 mImpl->mRecalculateNaturalSize = false;
1940 // Clear the update info. This info will be set the next time the text is updated.
1941 mImpl->mTextUpdateInfo.Clear();
1942 mImpl->mTextUpdateInfo.mClearAll = true;
1944 // Restore the actual control's size.
1945 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1947 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1951 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1953 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1956 naturalSize.x = ConvertToEven( naturalSize.x );
1957 naturalSize.y = ConvertToEven( naturalSize.y );
1962 float Controller::GetHeightForWidth( float width )
1964 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1965 // Make sure the model is up-to-date before layouting
1966 ProcessModifyEvents();
1969 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1970 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1971 mImpl->mTextUpdateInfo.mClearAll )
1973 // Operations that can be done only once until the text changes.
1974 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1981 GET_GLYPH_METRICS );
1983 // Set the update info to relayout the whole text.
1984 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1985 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1987 // Make sure the model is up-to-date before layouting
1988 mImpl->UpdateModel( onlyOnceOperations );
1991 // Layout the text for the new width.
1992 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1994 // Store the actual control's width.
1995 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1997 DoRelayout( Size( width, MAX_FLOAT ),
1998 static_cast<OperationsMask>( onlyOnceOperations |
2002 // Do not do again the only once operations.
2003 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2005 // Do the size related operations again.
2006 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2010 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2012 // Clear the update info. This info will be set the next time the text is updated.
2013 mImpl->mTextUpdateInfo.Clear();
2014 mImpl->mTextUpdateInfo.mClearAll = true;
2016 // Restore the actual control's width.
2017 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2019 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2023 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2024 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2027 return layoutSize.height;
2030 int Controller::GetLineCount( float width )
2032 GetHeightForWidth( width );
2033 int numberofLines = mImpl->mModel->GetNumberOfLines();
2034 return numberofLines;
2037 const ModelInterface* const Controller::GetTextModel() const
2039 return mImpl->mModel.Get();
2042 float Controller::GetScrollAmountByUserInput()
2044 float scrollAmount = 0.0f;
2046 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2048 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2049 mImpl->mEventData->mCheckScrollAmount = false;
2051 return scrollAmount;
2054 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2056 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2059 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2060 layoutHeight = layout.height;
2061 scrollPosition = mImpl->mModel->mScrollPosition.y;
2062 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2066 void Controller::SetHiddenInputOption(const Property::Map& options )
2068 if( NULL == mImpl->mHiddenInput )
2070 mImpl->mHiddenInput = new HiddenText( this );
2072 mImpl->mHiddenInput->SetProperties(options);
2075 void Controller::GetHiddenInputOption(Property::Map& options )
2077 if( NULL != mImpl->mHiddenInput )
2079 mImpl->mHiddenInput->GetProperties(options);
2083 void Controller::SetPlaceholderProperty( const Property::Map& map )
2085 const Property::Map::SizeType count = map.Count();
2087 for( Property::Map::SizeType position = 0; position < count; ++position )
2089 KeyValuePair keyValue = map.GetKeyValue( position );
2090 Property::Key& key = keyValue.first;
2091 Property::Value& value = keyValue.second;
2093 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2095 std::string text = "";
2097 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2099 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2101 std::string text = "";
2103 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2105 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2108 value.Get( textColor );
2109 if( GetPlaceholderTextColor() != textColor )
2111 SetPlaceholderTextColor( textColor );
2114 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2116 std::string fontFamily = "";
2117 value.Get( fontFamily );
2118 SetPlaceholderFontFamily( fontFamily );
2120 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2122 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2124 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2127 value.Get( pointSize );
2128 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2130 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2133 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2136 value.Get( pixelSize );
2137 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2139 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2142 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2145 value.Get( ellipsis );
2146 SetPlaceholderTextElideEnabled( ellipsis );
2151 void Controller::GetPlaceholderProperty( Property::Map& map )
2153 if( NULL != mImpl->mEventData )
2155 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2157 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2159 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2161 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2164 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2165 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2167 Property::Value fontStyleMapGet;
2168 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2169 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2171 // Choose font size : POINT_SIZE or PIXEL_SIZE
2172 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2174 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2178 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2181 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2183 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2188 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2190 // Make sure the model is up-to-date before layouting
2191 ProcessModifyEvents();
2193 if ( mImpl->mUpdateTextDirection )
2195 // Operations that can be done only once until the text changes.
2196 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2203 GET_GLYPH_METRICS );
2205 // Set the update info to relayout the whole text.
2206 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2207 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2209 // Make sure the model is up-to-date before layouting
2210 mImpl->UpdateModel( onlyOnceOperations );
2212 Vector3 naturalSize;
2213 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2214 static_cast<OperationsMask>( onlyOnceOperations |
2215 LAYOUT | REORDER | UPDATE_DIRECTION ),
2216 naturalSize.GetVectorXY() );
2218 // Do not do again the only once operations.
2219 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2221 // Clear the update info. This info will be set the next time the text is updated.
2222 mImpl->mTextUpdateInfo.Clear();
2224 mImpl->mUpdateTextDirection = false;
2227 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2230 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2232 return mImpl->mModel->GetVerticalLineAlignment();
2235 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2237 mImpl->mModel->mVerticalLineAlignment = alignment;
2240 // public : Relayout.
2242 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2244 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2246 UpdateTextType updateTextType = NONE_UPDATED;
2248 mImpl->mLayoutDirection = layoutDirection;
2249 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2251 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2253 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2254 updateTextType = MODEL_UPDATED;
2257 // Clear the update info. This info will be set the next time the text is updated.
2258 mImpl->mTextUpdateInfo.Clear();
2260 // Not worth to relayout if width or height is equal to zero.
2261 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2263 return updateTextType;
2266 // Whether a new size has been set.
2267 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2271 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2273 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2274 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2275 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2277 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2280 // Layout operations that need to be done if the size changes.
2281 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2284 UPDATE_LAYOUT_SIZE |
2286 // Set the update info to relayout the whole text.
2287 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2288 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2290 // Store the size used to layout the text.
2291 mImpl->mModel->mVisualModel->mControlSize = size;
2294 // Whether there are modify events.
2295 if( 0u != mImpl->mModifyEvents.Count() )
2297 // Style operations that need to be done if the text is modified.
2298 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2302 // Set the update info to elide the text.
2303 if( mImpl->mModel->mElideEnabled ||
2304 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2306 // Update Text layout for applying elided
2307 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2310 UPDATE_LAYOUT_SIZE |
2312 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2313 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2316 // Make sure the model is up-to-date before layouting.
2317 ProcessModifyEvents();
2318 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2322 updated = DoRelayout( size,
2323 mImpl->mOperationsPending,
2324 layoutSize ) || updated;
2328 updateTextType = MODEL_UPDATED;
2331 // Do not re-do any operation until something changes.
2332 mImpl->mOperationsPending = NO_OPERATION;
2333 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2335 // Whether the text control is editable
2336 const bool isEditable = NULL != mImpl->mEventData;
2338 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2340 if( newSize && isEditable )
2342 offset = mImpl->mModel->mScrollPosition;
2345 if( !isEditable || !IsMultiLineEnabled() )
2347 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2348 CalculateVerticalOffset( size );
2355 // If there is a new size, the scroll position needs to be clamped.
2356 mImpl->ClampHorizontalScroll( layoutSize );
2358 // Update the decorator's positions is needed if there is a new size.
2359 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2362 // Move the cursor, grab handle etc.
2363 if( mImpl->ProcessInputEvents() )
2365 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2369 // Clear the update info. This info will be set the next time the text is updated.
2370 mImpl->mTextUpdateInfo.Clear();
2371 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2373 return updateTextType;
2376 void Controller::RequestRelayout()
2378 mImpl->RequestRelayout();
2381 // public : Input style change signals.
2383 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2385 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2388 void Controller::ProcessInputStyleChangedSignals()
2390 if( NULL == mImpl->mEventData )
2396 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2397 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2401 const InputStyle::Mask mask = *it;
2403 if( NULL != mImpl->mEditableControlInterface )
2405 // Emit the input style changed signal.
2406 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2410 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2413 // public : Text-input Event Queuing.
2415 void Controller::KeyboardFocusGainEvent()
2417 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2419 if( NULL != mImpl->mEventData )
2421 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2422 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2424 mImpl->ChangeState( EventData::EDITING );
2425 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2426 mImpl->mEventData->mUpdateInputStyle = true;
2428 mImpl->NotifyInputMethodContextMultiLineStatus();
2429 if( mImpl->IsShowingPlaceholderText() )
2431 // Show alternative placeholder-text when editing
2432 ShowPlaceholderText();
2435 mImpl->RequestRelayout();
2439 void Controller::KeyboardFocusLostEvent()
2441 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2443 if( NULL != mImpl->mEventData )
2445 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2447 mImpl->ChangeState( EventData::INACTIVE );
2449 if( !mImpl->IsShowingRealText() )
2451 // Revert to regular placeholder-text when not editing
2452 ShowPlaceholderText();
2456 mImpl->RequestRelayout();
2459 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2461 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2463 bool textChanged = false;
2464 bool relayoutNeeded = false;
2466 if( ( NULL != mImpl->mEventData ) &&
2467 ( keyEvent.state == KeyEvent::Down ) )
2469 int keyCode = keyEvent.keyCode;
2470 const std::string& keyString = keyEvent.keyPressed;
2471 const std::string keyName = keyEvent.keyPressedName;
2473 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2475 // Pre-process to separate modifying events from non-modifying input events.
2478 // In some platforms arrive key events with no key code.
2482 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2487 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2488 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2489 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2490 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2492 // If don't have any text, do nothing.
2493 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2498 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2499 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2500 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2501 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2503 // Logic to determine whether this text control will lose focus or not.
2504 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2505 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2506 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2507 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2508 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2509 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2511 // Release the active highlight.
2512 if( mImpl->mEventData->mState == EventData::SELECTING )
2514 mImpl->ChangeState( EventData::EDITING );
2516 // Update selection position.
2517 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2518 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2519 mImpl->mEventData->mUpdateCursorPosition = true;
2520 mImpl->RequestRelayout();
2525 mImpl->mEventData->mCheckScrollAmount = true;
2526 Event event( Event::CURSOR_KEY_EVENT );
2527 event.p1.mInt = keyCode;
2528 event.p2.mBool = keyEvent.IsShiftModifier();
2529 mImpl->mEventData->mEventQueue.push_back( event );
2531 // Will request for relayout.
2532 relayoutNeeded = true;
2534 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2536 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2537 // If not handle it here, any selected text will be deleted
2542 else if ( keyEvent.IsCtrlModifier() )
2544 bool consumed = false;
2545 if (keyName == KEY_C_NAME)
2547 // Ctrl-C to copy the selected text
2548 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2551 else if (keyName == KEY_V_NAME)
2553 // Ctrl-V to paste the copied text
2554 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2557 else if (keyName == KEY_X_NAME)
2559 // Ctrl-X to cut the selected text
2560 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2565 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2566 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2568 textChanged = DeleteEvent( keyCode );
2570 // Will request for relayout.
2571 relayoutNeeded = true;
2573 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2574 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2575 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2577 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2578 mImpl->ChangeState( EventData::INACTIVE );
2580 // Will request for relayout.
2581 relayoutNeeded = true;
2583 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2585 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2587 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the InputMethodContext?) when the predictive text is enabled
2588 // and a character is typed after the type of a upper case latin character.
2593 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2595 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2601 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2603 // InputMethodContext is no longer handling key-events
2604 mImpl->ClearPreEditFlag();
2606 InsertText( keyString, COMMIT );
2609 // Will request for relayout.
2610 relayoutNeeded = true;
2613 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2614 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2616 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2617 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2618 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2620 // Should not change the state if the key is the shift send by the InputMethodContext.
2621 // Otherwise, when the state is SELECTING the text controller can't send the right
2622 // surrounding info to the InputMethodContext.
2623 mImpl->ChangeState( EventData::EDITING );
2625 // Will request for relayout.
2626 relayoutNeeded = true;
2629 if( relayoutNeeded )
2631 mImpl->RequestRelayout();
2636 ( NULL != mImpl->mEditableControlInterface ) )
2638 // Do this last since it provides callbacks into application code
2639 mImpl->mEditableControlInterface->TextChanged();
2645 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2647 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2649 if( NULL != mImpl->mEventData )
2651 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2652 EventData::State state( mImpl->mEventData->mState );
2653 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2655 if( mImpl->IsClipboardVisible() )
2657 if( EventData::INACTIVE == state || EventData::EDITING == state)
2659 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2661 relayoutNeeded = true;
2663 else if( 1u == tapCount )
2665 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2667 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2670 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2672 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2673 relayoutNeeded = true;
2677 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2679 // Hide placeholder text
2683 if( EventData::INACTIVE == state )
2685 mImpl->ChangeState( EventData::EDITING );
2687 else if( !mImpl->IsClipboardEmpty() )
2689 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2691 relayoutNeeded = true;
2694 else if( 2u == tapCount )
2696 if( mImpl->mEventData->mSelectionEnabled &&
2697 mImpl->IsShowingRealText() )
2699 relayoutNeeded = true;
2700 mImpl->mEventData->mIsLeftHandleSelected = true;
2701 mImpl->mEventData->mIsRightHandleSelected = true;
2705 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2706 if( relayoutNeeded )
2708 Event event( Event::TAP_EVENT );
2709 event.p1.mUint = tapCount;
2710 event.p2.mFloat = x;
2711 event.p3.mFloat = y;
2712 mImpl->mEventData->mEventQueue.push_back( event );
2714 mImpl->RequestRelayout();
2718 // Reset keyboard as tap event has occurred.
2719 mImpl->ResetInputMethodContext();
2722 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2724 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2726 if( NULL != mImpl->mEventData )
2728 Event event( Event::PAN_EVENT );
2729 event.p1.mInt = state;
2730 event.p2.mFloat = displacement.x;
2731 event.p3.mFloat = displacement.y;
2732 mImpl->mEventData->mEventQueue.push_back( event );
2734 mImpl->RequestRelayout();
2738 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2740 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2742 if( ( state == Gesture::Started ) &&
2743 ( NULL != mImpl->mEventData ) )
2745 // The 1st long-press on inactive text-field is treated as tap
2746 if( EventData::INACTIVE == mImpl->mEventData->mState )
2748 mImpl->ChangeState( EventData::EDITING );
2750 Event event( Event::TAP_EVENT );
2752 event.p2.mFloat = x;
2753 event.p3.mFloat = y;
2754 mImpl->mEventData->mEventQueue.push_back( event );
2756 mImpl->RequestRelayout();
2758 else if( !mImpl->IsShowingRealText() )
2760 Event event( Event::LONG_PRESS_EVENT );
2761 event.p1.mInt = state;
2762 event.p2.mFloat = x;
2763 event.p3.mFloat = y;
2764 mImpl->mEventData->mEventQueue.push_back( event );
2765 mImpl->RequestRelayout();
2767 else if( !mImpl->IsClipboardVisible() )
2769 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
2770 mImpl->ResetInputMethodContext();
2772 Event event( Event::LONG_PRESS_EVENT );
2773 event.p1.mInt = state;
2774 event.p2.mFloat = x;
2775 event.p3.mFloat = y;
2776 mImpl->mEventData->mEventQueue.push_back( event );
2777 mImpl->RequestRelayout();
2779 mImpl->mEventData->mIsLeftHandleSelected = true;
2780 mImpl->mEventData->mIsRightHandleSelected = true;
2785 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
2787 // Whether the text needs to be relaid-out.
2788 bool requestRelayout = false;
2790 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
2791 bool retrieveText = false;
2792 bool retrieveCursor = false;
2794 switch( inputMethodContextEvent.eventName )
2796 case InputMethodContext::COMMIT:
2798 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
2799 requestRelayout = true;
2800 retrieveCursor = true;
2803 case InputMethodContext::PRE_EDIT:
2805 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
2806 requestRelayout = true;
2807 retrieveCursor = true;
2810 case InputMethodContext::DELETE_SURROUNDING:
2812 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
2813 inputMethodContextEvent.numberOfChars,
2814 DONT_UPDATE_INPUT_STYLE );
2818 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2819 !mImpl->IsPlaceholderAvailable() )
2821 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2825 ShowPlaceholderText();
2827 mImpl->mEventData->mUpdateCursorPosition = true;
2828 mImpl->mEventData->mScrollAfterDelete = true;
2830 requestRelayout = true;
2834 case InputMethodContext::GET_SURROUNDING:
2836 retrieveText = true;
2837 retrieveCursor = true;
2840 case InputMethodContext::PRIVATE_COMMAND:
2842 // PRIVATECOMMAND event is just for getting the private command message
2843 retrieveText = true;
2844 retrieveCursor = true;
2847 case InputMethodContext::VOID:
2854 if( requestRelayout )
2856 mImpl->mOperationsPending = ALL_OPERATIONS;
2857 mImpl->RequestRelayout();
2861 CharacterIndex cursorPosition = 0u;
2862 Length numberOfWhiteSpaces = 0u;
2864 if( retrieveCursor )
2866 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2868 cursorPosition = mImpl->GetLogicalCursorPosition();
2870 if( cursorPosition < numberOfWhiteSpaces )
2872 cursorPosition = 0u;
2876 cursorPosition -= numberOfWhiteSpaces;
2882 if( !mImpl->IsShowingPlaceholderText() )
2884 // Retrieves the normal text string.
2885 mImpl->GetText( numberOfWhiteSpaces, text );
2889 // When the current text is Placeholder Text, the surrounding text should be empty string.
2890 // It means DALi should send empty string ("") to IME.
2895 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2897 if( requestRelayout &&
2898 ( NULL != mImpl->mEditableControlInterface ) )
2900 // Do this last since it provides callbacks into application code
2901 mImpl->mEditableControlInterface->TextChanged();
2904 return callbackData;
2907 void Controller::PasteClipboardItemEvent()
2909 // Retrieve the clipboard contents first
2910 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2911 std::string stringToPaste( notifier.GetContent() );
2913 // Commit the current pre-edit text; the contents of the clipboard should be appended
2914 mImpl->ResetInputMethodContext();
2916 // Temporary disable hiding clipboard
2917 mImpl->SetClipboardHideEnable( false );
2920 PasteText( stringToPaste );
2922 mImpl->SetClipboardHideEnable( true );
2925 // protected : Inherit from Text::Decorator::ControllerInterface.
2927 void Controller::GetTargetSize( Vector2& targetSize )
2929 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2932 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2934 if( NULL != mImpl->mEditableControlInterface )
2936 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2940 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2942 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2944 if( NULL != mImpl->mEventData )
2946 switch( handleType )
2950 Event event( Event::GRAB_HANDLE_EVENT );
2951 event.p1.mUint = state;
2952 event.p2.mFloat = x;
2953 event.p3.mFloat = y;
2955 mImpl->mEventData->mEventQueue.push_back( event );
2958 case LEFT_SELECTION_HANDLE:
2960 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2961 event.p1.mUint = state;
2962 event.p2.mFloat = x;
2963 event.p3.mFloat = y;
2965 mImpl->mEventData->mEventQueue.push_back( event );
2968 case RIGHT_SELECTION_HANDLE:
2970 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2971 event.p1.mUint = state;
2972 event.p2.mFloat = x;
2973 event.p3.mFloat = y;
2975 mImpl->mEventData->mEventQueue.push_back( event );
2978 case LEFT_SELECTION_HANDLE_MARKER:
2979 case RIGHT_SELECTION_HANDLE_MARKER:
2981 // Markers do not move the handles.
2984 case HANDLE_TYPE_COUNT:
2986 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2990 mImpl->RequestRelayout();
2994 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2996 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2998 if( NULL == mImpl->mEventData )
3005 case Toolkit::TextSelectionPopup::CUT:
3007 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3008 mImpl->mOperationsPending = ALL_OPERATIONS;
3010 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3011 !mImpl->IsPlaceholderAvailable() )
3013 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3017 ShowPlaceholderText();
3020 mImpl->mEventData->mUpdateCursorPosition = true;
3021 mImpl->mEventData->mScrollAfterDelete = true;
3023 mImpl->RequestRelayout();
3025 if( NULL != mImpl->mEditableControlInterface )
3027 mImpl->mEditableControlInterface->TextChanged();
3031 case Toolkit::TextSelectionPopup::COPY:
3033 mImpl->SendSelectionToClipboard( false ); // Text not modified
3035 mImpl->mEventData->mUpdateCursorPosition = true;
3037 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3040 case Toolkit::TextSelectionPopup::PASTE:
3042 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3045 case Toolkit::TextSelectionPopup::SELECT:
3047 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3049 if( mImpl->mEventData->mSelectionEnabled )
3051 // Creates a SELECT event.
3052 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3056 case Toolkit::TextSelectionPopup::SELECT_ALL:
3058 // Creates a SELECT_ALL event
3059 SelectEvent( 0.f, 0.f, true );
3062 case Toolkit::TextSelectionPopup::CLIPBOARD:
3064 mImpl->ShowClipboard();
3067 case Toolkit::TextSelectionPopup::NONE:
3075 void Controller::DisplayTimeExpired()
3077 mImpl->mEventData->mUpdateCursorPosition = true;
3078 // Apply modifications to the model
3079 mImpl->mOperationsPending = ALL_OPERATIONS;
3081 mImpl->RequestRelayout();
3084 // private : Update.
3086 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3088 bool removedPrevious = false;
3089 bool removedSelected = false;
3090 bool maxLengthReached = false;
3092 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3094 if( NULL == mImpl->mEventData )
3099 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3100 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3101 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3103 // TODO: At the moment the underline runs are only for pre-edit.
3104 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3106 // Remove the previous InputMethodContext pre-edit.
3107 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3109 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3110 mImpl->mEventData->mPreEditLength,
3111 DONT_UPDATE_INPUT_STYLE );
3113 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3114 mImpl->mEventData->mPreEditLength = 0u;
3118 // Remove the previous Selection.
3119 removedSelected = RemoveSelectedText();
3123 Vector<Character> utf32Characters;
3124 Length characterCount = 0u;
3128 // Convert text into UTF-32
3129 utf32Characters.Resize( text.size() );
3131 // This is a bit horrible but std::string returns a (signed) char*
3132 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3134 // Transform a text array encoded in utf8 into an array encoded in utf32.
3135 // It returns the actual number of characters.
3136 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3137 utf32Characters.Resize( characterCount );
3139 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3140 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3143 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3145 // The placeholder text is no longer needed
3146 if( mImpl->IsShowingPlaceholderText() )
3151 mImpl->ChangeState( EventData::EDITING );
3153 // Handle the InputMethodContext (predicitive text) state changes
3154 if( COMMIT == type )
3156 // InputMethodContext is no longer handling key-events
3157 mImpl->ClearPreEditFlag();
3161 if( !mImpl->mEventData->mPreEditFlag )
3163 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3165 // Record the start of the pre-edit text
3166 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3169 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3170 mImpl->mEventData->mPreEditFlag = true;
3172 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3175 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3177 // Restrict new text to fit within Maximum characters setting.
3178 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3179 maxLengthReached = ( characterCount > maxSizeOfNewText );
3181 // The cursor position.
3182 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3184 // Update the text's style.
3186 // Updates the text style runs by adding characters.
3187 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3189 // Get the character index from the cursor index.
3190 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3192 // Retrieve the text's style for the given index.
3194 mImpl->RetrieveDefaultInputStyle( style );
3195 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3197 // Whether to add a new text color run.
3198 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3200 // Whether to add a new font run.
3201 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3202 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3203 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3204 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3205 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3210 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3211 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3213 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3214 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3215 colorRun.characterRun.characterIndex = cursorIndex;
3216 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3219 if( addFontNameRun ||
3225 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3226 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3228 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3230 if( addFontNameRun )
3232 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3233 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3234 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3235 fontDescriptionRun.familyDefined = true;
3237 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3240 if( addFontWeightRun )
3242 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3243 fontDescriptionRun.weightDefined = true;
3246 if( addFontWidthRun )
3248 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3249 fontDescriptionRun.widthDefined = true;
3252 if( addFontSlantRun )
3254 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3255 fontDescriptionRun.slantDefined = true;
3258 if( addFontSizeRun )
3260 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3261 fontDescriptionRun.sizeDefined = true;
3264 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3265 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3268 // Insert at current cursor position.
3269 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3271 if( cursorIndex < numberOfCharactersInModel )
3273 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3277 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3280 // Mark the first paragraph to be updated.
3281 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3283 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3284 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3285 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3286 mImpl->mTextUpdateInfo.mClearAll = true;
3290 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3291 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3294 // Update the cursor index.
3295 cursorIndex += maxSizeOfNewText;
3297 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 );
3300 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3301 mImpl->IsPlaceholderAvailable() )
3303 // Show place-holder if empty after removing the pre-edit text
3304 ShowPlaceholderText();
3305 mImpl->mEventData->mUpdateCursorPosition = true;
3306 mImpl->ClearPreEditFlag();
3308 else if( removedPrevious ||
3310 ( 0 != utf32Characters.Count() ) )
3312 // Queue an inserted event
3313 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3315 mImpl->mEventData->mUpdateCursorPosition = true;
3316 if( removedSelected )
3318 mImpl->mEventData->mScrollAfterDelete = true;
3322 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3326 if( maxLengthReached )
3328 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3330 mImpl->ResetInputMethodContext();
3332 if( NULL != mImpl->mEditableControlInterface )
3334 // Do this last since it provides callbacks into application code
3335 mImpl->mEditableControlInterface->MaxLengthReached();
3340 void Controller::PasteText( const std::string& stringToPaste )
3342 InsertText( stringToPaste, Text::Controller::COMMIT );
3343 mImpl->ChangeState( EventData::EDITING );
3344 mImpl->RequestRelayout();
3346 if( NULL != mImpl->mEditableControlInterface )
3348 // Do this last since it provides callbacks into application code
3349 mImpl->mEditableControlInterface->TextChanged();
3353 bool Controller::RemoveText( int cursorOffset,
3354 int numberOfCharacters,
3355 UpdateInputStyleType type )
3357 bool removed = false;
3359 if( NULL == mImpl->mEventData )
3364 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3365 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3367 if( !mImpl->IsShowingPlaceholderText() )
3369 // Delete at current cursor position
3370 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3371 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3373 CharacterIndex cursorIndex = 0;
3375 // Validate the cursor position & number of characters
3376 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3378 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3381 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3383 numberOfCharacters = currentText.Count() - cursorIndex;
3386 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.
3387 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3389 // Mark the paragraphs to be updated.
3390 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3392 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3393 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3394 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3395 mImpl->mTextUpdateInfo.mClearAll = true;
3399 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3400 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3403 // Update the input style and remove the text's style before removing the text.
3405 if( UPDATE_INPUT_STYLE == type )
3407 // Keep a copy of the current input style.
3408 InputStyle currentInputStyle;
3409 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3411 // Set first the default input style.
3412 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3414 // Update the input style.
3415 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3417 // Compare if the input style has changed.
3418 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3420 if( hasInputStyleChanged )
3422 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3423 // Queue the input style changed signal.
3424 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3428 // Updates the text style runs by removing characters. Runs with no characters are removed.
3429 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3431 // Remove the characters.
3432 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3433 Vector<Character>::Iterator last = first + numberOfCharacters;
3435 currentText.Erase( first, last );
3437 // Cursor position retreat
3438 oldCursorIndex = cursorIndex;
3440 mImpl->mEventData->mScrollAfterDelete = true;
3442 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3450 bool Controller::RemoveSelectedText()
3452 bool textRemoved( false );
3454 if( EventData::SELECTING == mImpl->mEventData->mState )
3456 std::string removedString;
3457 mImpl->RetrieveSelection( removedString, true );
3459 if( !removedString.empty() )
3462 mImpl->ChangeState( EventData::EDITING );
3469 // private : Relayout.
3471 bool Controller::DoRelayout( const Size& size,
3472 OperationsMask operationsRequired,
3475 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3476 bool viewUpdated( false );
3478 // Calculate the operations to be done.
3479 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3481 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3482 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3484 // Get the current layout size.
3485 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3487 if( NO_OPERATION != ( LAYOUT & operations ) )
3489 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3491 // Some vectors with data needed to layout and reorder may be void
3492 // after the first time the text has been laid out.
3493 // Fill the vectors again.
3495 // Calculate the number of glyphs to layout.
3496 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3497 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3498 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3499 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3501 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3502 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3504 // Make sure the index is not out of bound
3505 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3506 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3507 ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3509 std::string currentText;
3510 GetText( currentText );
3512 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3513 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3514 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3519 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3520 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3522 if( 0u == totalNumberOfGlyphs )
3524 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3526 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3529 // Nothing else to do if there is no glyphs.
3530 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3534 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3535 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3536 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3537 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3538 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3539 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3540 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3541 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3543 // Set the layout parameters.
3544 Layout::Parameters layoutParameters( size,
3546 lineBreakInfo.Begin(),
3547 wordBreakInfo.Begin(),
3548 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3550 glyphsToCharactersMap.Begin(),
3551 charactersPerGlyph.Begin(),
3552 charactersToGlyphBuffer,
3553 glyphsPerCharacterBuffer,
3554 totalNumberOfGlyphs,
3555 mImpl->mModel->mHorizontalAlignment,
3556 mImpl->mModel->mLineWrapMode,
3558 mImpl->mModel->mIgnoreSpacesAfterText,
3559 mImpl->mModel->mMatchSystemLanguageDirection );
3561 // Resize the vector of positions to have the same size than the vector of glyphs.
3562 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3563 glyphPositions.Resize( totalNumberOfGlyphs );
3565 // Whether the last character is a new paragraph character.
3566 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3567 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3569 // The initial glyph and the number of glyphs to layout.
3570 layoutParameters.startGlyphIndex = startGlyphIndex;
3571 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3572 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3573 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3575 // Update the ellipsis
3576 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3578 if( NULL != mImpl->mEventData )
3580 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3582 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3584 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3586 // Disable ellipsis when editing
3587 elideTextEnabled = false;
3590 // Reset the scroll position in inactive state
3591 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3593 ResetScrollPosition();
3597 // Update the visual model.
3599 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3601 mImpl->mModel->mVisualModel->mLines,
3605 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3609 layoutSize = newLayoutSize;
3611 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3613 mImpl->mIsTextDirectionRTL = false;
3616 // Reorder the lines
3617 if( NO_OPERATION != ( REORDER & operations ) )
3619 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3620 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3622 // Check first if there are paragraphs with bidirectional info.
3623 if( 0u != bidirectionalInfo.Count() )
3626 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3628 // Reorder the lines.
3629 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3630 ReorderLines( bidirectionalInfo,
3632 requestedNumberOfCharacters,
3633 mImpl->mModel->mVisualModel->mLines,
3634 bidirectionalLineInfo );
3636 // Set the bidirectional info per line into the layout parameters.
3637 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3638 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3640 // Re-layout the text. Reorder those lines with right to left characters.
3641 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3643 requestedNumberOfCharacters,
3646 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3648 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3651 mImpl->mIsTextDirectionRTL = firstline->direction;
3657 // Sets the layout size.
3658 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3660 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3665 if( NO_OPERATION != ( ALIGN & operations ) )
3667 // The laid-out lines.
3668 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3670 // Need to align with the control's size as the text may contain lines
3671 // starting either with left to right text or right to left.
3672 mImpl->mLayoutEngine.Align( size,
3674 requestedNumberOfCharacters,
3675 mImpl->mModel->mHorizontalAlignment,
3677 mImpl->mModel->mAlignmentOffset,
3678 mImpl->mLayoutDirection,
3679 mImpl->mModel->mMatchSystemLanguageDirection );
3683 #if defined(DEBUG_ENABLED)
3684 std::string currentText;
3685 GetText( currentText );
3686 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3688 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3692 void Controller::CalculateVerticalOffset( const Size& controlSize )
3694 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3696 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3698 // Get the line height of the default font.
3699 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3702 switch( mImpl->mModel->mVerticalAlignment )
3704 case VerticalAlignment::TOP:
3706 mImpl->mModel->mScrollPosition.y = 0.f;
3709 case VerticalAlignment::CENTER:
3711 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3714 case VerticalAlignment::BOTTOM:
3716 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3722 // private : Events.
3724 void Controller::ProcessModifyEvents()
3726 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3728 if( 0u == events.Count() )
3734 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3735 endIt = events.End();
3739 const ModifyEvent& event = *it;
3741 if( ModifyEvent::TEXT_REPLACED == event.type )
3743 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3744 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3746 TextReplacedEvent();
3748 else if( ModifyEvent::TEXT_INSERTED == event.type )
3750 TextInsertedEvent();
3752 else if( ModifyEvent::TEXT_DELETED == event.type )
3754 // Placeholder-text cannot be deleted
3755 if( !mImpl->IsShowingPlaceholderText() )
3762 if( NULL != mImpl->mEventData )
3764 // When the text is being modified, delay cursor blinking
3765 mImpl->mEventData->mDecorator->DelayCursorBlink();
3767 // Update selection position after modifying the text
3768 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3769 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3772 // Discard temporary text
3776 void Controller::TextReplacedEvent()
3778 // The natural size needs to be re-calculated.
3779 mImpl->mRecalculateNaturalSize = true;
3781 // The text direction needs to be updated.
3782 mImpl->mUpdateTextDirection = true;
3784 // Apply modifications to the model
3785 mImpl->mOperationsPending = ALL_OPERATIONS;
3788 void Controller::TextInsertedEvent()
3790 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3792 if( NULL == mImpl->mEventData )
3797 mImpl->mEventData->mCheckScrollAmount = true;
3799 // The natural size needs to be re-calculated.
3800 mImpl->mRecalculateNaturalSize = true;
3802 // The text direction needs to be updated.
3803 mImpl->mUpdateTextDirection = true;
3805 // Apply modifications to the model; TODO - Optimize this
3806 mImpl->mOperationsPending = ALL_OPERATIONS;
3809 void Controller::TextDeletedEvent()
3811 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3813 if( NULL == mImpl->mEventData )
3818 mImpl->mEventData->mCheckScrollAmount = true;
3820 // The natural size needs to be re-calculated.
3821 mImpl->mRecalculateNaturalSize = true;
3823 // The text direction needs to be updated.
3824 mImpl->mUpdateTextDirection = true;
3826 // Apply modifications to the model; TODO - Optimize this
3827 mImpl->mOperationsPending = ALL_OPERATIONS;
3830 void Controller::SelectEvent( float x, float y, bool selectAll )
3832 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3834 if( NULL != mImpl->mEventData )
3838 Event event( Event::SELECT_ALL );
3839 mImpl->mEventData->mEventQueue.push_back( event );
3843 Event event( Event::SELECT );
3844 event.p2.mFloat = x;
3845 event.p3.mFloat = y;
3846 mImpl->mEventData->mEventQueue.push_back( event );
3849 mImpl->mEventData->mCheckScrollAmount = true;
3850 mImpl->mEventData->mIsLeftHandleSelected = true;
3851 mImpl->mEventData->mIsRightHandleSelected = true;
3852 mImpl->RequestRelayout();
3856 bool Controller::DeleteEvent( int keyCode )
3858 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3860 bool removed = false;
3862 if( NULL == mImpl->mEventData )
3867 // InputMethodContext is no longer handling key-events
3868 mImpl->ClearPreEditFlag();
3870 if( EventData::SELECTING == mImpl->mEventData->mState )
3872 removed = RemoveSelectedText();
3874 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3876 // Remove the character before the current cursor position
3877 removed = RemoveText( -1,
3879 UPDATE_INPUT_STYLE );
3881 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
3883 // Remove the character after the current cursor position
3884 removed = RemoveText( 0,
3886 UPDATE_INPUT_STYLE );
3891 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3892 !mImpl->IsPlaceholderAvailable() )
3894 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3898 ShowPlaceholderText();
3900 mImpl->mEventData->mUpdateCursorPosition = true;
3901 mImpl->mEventData->mScrollAfterDelete = true;
3907 // private : Helpers.
3909 void Controller::ResetText()
3912 mImpl->mModel->mLogicalModel->mText.Clear();
3914 // We have cleared everything including the placeholder-text
3915 mImpl->PlaceholderCleared();
3917 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3918 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3919 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3921 // Clear any previous text.
3922 mImpl->mTextUpdateInfo.mClearAll = true;
3924 // The natural size needs to be re-calculated.
3925 mImpl->mRecalculateNaturalSize = true;
3927 // The text direction needs to be updated.
3928 mImpl->mUpdateTextDirection = true;
3930 // Apply modifications to the model
3931 mImpl->mOperationsPending = ALL_OPERATIONS;
3934 void Controller::ShowPlaceholderText()
3936 if( mImpl->IsPlaceholderAvailable() )
3938 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3940 if( NULL == mImpl->mEventData )
3945 mImpl->mEventData->mIsShowingPlaceholderText = true;
3947 // Disable handles when showing place-holder text
3948 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3949 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3950 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3952 const char* text( NULL );
3955 // TODO - Switch Placeholder text when changing state
3956 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3957 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3959 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3960 size = mImpl->mEventData->mPlaceholderTextActive.size();
3964 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3965 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3968 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3969 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3971 // Reset model for showing placeholder.
3972 mImpl->mModel->mLogicalModel->mText.Clear();
3973 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3975 // Convert text into UTF-32
3976 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3977 utf32Characters.Resize( size );
3979 // This is a bit horrible but std::string returns a (signed) char*
3980 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3982 // Transform a text array encoded in utf8 into an array encoded in utf32.
3983 // It returns the actual number of characters.
3984 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3985 utf32Characters.Resize( characterCount );
3987 // The characters to be added.
3988 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3990 // Reset the cursor position
3991 mImpl->mEventData->mPrimaryCursorPosition = 0;
3993 // The natural size needs to be re-calculated.
3994 mImpl->mRecalculateNaturalSize = true;
3996 // The text direction needs to be updated.
3997 mImpl->mUpdateTextDirection = true;
3999 // Apply modifications to the model
4000 mImpl->mOperationsPending = ALL_OPERATIONS;
4002 // Update the rest of the model during size negotiation
4003 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4007 void Controller::ClearFontData()
4009 if( mImpl->mFontDefaults )
4011 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4014 // Set flags to update the model.
4015 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4016 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4017 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4019 mImpl->mTextUpdateInfo.mClearAll = true;
4020 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4021 mImpl->mRecalculateNaturalSize = true;
4023 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4029 UPDATE_LAYOUT_SIZE |
4034 void Controller::ClearStyleData()
4036 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4037 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4040 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4042 // Reset the cursor position
4043 if( NULL != mImpl->mEventData )
4045 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4047 // Update the cursor if it's in editing mode.
4048 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4050 mImpl->mEventData->mUpdateCursorPosition = true;
4055 void Controller::ResetScrollPosition()
4057 if( NULL != mImpl->mEventData )
4059 // Reset the scroll position.
4060 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4061 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4065 void Controller::SetControlInterface( ControlInterface* controlInterface )
4067 mImpl->mControlInterface = controlInterface;
4070 bool Controller::ShouldClearFocusOnEscape() const
4072 return mImpl->mShouldClearFocusOnEscape;
4075 // private : Private contructors & copy operator.
4077 Controller::Controller()
4080 mImpl = new Controller::Impl( NULL, NULL );
4083 Controller::Controller( ControlInterface* controlInterface )
4085 mImpl = new Controller::Impl( controlInterface, NULL );
4088 Controller::Controller( ControlInterface* controlInterface,
4089 EditableControlInterface* editableControlInterface )
4091 mImpl = new Controller::Impl( controlInterface,
4092 editableControlInterface );
4095 // The copy constructor and operator are left unimplemented.
4097 // protected : Destructor.
4099 Controller::~Controller()
4106 } // namespace Toolkit