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 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
412 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
414 // Set the text wrap mode.
415 mImpl->mModel->mLineWrapMode = lineWrapMode;
418 // Update Text layout for applying wrap mode
419 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
424 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
425 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
426 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
429 mImpl->RequestRelayout();
433 Text::LineWrap::Mode Controller::GetLineWrapMode() const
435 return mImpl->mModel->mLineWrapMode;
438 void Controller::SetTextElideEnabled( bool enabled )
440 mImpl->mModel->mElideEnabled = enabled;
443 bool Controller::IsTextElideEnabled() const
445 return mImpl->mModel->mElideEnabled;
448 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
450 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
451 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
453 // Update placeholder if there is no text
454 if( mImpl->IsShowingPlaceholderText() ||
455 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
457 ShowPlaceholderText();
461 bool Controller::IsPlaceholderTextElideEnabled() const
463 return mImpl->mEventData->mIsPlaceholderElideEnabled;
466 void Controller::SetSelectionEnabled( bool enabled )
468 mImpl->mEventData->mSelectionEnabled = enabled;
471 bool Controller::IsSelectionEnabled() const
473 return mImpl->mEventData->mSelectionEnabled;
476 void Controller::SetShiftSelectionEnabled( bool enabled )
478 mImpl->mEventData->mShiftSelectionFlag = enabled;
481 bool Controller::IsShiftSelectionEnabled() const
483 return mImpl->mEventData->mShiftSelectionFlag;
486 void Controller::SetGrabHandleEnabled( bool enabled )
488 mImpl->mEventData->mGrabHandleEnabled = enabled;
491 bool Controller::IsGrabHandleEnabled() const
493 return mImpl->mEventData->mGrabHandleEnabled;
498 void Controller::SetText( const std::string& text )
500 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
502 // Reset keyboard as text changed
503 mImpl->ResetInputMethodContext();
505 // Remove the previously set text and style.
511 CharacterIndex lastCursorIndex = 0u;
513 if( NULL != mImpl->mEventData )
515 // If popup shown then hide it by switching to Editing state
516 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
517 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
518 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
519 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
521 mImpl->ChangeState( EventData::EDITING );
527 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
529 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
530 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
532 Length textSize = 0u;
533 const uint8_t* utf8 = NULL;
534 if( mImpl->mMarkupProcessorEnabled )
536 ProcessMarkupString( text, markupProcessData );
537 textSize = markupProcessData.markupProcessedText.size();
539 // This is a bit horrible but std::string returns a (signed) char*
540 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
544 textSize = text.size();
546 // This is a bit horrible but std::string returns a (signed) char*
547 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
550 // Convert text into UTF-32
551 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
552 utf32Characters.Resize( textSize );
554 // Transform a text array encoded in utf8 into an array encoded in utf32.
555 // It returns the actual number of characters.
556 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
557 utf32Characters.Resize( characterCount );
559 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
560 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
562 // The characters to be added.
563 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
565 // To reset the cursor position
566 lastCursorIndex = characterCount;
568 // Update the rest of the model during size negotiation
569 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
571 // The natural size needs to be re-calculated.
572 mImpl->mRecalculateNaturalSize = true;
574 // The text direction needs to be updated.
575 mImpl->mUpdateTextDirection = true;
577 // Apply modifications to the model
578 mImpl->mOperationsPending = ALL_OPERATIONS;
582 ShowPlaceholderText();
585 // Resets the cursor position.
586 ResetCursorPosition( lastCursorIndex );
588 // Scrolls the text to make the cursor visible.
589 ResetScrollPosition();
591 mImpl->RequestRelayout();
593 if( NULL != mImpl->mEventData )
595 // Cancel previously queued events
596 mImpl->mEventData->mEventQueue.clear();
599 // Do this last since it provides callbacks into application code.
600 if( NULL != mImpl->mEditableControlInterface )
602 mImpl->mEditableControlInterface->TextChanged();
606 void Controller::GetText( std::string& text ) const
608 if( !mImpl->IsShowingPlaceholderText() )
610 // Retrieves the text string.
611 mImpl->GetText( 0u, text );
615 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
619 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
621 if( NULL != mImpl->mEventData )
623 if( PLACEHOLDER_TYPE_INACTIVE == type )
625 mImpl->mEventData->mPlaceholderTextInactive = text;
629 mImpl->mEventData->mPlaceholderTextActive = text;
632 // Update placeholder if there is no text
633 if( mImpl->IsShowingPlaceholderText() ||
634 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
636 ShowPlaceholderText();
641 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
643 if( NULL != mImpl->mEventData )
645 if( PLACEHOLDER_TYPE_INACTIVE == type )
647 text = mImpl->mEventData->mPlaceholderTextInactive;
651 text = mImpl->mEventData->mPlaceholderTextActive;
656 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
658 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
660 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
662 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
663 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
667 mImpl->RequestRelayout();
671 // public : Default style & Input style
673 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
675 if( NULL == mImpl->mFontDefaults )
677 mImpl->mFontDefaults = new FontDefaults();
680 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
681 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
682 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
684 // Clear the font-specific data
687 mImpl->RequestRelayout();
690 const std::string& Controller::GetDefaultFontFamily() const
692 if( NULL != mImpl->mFontDefaults )
694 return mImpl->mFontDefaults->mFontDescription.family;
700 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
702 if( NULL != mImpl->mEventData )
704 if( NULL == mImpl->mEventData->mPlaceholderFont )
706 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
709 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
710 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
711 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
713 mImpl->RequestRelayout();
717 const std::string& Controller::GetPlaceholderFontFamily() const
719 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
721 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
727 void Controller::SetDefaultFontWeight( FontWeight weight )
729 if( NULL == mImpl->mFontDefaults )
731 mImpl->mFontDefaults = new FontDefaults();
734 mImpl->mFontDefaults->mFontDescription.weight = weight;
735 mImpl->mFontDefaults->weightDefined = true;
737 // Clear the font-specific data
740 mImpl->RequestRelayout();
743 bool Controller::IsDefaultFontWeightDefined() const
745 if( NULL != mImpl->mFontDefaults )
747 return mImpl->mFontDefaults->weightDefined;
753 FontWeight Controller::GetDefaultFontWeight() const
755 if( NULL != mImpl->mFontDefaults )
757 return mImpl->mFontDefaults->mFontDescription.weight;
760 return TextAbstraction::FontWeight::NORMAL;
763 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
765 if( NULL != mImpl->mEventData )
767 if( NULL == mImpl->mEventData->mPlaceholderFont )
769 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
772 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
773 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
775 mImpl->RequestRelayout();
779 bool Controller::IsPlaceholderTextFontWeightDefined() const
781 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
783 return mImpl->mEventData->mPlaceholderFont->weightDefined;
788 FontWeight Controller::GetPlaceholderTextFontWeight() const
790 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
792 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
795 return TextAbstraction::FontWeight::NORMAL;
798 void Controller::SetDefaultFontWidth( FontWidth width )
800 if( NULL == mImpl->mFontDefaults )
802 mImpl->mFontDefaults = new FontDefaults();
805 mImpl->mFontDefaults->mFontDescription.width = width;
806 mImpl->mFontDefaults->widthDefined = true;
808 // Clear the font-specific data
811 mImpl->RequestRelayout();
814 bool Controller::IsDefaultFontWidthDefined() const
816 if( NULL != mImpl->mFontDefaults )
818 return mImpl->mFontDefaults->widthDefined;
824 FontWidth Controller::GetDefaultFontWidth() const
826 if( NULL != mImpl->mFontDefaults )
828 return mImpl->mFontDefaults->mFontDescription.width;
831 return TextAbstraction::FontWidth::NORMAL;
834 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
836 if( NULL != mImpl->mEventData )
838 if( NULL == mImpl->mEventData->mPlaceholderFont )
840 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
843 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
844 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
846 mImpl->RequestRelayout();
850 bool Controller::IsPlaceholderTextFontWidthDefined() const
852 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
854 return mImpl->mEventData->mPlaceholderFont->widthDefined;
859 FontWidth Controller::GetPlaceholderTextFontWidth() const
861 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
863 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
866 return TextAbstraction::FontWidth::NORMAL;
869 void Controller::SetDefaultFontSlant( FontSlant slant )
871 if( NULL == mImpl->mFontDefaults )
873 mImpl->mFontDefaults = new FontDefaults();
876 mImpl->mFontDefaults->mFontDescription.slant = slant;
877 mImpl->mFontDefaults->slantDefined = true;
879 // Clear the font-specific data
882 mImpl->RequestRelayout();
885 bool Controller::IsDefaultFontSlantDefined() const
887 if( NULL != mImpl->mFontDefaults )
889 return mImpl->mFontDefaults->slantDefined;
894 FontSlant Controller::GetDefaultFontSlant() const
896 if( NULL != mImpl->mFontDefaults )
898 return mImpl->mFontDefaults->mFontDescription.slant;
901 return TextAbstraction::FontSlant::NORMAL;
904 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
906 if( NULL != mImpl->mEventData )
908 if( NULL == mImpl->mEventData->mPlaceholderFont )
910 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
913 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
914 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
916 mImpl->RequestRelayout();
920 bool Controller::IsPlaceholderTextFontSlantDefined() const
922 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
924 return mImpl->mEventData->mPlaceholderFont->slantDefined;
929 FontSlant Controller::GetPlaceholderTextFontSlant() const
931 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
933 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
936 return TextAbstraction::FontSlant::NORMAL;
939 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
941 if( NULL == mImpl->mFontDefaults )
943 mImpl->mFontDefaults = new FontDefaults();
950 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
951 mImpl->mFontDefaults->sizeDefined = true;
956 // Point size = Pixel size * 72.f / DPI
957 unsigned int horizontalDpi = 0u;
958 unsigned int verticalDpi = 0u;
959 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
960 fontClient.GetDpi( horizontalDpi, verticalDpi );
962 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
963 mImpl->mFontDefaults->sizeDefined = true;
968 // Clear the font-specific data
971 mImpl->RequestRelayout();
974 float Controller::GetDefaultFontSize( FontSizeType type ) const
977 if( NULL != mImpl->mFontDefaults )
983 value = mImpl->mFontDefaults->mDefaultPointSize;
988 // Pixel size = Point size * DPI / 72.f
989 unsigned int horizontalDpi = 0u;
990 unsigned int verticalDpi = 0u;
991 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
992 fontClient.GetDpi( horizontalDpi, verticalDpi );
994 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1004 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1006 if( NULL != mImpl->mEventData )
1008 if( NULL == mImpl->mEventData->mPlaceholderFont )
1010 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1017 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1018 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1019 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1024 // Point size = Pixel size * 72.f / DPI
1025 unsigned int horizontalDpi = 0u;
1026 unsigned int verticalDpi = 0u;
1027 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1028 fontClient.GetDpi( horizontalDpi, verticalDpi );
1030 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1031 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1032 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1037 mImpl->RequestRelayout();
1041 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1044 if( NULL != mImpl->mEventData )
1050 if( NULL != mImpl->mEventData->mPlaceholderFont )
1052 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1056 // If the placeholder text font size is not set, then return the default font size.
1057 value = GetDefaultFontSize( POINT_SIZE );
1063 if( NULL != mImpl->mEventData->mPlaceholderFont )
1065 // Pixel size = Point size * DPI / 72.f
1066 unsigned int horizontalDpi = 0u;
1067 unsigned int verticalDpi = 0u;
1068 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1069 fontClient.GetDpi( horizontalDpi, verticalDpi );
1071 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1075 // If the placeholder text font size is not set, then return the default font size.
1076 value = GetDefaultFontSize( PIXEL_SIZE );
1087 void Controller::SetDefaultColor( const Vector4& color )
1089 mImpl->mTextColor = color;
1091 if( !mImpl->IsShowingPlaceholderText() )
1093 mImpl->mModel->mVisualModel->SetTextColor( color );
1095 mImpl->RequestRelayout();
1099 const Vector4& Controller::GetDefaultColor() const
1101 return mImpl->mTextColor;
1104 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1106 if( NULL != mImpl->mEventData )
1108 mImpl->mEventData->mPlaceholderTextColor = textColor;
1111 if( mImpl->IsShowingPlaceholderText() )
1113 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1114 mImpl->RequestRelayout();
1118 const Vector4& Controller::GetPlaceholderTextColor() const
1120 if( NULL != mImpl->mEventData )
1122 return mImpl->mEventData->mPlaceholderTextColor;
1125 return Color::BLACK;
1128 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1130 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1132 mImpl->RequestRelayout();
1135 const Vector2& Controller::GetShadowOffset() const
1137 return mImpl->mModel->mVisualModel->GetShadowOffset();
1140 void Controller::SetShadowColor( const Vector4& shadowColor )
1142 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1144 mImpl->RequestRelayout();
1147 const Vector4& Controller::GetShadowColor() const
1149 return mImpl->mModel->mVisualModel->GetShadowColor();
1152 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1154 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1156 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1158 mImpl->RequestRelayout();
1162 const float& Controller::GetShadowBlurRadius() const
1164 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1167 void Controller::SetUnderlineColor( const Vector4& color )
1169 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1171 mImpl->RequestRelayout();
1174 const Vector4& Controller::GetUnderlineColor() const
1176 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1179 void Controller::SetUnderlineEnabled( bool enabled )
1181 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1183 mImpl->RequestRelayout();
1186 bool Controller::IsUnderlineEnabled() const
1188 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1191 void Controller::SetUnderlineHeight( float height )
1193 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1195 mImpl->RequestRelayout();
1198 float Controller::GetUnderlineHeight() const
1200 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1203 void Controller::SetOutlineColor( const Vector4& color )
1205 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1207 mImpl->RequestRelayout();
1210 const Vector4& Controller::GetOutlineColor() const
1212 return mImpl->mModel->mVisualModel->GetOutlineColor();
1215 void Controller::SetOutlineWidth( unsigned int width )
1217 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1219 mImpl->RequestRelayout();
1222 unsigned int Controller::GetOutlineWidth() const
1224 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1227 void Controller::SetBackgroundColor( const Vector4& color )
1229 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1231 mImpl->RequestRelayout();
1234 const Vector4& Controller::GetBackgroundColor() const
1236 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1239 void Controller::SetBackgroundEnabled( bool enabled )
1241 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1243 mImpl->RequestRelayout();
1246 bool Controller::IsBackgroundEnabled() const
1248 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1251 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1253 if( NULL == mImpl->mEmbossDefaults )
1255 mImpl->mEmbossDefaults = new EmbossDefaults();
1258 mImpl->mEmbossDefaults->properties = embossProperties;
1261 const std::string& Controller::GetDefaultEmbossProperties() const
1263 if( NULL != mImpl->mEmbossDefaults )
1265 return mImpl->mEmbossDefaults->properties;
1268 return EMPTY_STRING;
1271 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1273 if( NULL == mImpl->mOutlineDefaults )
1275 mImpl->mOutlineDefaults = new OutlineDefaults();
1278 mImpl->mOutlineDefaults->properties = outlineProperties;
1281 const std::string& Controller::GetDefaultOutlineProperties() const
1283 if( NULL != mImpl->mOutlineDefaults )
1285 return mImpl->mOutlineDefaults->properties;
1288 return EMPTY_STRING;
1291 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1293 if( std::abs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000 )
1295 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1296 mImpl->mRecalculateNaturalSize = true;
1302 float Controller::GetDefaultLineSpacing() const
1304 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1307 void Controller::SetInputColor( const Vector4& color )
1309 if( NULL != mImpl->mEventData )
1311 mImpl->mEventData->mInputStyle.textColor = color;
1312 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1314 if( EventData::SELECTING == mImpl->mEventData->mState )
1316 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1318 // Get start and end position of selection
1319 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1320 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1322 // Add the color run.
1323 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1324 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1326 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1327 colorRun.color = color;
1328 colorRun.characterRun.characterIndex = startOfSelectedText;
1329 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1331 // Request to relayout.
1332 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1333 mImpl->RequestRelayout();
1335 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1336 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1337 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1342 const Vector4& Controller::GetInputColor() const
1344 if( NULL != mImpl->mEventData )
1346 return mImpl->mEventData->mInputStyle.textColor;
1349 // Return the default text's color if there is no EventData.
1350 return mImpl->mTextColor;
1354 void Controller::SetInputFontFamily( const std::string& fontFamily )
1356 if( NULL != mImpl->mEventData )
1358 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1359 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1361 if( EventData::SELECTING == mImpl->mEventData->mState )
1363 CharacterIndex startOfSelectedText = 0u;
1364 Length lengthOfSelectedText = 0u;
1365 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1366 mImpl->mModel->mLogicalModel,
1367 startOfSelectedText,
1368 lengthOfSelectedText );
1370 fontDescriptionRun.familyLength = fontFamily.size();
1371 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1372 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1373 fontDescriptionRun.familyDefined = true;
1375 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1377 // Request to relayout.
1378 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1383 UPDATE_LAYOUT_SIZE |
1386 mImpl->mRecalculateNaturalSize = true;
1387 mImpl->RequestRelayout();
1389 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1390 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1391 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1393 // As the font changes, recalculate the handle positions is needed.
1394 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1395 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1396 mImpl->mEventData->mUpdateHighlightBox = true;
1397 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1402 const std::string& Controller::GetInputFontFamily() const
1404 if( NULL != mImpl->mEventData )
1406 return mImpl->mEventData->mInputStyle.familyName;
1409 // Return the default font's family if there is no EventData.
1410 return GetDefaultFontFamily();
1413 void Controller::SetInputFontWeight( FontWeight weight )
1415 if( NULL != mImpl->mEventData )
1417 mImpl->mEventData->mInputStyle.weight = weight;
1418 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1420 if( EventData::SELECTING == mImpl->mEventData->mState )
1422 CharacterIndex startOfSelectedText = 0u;
1423 Length lengthOfSelectedText = 0u;
1424 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1425 mImpl->mModel->mLogicalModel,
1426 startOfSelectedText,
1427 lengthOfSelectedText );
1429 fontDescriptionRun.weight = weight;
1430 fontDescriptionRun.weightDefined = true;
1432 // Request to relayout.
1433 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1438 UPDATE_LAYOUT_SIZE |
1441 mImpl->mRecalculateNaturalSize = true;
1442 mImpl->RequestRelayout();
1444 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1445 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1446 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1448 // As the font might change, recalculate the handle positions is needed.
1449 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1450 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1451 mImpl->mEventData->mUpdateHighlightBox = true;
1452 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1457 bool Controller::IsInputFontWeightDefined() const
1459 bool defined = false;
1461 if( NULL != mImpl->mEventData )
1463 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1469 FontWeight Controller::GetInputFontWeight() const
1471 if( NULL != mImpl->mEventData )
1473 return mImpl->mEventData->mInputStyle.weight;
1476 return GetDefaultFontWeight();
1479 void Controller::SetInputFontWidth( FontWidth width )
1481 if( NULL != mImpl->mEventData )
1483 mImpl->mEventData->mInputStyle.width = width;
1484 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1486 if( EventData::SELECTING == mImpl->mEventData->mState )
1488 CharacterIndex startOfSelectedText = 0u;
1489 Length lengthOfSelectedText = 0u;
1490 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1491 mImpl->mModel->mLogicalModel,
1492 startOfSelectedText,
1493 lengthOfSelectedText );
1495 fontDescriptionRun.width = width;
1496 fontDescriptionRun.widthDefined = true;
1498 // Request to relayout.
1499 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1504 UPDATE_LAYOUT_SIZE |
1507 mImpl->mRecalculateNaturalSize = true;
1508 mImpl->RequestRelayout();
1510 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1511 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1512 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1514 // As the font might change, recalculate the handle positions is needed.
1515 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1516 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1517 mImpl->mEventData->mUpdateHighlightBox = true;
1518 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1523 bool Controller::IsInputFontWidthDefined() const
1525 bool defined = false;
1527 if( NULL != mImpl->mEventData )
1529 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1535 FontWidth Controller::GetInputFontWidth() const
1537 if( NULL != mImpl->mEventData )
1539 return mImpl->mEventData->mInputStyle.width;
1542 return GetDefaultFontWidth();
1545 void Controller::SetInputFontSlant( FontSlant slant )
1547 if( NULL != mImpl->mEventData )
1549 mImpl->mEventData->mInputStyle.slant = slant;
1550 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1552 if( EventData::SELECTING == mImpl->mEventData->mState )
1554 CharacterIndex startOfSelectedText = 0u;
1555 Length lengthOfSelectedText = 0u;
1556 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1557 mImpl->mModel->mLogicalModel,
1558 startOfSelectedText,
1559 lengthOfSelectedText );
1561 fontDescriptionRun.slant = slant;
1562 fontDescriptionRun.slantDefined = true;
1564 // Request to relayout.
1565 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1570 UPDATE_LAYOUT_SIZE |
1573 mImpl->mRecalculateNaturalSize = true;
1574 mImpl->RequestRelayout();
1576 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1577 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1578 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1580 // As the font might change, recalculate the handle positions is needed.
1581 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1582 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1583 mImpl->mEventData->mUpdateHighlightBox = true;
1584 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1589 bool Controller::IsInputFontSlantDefined() const
1591 bool defined = false;
1593 if( NULL != mImpl->mEventData )
1595 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1601 FontSlant Controller::GetInputFontSlant() const
1603 if( NULL != mImpl->mEventData )
1605 return mImpl->mEventData->mInputStyle.slant;
1608 return GetDefaultFontSlant();
1611 void Controller::SetInputFontPointSize( float size )
1613 if( NULL != mImpl->mEventData )
1615 mImpl->mEventData->mInputStyle.size = size;
1616 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1618 if( EventData::SELECTING == mImpl->mEventData->mState )
1620 CharacterIndex startOfSelectedText = 0u;
1621 Length lengthOfSelectedText = 0u;
1622 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1623 mImpl->mModel->mLogicalModel,
1624 startOfSelectedText,
1625 lengthOfSelectedText );
1627 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1628 fontDescriptionRun.sizeDefined = true;
1630 // Request to relayout.
1631 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1636 UPDATE_LAYOUT_SIZE |
1639 mImpl->mRecalculateNaturalSize = true;
1640 mImpl->RequestRelayout();
1642 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1643 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1644 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1646 // As the font might change, recalculate the handle positions is needed.
1647 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1648 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1649 mImpl->mEventData->mUpdateHighlightBox = true;
1650 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1655 float Controller::GetInputFontPointSize() const
1657 if( NULL != mImpl->mEventData )
1659 return mImpl->mEventData->mInputStyle.size;
1662 // Return the default font's point size if there is no EventData.
1663 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1666 void Controller::SetInputLineSpacing( float lineSpacing )
1668 if( NULL != mImpl->mEventData )
1670 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1671 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1675 float Controller::GetInputLineSpacing() const
1677 if( NULL != mImpl->mEventData )
1679 return mImpl->mEventData->mInputStyle.lineSpacing;
1685 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1687 if( NULL != mImpl->mEventData )
1689 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1693 const std::string& Controller::GetInputShadowProperties() const
1695 if( NULL != mImpl->mEventData )
1697 return mImpl->mEventData->mInputStyle.shadowProperties;
1700 return EMPTY_STRING;
1703 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1705 if( NULL != mImpl->mEventData )
1707 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1711 const std::string& Controller::GetInputUnderlineProperties() const
1713 if( NULL != mImpl->mEventData )
1715 return mImpl->mEventData->mInputStyle.underlineProperties;
1718 return EMPTY_STRING;
1721 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1723 if( NULL != mImpl->mEventData )
1725 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1729 const std::string& Controller::GetInputEmbossProperties() const
1731 if( NULL != mImpl->mEventData )
1733 return mImpl->mEventData->mInputStyle.embossProperties;
1736 return GetDefaultEmbossProperties();
1739 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1741 if( NULL != mImpl->mEventData )
1743 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1747 const std::string& Controller::GetInputOutlineProperties() const
1749 if( NULL != mImpl->mEventData )
1751 return mImpl->mEventData->mInputStyle.outlineProperties;
1754 return GetDefaultOutlineProperties();
1757 void Controller::SetInputModePassword( bool passwordInput )
1759 if( NULL != mImpl->mEventData )
1761 mImpl->mEventData->mPasswordInput = passwordInput;
1765 bool Controller::IsInputModePassword()
1767 if( NULL != mImpl->mEventData )
1769 return mImpl->mEventData->mPasswordInput;
1774 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1776 if( NULL != mImpl->mEventData )
1778 mImpl->mEventData->mDoubleTapAction = action;
1782 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1784 NoTextTap::Action action = NoTextTap::NO_ACTION;
1786 if( NULL != mImpl->mEventData )
1788 action = mImpl->mEventData->mDoubleTapAction;
1794 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1796 if( NULL != mImpl->mEventData )
1798 mImpl->mEventData->mLongPressAction = action;
1802 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1804 NoTextTap::Action action = NoTextTap::NO_ACTION;
1806 if( NULL != mImpl->mEventData )
1808 action = mImpl->mEventData->mLongPressAction;
1814 bool Controller::IsUnderlineSetByString()
1816 return mImpl->mUnderlineSetByString;
1819 void Controller::UnderlineSetByString( bool setByString )
1821 mImpl->mUnderlineSetByString = setByString;
1824 bool Controller::IsShadowSetByString()
1826 return mImpl->mShadowSetByString;
1829 void Controller::ShadowSetByString( bool setByString )
1831 mImpl->mShadowSetByString = setByString;
1834 bool Controller::IsOutlineSetByString()
1836 return mImpl->mOutlineSetByString;
1839 void Controller::OutlineSetByString( bool setByString )
1841 mImpl->mOutlineSetByString = setByString;
1844 bool Controller::IsFontStyleSetByString()
1846 return mImpl->mFontStyleSetByString;
1849 void Controller::FontStyleSetByString( bool setByString )
1851 mImpl->mFontStyleSetByString = setByString;
1854 // public : Queries & retrieves.
1856 Layout::Engine& Controller::GetLayoutEngine()
1858 return mImpl->mLayoutEngine;
1861 View& Controller::GetView()
1863 return mImpl->mView;
1866 Vector3 Controller::GetNaturalSize()
1868 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1869 Vector3 naturalSize;
1871 // Make sure the model is up-to-date before layouting
1872 ProcessModifyEvents();
1874 if( mImpl->mRecalculateNaturalSize )
1876 // Operations that can be done only once until the text changes.
1877 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1884 GET_GLYPH_METRICS );
1886 // Set the update info to relayout the whole text.
1887 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1888 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1890 // Make sure the model is up-to-date before layouting
1891 mImpl->UpdateModel( onlyOnceOperations );
1893 // Layout the text for the new width.
1894 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1896 // Store the actual control's size to restore later.
1897 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1899 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1900 static_cast<OperationsMask>( onlyOnceOperations |
1902 naturalSize.GetVectorXY() );
1904 // Do not do again the only once operations.
1905 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1907 // Do the size related operations again.
1908 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1911 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1913 // Stores the natural size to avoid recalculate it again
1914 // unless the text/style changes.
1915 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1917 mImpl->mRecalculateNaturalSize = false;
1919 // Clear the update info. This info will be set the next time the text is updated.
1920 mImpl->mTextUpdateInfo.Clear();
1921 mImpl->mTextUpdateInfo.mClearAll = true;
1923 // Restore the actual control's size.
1924 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1926 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1930 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1932 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1935 naturalSize.x = ConvertToEven( naturalSize.x );
1936 naturalSize.y = ConvertToEven( naturalSize.y );
1941 float Controller::GetHeightForWidth( float width )
1943 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1944 // Make sure the model is up-to-date before layouting
1945 ProcessModifyEvents();
1948 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1949 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1950 mImpl->mTextUpdateInfo.mClearAll )
1952 // Operations that can be done only once until the text changes.
1953 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1960 GET_GLYPH_METRICS );
1962 // Set the update info to relayout the whole text.
1963 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1964 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1966 // Make sure the model is up-to-date before layouting
1967 mImpl->UpdateModel( onlyOnceOperations );
1970 // Layout the text for the new width.
1971 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1973 // Store the actual control's width.
1974 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1976 DoRelayout( Size( width, MAX_FLOAT ),
1977 static_cast<OperationsMask>( onlyOnceOperations |
1981 // Do not do again the only once operations.
1982 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1984 // Do the size related operations again.
1985 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1989 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1991 // Clear the update info. This info will be set the next time the text is updated.
1992 mImpl->mTextUpdateInfo.Clear();
1993 mImpl->mTextUpdateInfo.mClearAll = true;
1995 // Restore the actual control's width.
1996 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1998 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2002 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2003 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2006 return layoutSize.height;
2009 int Controller::GetLineCount( float width )
2011 GetHeightForWidth( width );
2012 int numberofLines = mImpl->mModel->GetNumberOfLines();
2013 return numberofLines;
2016 const ModelInterface* const Controller::GetTextModel() const
2018 return mImpl->mModel.Get();
2021 float Controller::GetScrollAmountByUserInput()
2023 float scrollAmount = 0.0f;
2025 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2027 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2028 mImpl->mEventData->mCheckScrollAmount = false;
2030 return scrollAmount;
2033 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2035 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2038 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2039 layoutHeight = layout.height;
2040 scrollPosition = mImpl->mModel->mScrollPosition.y;
2041 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2045 void Controller::SetHiddenInputOption(const Property::Map& options )
2047 if( NULL == mImpl->mHiddenInput )
2049 mImpl->mHiddenInput = new HiddenText( this );
2051 mImpl->mHiddenInput->SetProperties(options);
2054 void Controller::GetHiddenInputOption(Property::Map& options )
2056 if( NULL != mImpl->mHiddenInput )
2058 mImpl->mHiddenInput->GetProperties(options);
2062 void Controller::SetPlaceholderProperty( const Property::Map& map )
2064 const Property::Map::SizeType count = map.Count();
2066 for( Property::Map::SizeType position = 0; position < count; ++position )
2068 KeyValuePair keyValue = map.GetKeyValue( position );
2069 Property::Key& key = keyValue.first;
2070 Property::Value& value = keyValue.second;
2072 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2074 std::string text = "";
2076 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2078 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2080 std::string text = "";
2082 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2084 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2087 value.Get( textColor );
2088 if( GetPlaceholderTextColor() != textColor )
2090 SetPlaceholderTextColor( textColor );
2093 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2095 std::string fontFamily = "";
2096 value.Get( fontFamily );
2097 SetPlaceholderFontFamily( fontFamily );
2099 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2101 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2103 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2106 value.Get( pointSize );
2107 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2109 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2112 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2115 value.Get( pixelSize );
2116 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2118 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2121 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2124 value.Get( ellipsis );
2125 SetPlaceholderTextElideEnabled( ellipsis );
2130 void Controller::GetPlaceholderProperty( Property::Map& map )
2132 if( NULL != mImpl->mEventData )
2134 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2136 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2138 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2140 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2143 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2144 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2146 Property::Value fontStyleMapGet;
2147 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2148 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2150 // Choose font size : POINT_SIZE or PIXEL_SIZE
2151 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2153 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2157 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2160 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2162 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2167 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2169 // Make sure the model is up-to-date before layouting
2170 ProcessModifyEvents();
2172 if ( mImpl->mUpdateTextDirection )
2174 // Operations that can be done only once until the text changes.
2175 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2182 GET_GLYPH_METRICS );
2184 // Set the update info to relayout the whole text.
2185 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2186 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2188 // Make sure the model is up-to-date before layouting
2189 mImpl->UpdateModel( onlyOnceOperations );
2191 Vector3 naturalSize;
2192 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2193 static_cast<OperationsMask>( onlyOnceOperations |
2194 LAYOUT | REORDER | UPDATE_DIRECTION ),
2195 naturalSize.GetVectorXY() );
2197 // Do not do again the only once operations.
2198 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2200 // Clear the update info. This info will be set the next time the text is updated.
2201 mImpl->mTextUpdateInfo.Clear();
2203 mImpl->mUpdateTextDirection = false;
2206 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2209 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2211 return mImpl->mModel->GetVerticalLineAlignment();
2214 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2216 mImpl->mModel->mVerticalLineAlignment = alignment;
2219 // public : Relayout.
2221 Controller::UpdateTextType Controller::Relayout( const Size& size )
2223 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2225 UpdateTextType updateTextType = NONE_UPDATED;
2227 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2229 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2231 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2232 updateTextType = MODEL_UPDATED;
2235 // Clear the update info. This info will be set the next time the text is updated.
2236 mImpl->mTextUpdateInfo.Clear();
2238 // Not worth to relayout if width or height is equal to zero.
2239 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2241 return updateTextType;
2244 // Whether a new size has been set.
2245 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2249 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2251 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2252 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2253 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2255 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2258 // Layout operations that need to be done if the size changes.
2259 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2262 UPDATE_LAYOUT_SIZE |
2264 // Set the update info to relayout the whole text.
2265 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2266 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2268 // Store the size used to layout the text.
2269 mImpl->mModel->mVisualModel->mControlSize = size;
2272 // Whether there are modify events.
2273 if( 0u != mImpl->mModifyEvents.Count() )
2275 // Style operations that need to be done if the text is modified.
2276 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2280 // Set the update info to elide the text.
2281 if( mImpl->mModel->mElideEnabled ||
2282 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2284 // Update Text layout for applying elided
2285 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2288 UPDATE_LAYOUT_SIZE |
2290 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2291 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2294 // Make sure the model is up-to-date before layouting.
2295 ProcessModifyEvents();
2296 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2300 updated = DoRelayout( size,
2301 mImpl->mOperationsPending,
2302 layoutSize ) || updated;
2306 updateTextType = MODEL_UPDATED;
2309 // Do not re-do any operation until something changes.
2310 mImpl->mOperationsPending = NO_OPERATION;
2311 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2313 // Whether the text control is editable
2314 const bool isEditable = NULL != mImpl->mEventData;
2316 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2318 if( newSize && isEditable )
2320 offset = mImpl->mModel->mScrollPosition;
2323 if( !isEditable || !IsMultiLineEnabled() )
2325 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2326 CalculateVerticalOffset( size );
2333 // If there is a new size, the scroll position needs to be clamped.
2334 mImpl->ClampHorizontalScroll( layoutSize );
2336 // Update the decorator's positions is needed if there is a new size.
2337 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2340 // Move the cursor, grab handle etc.
2341 if( mImpl->ProcessInputEvents() )
2343 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2347 // Clear the update info. This info will be set the next time the text is updated.
2348 mImpl->mTextUpdateInfo.Clear();
2349 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2351 return updateTextType;
2354 void Controller::RequestRelayout()
2356 mImpl->RequestRelayout();
2359 // public : Input style change signals.
2361 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2363 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2366 void Controller::ProcessInputStyleChangedSignals()
2368 if( NULL == mImpl->mEventData )
2374 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2375 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2379 const InputStyle::Mask mask = *it;
2381 if( NULL != mImpl->mEditableControlInterface )
2383 // Emit the input style changed signal.
2384 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2388 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2391 // public : Text-input Event Queuing.
2393 void Controller::KeyboardFocusGainEvent()
2395 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2397 if( NULL != mImpl->mEventData )
2399 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2400 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2402 mImpl->ChangeState( EventData::EDITING );
2403 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2404 mImpl->mEventData->mUpdateInputStyle = true;
2406 mImpl->NotifyInputMethodContextMultiLineStatus();
2407 if( mImpl->IsShowingPlaceholderText() )
2409 // Show alternative placeholder-text when editing
2410 ShowPlaceholderText();
2413 mImpl->RequestRelayout();
2417 void Controller::KeyboardFocusLostEvent()
2419 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2421 if( NULL != mImpl->mEventData )
2423 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2425 mImpl->ChangeState( EventData::INACTIVE );
2427 if( !mImpl->IsShowingRealText() )
2429 // Revert to regular placeholder-text when not editing
2430 ShowPlaceholderText();
2434 mImpl->RequestRelayout();
2437 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2439 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2441 bool textChanged = false;
2442 bool relayoutNeeded = false;
2444 if( ( NULL != mImpl->mEventData ) &&
2445 ( keyEvent.state == KeyEvent::Down ) )
2447 int keyCode = keyEvent.keyCode;
2448 const std::string& keyString = keyEvent.keyPressed;
2449 const std::string keyName = keyEvent.keyPressedName;
2451 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2453 // Pre-process to separate modifying events from non-modifying input events.
2456 // In some platforms arrive key events with no key code.
2460 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2465 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2466 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2467 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2468 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2470 // If don't have any text, do nothing.
2471 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2476 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2477 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2478 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2479 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2481 // Logic to determine whether this text control will lose focus or not.
2482 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2483 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2484 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2485 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2486 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2487 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2489 // Release the active highlight.
2490 if( mImpl->mEventData->mState == EventData::SELECTING )
2492 mImpl->ChangeState( EventData::EDITING );
2494 // Update selection position.
2495 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2496 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2497 mImpl->mEventData->mUpdateCursorPosition = true;
2498 mImpl->RequestRelayout();
2503 mImpl->mEventData->mCheckScrollAmount = true;
2504 Event event( Event::CURSOR_KEY_EVENT );
2505 event.p1.mInt = keyCode;
2506 event.p2.mBool = keyEvent.IsShiftModifier();
2507 mImpl->mEventData->mEventQueue.push_back( event );
2509 // Will request for relayout.
2510 relayoutNeeded = true;
2512 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2514 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2515 // If not handle it here, any selected text will be deleted
2520 else if ( keyEvent.IsCtrlModifier() )
2522 bool consumed = false;
2523 if (keyName == KEY_C_NAME)
2525 // Ctrl-C to copy the selected text
2526 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2529 else if (keyName == KEY_V_NAME)
2531 // Ctrl-V to paste the copied text
2532 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2535 else if (keyName == KEY_X_NAME)
2537 // Ctrl-X to cut the selected text
2538 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2543 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2544 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2546 textChanged = DeleteEvent( keyCode );
2548 // Will request for relayout.
2549 relayoutNeeded = true;
2551 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2552 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2553 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2555 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2556 mImpl->ChangeState( EventData::INACTIVE );
2558 // Will request for relayout.
2559 relayoutNeeded = true;
2561 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2563 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2565 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the InputMethodContext?) when the predictive text is enabled
2566 // and a character is typed after the type of a upper case latin character.
2571 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2573 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2579 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2581 // InputMethodContext is no longer handling key-events
2582 mImpl->ClearPreEditFlag();
2584 InsertText( keyString, COMMIT );
2587 // Will request for relayout.
2588 relayoutNeeded = true;
2591 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2592 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2594 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2595 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2596 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2598 // Should not change the state if the key is the shift send by the InputMethodContext.
2599 // Otherwise, when the state is SELECTING the text controller can't send the right
2600 // surrounding info to the InputMethodContext.
2601 mImpl->ChangeState( EventData::EDITING );
2603 // Will request for relayout.
2604 relayoutNeeded = true;
2607 if( relayoutNeeded )
2609 mImpl->RequestRelayout();
2614 ( NULL != mImpl->mEditableControlInterface ) )
2616 // Do this last since it provides callbacks into application code
2617 mImpl->mEditableControlInterface->TextChanged();
2623 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2625 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2627 if( NULL != mImpl->mEventData )
2629 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2630 EventData::State state( mImpl->mEventData->mState );
2631 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2633 if( mImpl->IsClipboardVisible() )
2635 if( EventData::INACTIVE == state || EventData::EDITING == state)
2637 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2639 relayoutNeeded = true;
2641 else if( 1u == tapCount )
2643 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2645 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2648 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2650 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2651 relayoutNeeded = true;
2655 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2657 // Hide placeholder text
2661 if( EventData::INACTIVE == state )
2663 mImpl->ChangeState( EventData::EDITING );
2665 else if( !mImpl->IsClipboardEmpty() )
2667 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2669 relayoutNeeded = true;
2672 else if( 2u == tapCount )
2674 if( mImpl->mEventData->mSelectionEnabled &&
2675 mImpl->IsShowingRealText() )
2677 relayoutNeeded = true;
2678 mImpl->mEventData->mIsLeftHandleSelected = true;
2679 mImpl->mEventData->mIsRightHandleSelected = true;
2683 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2684 if( relayoutNeeded )
2686 Event event( Event::TAP_EVENT );
2687 event.p1.mUint = tapCount;
2688 event.p2.mFloat = x;
2689 event.p3.mFloat = y;
2690 mImpl->mEventData->mEventQueue.push_back( event );
2692 mImpl->RequestRelayout();
2696 // Reset keyboard as tap event has occurred.
2697 mImpl->ResetInputMethodContext();
2700 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2702 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2704 if( NULL != mImpl->mEventData )
2706 Event event( Event::PAN_EVENT );
2707 event.p1.mInt = state;
2708 event.p2.mFloat = displacement.x;
2709 event.p3.mFloat = displacement.y;
2710 mImpl->mEventData->mEventQueue.push_back( event );
2712 mImpl->RequestRelayout();
2716 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2718 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2720 if( ( state == Gesture::Started ) &&
2721 ( NULL != mImpl->mEventData ) )
2723 // The 1st long-press on inactive text-field is treated as tap
2724 if( EventData::INACTIVE == mImpl->mEventData->mState )
2726 mImpl->ChangeState( EventData::EDITING );
2728 Event event( Event::TAP_EVENT );
2730 event.p2.mFloat = x;
2731 event.p3.mFloat = y;
2732 mImpl->mEventData->mEventQueue.push_back( event );
2734 mImpl->RequestRelayout();
2736 else if( !mImpl->IsShowingRealText() )
2738 Event event( Event::LONG_PRESS_EVENT );
2739 event.p1.mInt = state;
2740 event.p2.mFloat = x;
2741 event.p3.mFloat = y;
2742 mImpl->mEventData->mEventQueue.push_back( event );
2743 mImpl->RequestRelayout();
2745 else if( !mImpl->IsClipboardVisible() )
2747 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
2748 mImpl->ResetInputMethodContext();
2750 Event event( Event::LONG_PRESS_EVENT );
2751 event.p1.mInt = state;
2752 event.p2.mFloat = x;
2753 event.p3.mFloat = y;
2754 mImpl->mEventData->mEventQueue.push_back( event );
2755 mImpl->RequestRelayout();
2757 mImpl->mEventData->mIsLeftHandleSelected = true;
2758 mImpl->mEventData->mIsRightHandleSelected = true;
2763 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
2765 // Whether the text needs to be relaid-out.
2766 bool requestRelayout = false;
2768 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
2769 bool retrieveText = false;
2770 bool retrieveCursor = false;
2772 switch( inputMethodContextEvent.eventName )
2774 case InputMethodContext::COMMIT:
2776 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
2777 requestRelayout = true;
2778 retrieveCursor = true;
2781 case InputMethodContext::PRE_EDIT:
2783 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
2784 requestRelayout = true;
2785 retrieveCursor = true;
2788 case InputMethodContext::DELETE_SURROUNDING:
2790 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
2791 inputMethodContextEvent.numberOfChars,
2792 DONT_UPDATE_INPUT_STYLE );
2796 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2797 !mImpl->IsPlaceholderAvailable() )
2799 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2803 ShowPlaceholderText();
2805 mImpl->mEventData->mUpdateCursorPosition = true;
2806 mImpl->mEventData->mScrollAfterDelete = true;
2808 requestRelayout = true;
2812 case InputMethodContext::GET_SURROUNDING:
2814 retrieveText = true;
2815 retrieveCursor = true;
2818 case InputMethodContext::PRIVATE_COMMAND:
2820 // PRIVATECOMMAND event is just for getting the private command message
2821 retrieveText = true;
2822 retrieveCursor = true;
2825 case InputMethodContext::VOID:
2832 if( requestRelayout )
2834 mImpl->mOperationsPending = ALL_OPERATIONS;
2835 mImpl->RequestRelayout();
2839 CharacterIndex cursorPosition = 0u;
2840 Length numberOfWhiteSpaces = 0u;
2842 if( retrieveCursor )
2844 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2846 cursorPosition = mImpl->GetLogicalCursorPosition();
2848 if( cursorPosition < numberOfWhiteSpaces )
2850 cursorPosition = 0u;
2854 cursorPosition -= numberOfWhiteSpaces;
2860 if( !mImpl->IsShowingPlaceholderText() )
2862 // Retrieves the normal text string.
2863 mImpl->GetText( numberOfWhiteSpaces, text );
2867 // When the current text is Placeholder Text, the surrounding text should be empty string.
2868 // It means DALi should send empty string ("") to IME.
2873 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2875 if( requestRelayout &&
2876 ( NULL != mImpl->mEditableControlInterface ) )
2878 // Do this last since it provides callbacks into application code
2879 mImpl->mEditableControlInterface->TextChanged();
2882 return callbackData;
2885 void Controller::PasteClipboardItemEvent()
2887 // Retrieve the clipboard contents first
2888 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2889 std::string stringToPaste( notifier.GetContent() );
2891 // Commit the current pre-edit text; the contents of the clipboard should be appended
2892 mImpl->ResetInputMethodContext();
2894 // Temporary disable hiding clipboard
2895 mImpl->SetClipboardHideEnable( false );
2898 PasteText( stringToPaste );
2900 mImpl->SetClipboardHideEnable( true );
2903 // protected : Inherit from Text::Decorator::ControllerInterface.
2905 void Controller::GetTargetSize( Vector2& targetSize )
2907 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2910 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2912 if( NULL != mImpl->mEditableControlInterface )
2914 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2918 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2920 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2922 if( NULL != mImpl->mEventData )
2924 switch( handleType )
2928 Event event( Event::GRAB_HANDLE_EVENT );
2929 event.p1.mUint = state;
2930 event.p2.mFloat = x;
2931 event.p3.mFloat = y;
2933 mImpl->mEventData->mEventQueue.push_back( event );
2936 case LEFT_SELECTION_HANDLE:
2938 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2939 event.p1.mUint = state;
2940 event.p2.mFloat = x;
2941 event.p3.mFloat = y;
2943 mImpl->mEventData->mEventQueue.push_back( event );
2946 case RIGHT_SELECTION_HANDLE:
2948 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2949 event.p1.mUint = state;
2950 event.p2.mFloat = x;
2951 event.p3.mFloat = y;
2953 mImpl->mEventData->mEventQueue.push_back( event );
2956 case LEFT_SELECTION_HANDLE_MARKER:
2957 case RIGHT_SELECTION_HANDLE_MARKER:
2959 // Markers do not move the handles.
2962 case HANDLE_TYPE_COUNT:
2964 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2968 mImpl->RequestRelayout();
2972 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2974 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2976 if( NULL == mImpl->mEventData )
2983 case Toolkit::TextSelectionPopup::CUT:
2985 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2986 mImpl->mOperationsPending = ALL_OPERATIONS;
2988 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2989 !mImpl->IsPlaceholderAvailable() )
2991 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2995 ShowPlaceholderText();
2998 mImpl->mEventData->mUpdateCursorPosition = true;
2999 mImpl->mEventData->mScrollAfterDelete = true;
3001 mImpl->RequestRelayout();
3003 if( NULL != mImpl->mEditableControlInterface )
3005 mImpl->mEditableControlInterface->TextChanged();
3009 case Toolkit::TextSelectionPopup::COPY:
3011 mImpl->SendSelectionToClipboard( false ); // Text not modified
3013 mImpl->mEventData->mUpdateCursorPosition = true;
3015 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3018 case Toolkit::TextSelectionPopup::PASTE:
3020 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3023 case Toolkit::TextSelectionPopup::SELECT:
3025 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3027 if( mImpl->mEventData->mSelectionEnabled )
3029 // Creates a SELECT event.
3030 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3034 case Toolkit::TextSelectionPopup::SELECT_ALL:
3036 // Creates a SELECT_ALL event
3037 SelectEvent( 0.f, 0.f, true );
3040 case Toolkit::TextSelectionPopup::CLIPBOARD:
3042 mImpl->ShowClipboard();
3045 case Toolkit::TextSelectionPopup::NONE:
3053 void Controller::DisplayTimeExpired()
3055 mImpl->mEventData->mUpdateCursorPosition = true;
3056 // Apply modifications to the model
3057 mImpl->mOperationsPending = ALL_OPERATIONS;
3059 mImpl->RequestRelayout();
3062 // private : Update.
3064 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3066 bool removedPrevious = false;
3067 bool removedSelected = false;
3068 bool maxLengthReached = false;
3070 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3072 if( NULL == mImpl->mEventData )
3077 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3078 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3079 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3081 // TODO: At the moment the underline runs are only for pre-edit.
3082 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3084 // Remove the previous InputMethodContext pre-edit.
3085 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3087 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3088 mImpl->mEventData->mPreEditLength,
3089 DONT_UPDATE_INPUT_STYLE );
3091 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3092 mImpl->mEventData->mPreEditLength = 0u;
3096 // Remove the previous Selection.
3097 removedSelected = RemoveSelectedText();
3101 Vector<Character> utf32Characters;
3102 Length characterCount = 0u;
3106 // Convert text into UTF-32
3107 utf32Characters.Resize( text.size() );
3109 // This is a bit horrible but std::string returns a (signed) char*
3110 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3112 // Transform a text array encoded in utf8 into an array encoded in utf32.
3113 // It returns the actual number of characters.
3114 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3115 utf32Characters.Resize( characterCount );
3117 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3118 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3121 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3123 // The placeholder text is no longer needed
3124 if( mImpl->IsShowingPlaceholderText() )
3129 mImpl->ChangeState( EventData::EDITING );
3131 // Handle the InputMethodContext (predicitive text) state changes
3132 if( COMMIT == type )
3134 // InputMethodContext is no longer handling key-events
3135 mImpl->ClearPreEditFlag();
3139 if( !mImpl->mEventData->mPreEditFlag )
3141 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3143 // Record the start of the pre-edit text
3144 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3147 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3148 mImpl->mEventData->mPreEditFlag = true;
3150 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3153 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3155 // Restrict new text to fit within Maximum characters setting.
3156 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3157 maxLengthReached = ( characterCount > maxSizeOfNewText );
3159 // The cursor position.
3160 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3162 // Update the text's style.
3164 // Updates the text style runs by adding characters.
3165 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3167 // Get the character index from the cursor index.
3168 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3170 // Retrieve the text's style for the given index.
3172 mImpl->RetrieveDefaultInputStyle( style );
3173 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3175 // Whether to add a new text color run.
3176 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3178 // Whether to add a new font run.
3179 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3180 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3181 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3182 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3183 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3188 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3189 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3191 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3192 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3193 colorRun.characterRun.characterIndex = cursorIndex;
3194 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3197 if( addFontNameRun ||
3203 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3204 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3206 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3208 if( addFontNameRun )
3210 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3211 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3212 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3213 fontDescriptionRun.familyDefined = true;
3215 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3218 if( addFontWeightRun )
3220 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3221 fontDescriptionRun.weightDefined = true;
3224 if( addFontWidthRun )
3226 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3227 fontDescriptionRun.widthDefined = true;
3230 if( addFontSlantRun )
3232 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3233 fontDescriptionRun.slantDefined = true;
3236 if( addFontSizeRun )
3238 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3239 fontDescriptionRun.sizeDefined = true;
3242 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3243 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3246 // Insert at current cursor position.
3247 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3249 if( cursorIndex < numberOfCharactersInModel )
3251 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3255 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3258 // Mark the first paragraph to be updated.
3259 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3261 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3262 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3263 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3264 mImpl->mTextUpdateInfo.mClearAll = true;
3268 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3269 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3272 // Update the cursor index.
3273 cursorIndex += maxSizeOfNewText;
3275 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 );
3278 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3279 mImpl->IsPlaceholderAvailable() )
3281 // Show place-holder if empty after removing the pre-edit text
3282 ShowPlaceholderText();
3283 mImpl->mEventData->mUpdateCursorPosition = true;
3284 mImpl->ClearPreEditFlag();
3286 else if( removedPrevious ||
3288 ( 0 != utf32Characters.Count() ) )
3290 // Queue an inserted event
3291 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3293 mImpl->mEventData->mUpdateCursorPosition = true;
3294 if( removedSelected )
3296 mImpl->mEventData->mScrollAfterDelete = true;
3300 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3304 if( maxLengthReached )
3306 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3308 mImpl->ResetInputMethodContext();
3310 if( NULL != mImpl->mEditableControlInterface )
3312 // Do this last since it provides callbacks into application code
3313 mImpl->mEditableControlInterface->MaxLengthReached();
3318 void Controller::PasteText( const std::string& stringToPaste )
3320 InsertText( stringToPaste, Text::Controller::COMMIT );
3321 mImpl->ChangeState( EventData::EDITING );
3322 mImpl->RequestRelayout();
3324 if( NULL != mImpl->mEditableControlInterface )
3326 // Do this last since it provides callbacks into application code
3327 mImpl->mEditableControlInterface->TextChanged();
3331 bool Controller::RemoveText( int cursorOffset,
3332 int numberOfCharacters,
3333 UpdateInputStyleType type )
3335 bool removed = false;
3337 if( NULL == mImpl->mEventData )
3342 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3343 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3345 if( !mImpl->IsShowingPlaceholderText() )
3347 // Delete at current cursor position
3348 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3349 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3351 CharacterIndex cursorIndex = 0;
3353 // Validate the cursor position & number of characters
3354 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3356 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3359 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3361 numberOfCharacters = currentText.Count() - cursorIndex;
3364 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.
3365 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3367 // Mark the paragraphs to be updated.
3368 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3370 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3371 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3372 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3373 mImpl->mTextUpdateInfo.mClearAll = true;
3377 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3378 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3381 // Update the input style and remove the text's style before removing the text.
3383 if( UPDATE_INPUT_STYLE == type )
3385 // Keep a copy of the current input style.
3386 InputStyle currentInputStyle;
3387 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3389 // Set first the default input style.
3390 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3392 // Update the input style.
3393 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3395 // Compare if the input style has changed.
3396 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3398 if( hasInputStyleChanged )
3400 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3401 // Queue the input style changed signal.
3402 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3406 // Updates the text style runs by removing characters. Runs with no characters are removed.
3407 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3409 // Remove the characters.
3410 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3411 Vector<Character>::Iterator last = first + numberOfCharacters;
3413 currentText.Erase( first, last );
3415 // Cursor position retreat
3416 oldCursorIndex = cursorIndex;
3418 mImpl->mEventData->mScrollAfterDelete = true;
3420 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3428 bool Controller::RemoveSelectedText()
3430 bool textRemoved( false );
3432 if( EventData::SELECTING == mImpl->mEventData->mState )
3434 std::string removedString;
3435 mImpl->RetrieveSelection( removedString, true );
3437 if( !removedString.empty() )
3440 mImpl->ChangeState( EventData::EDITING );
3447 // private : Relayout.
3449 bool Controller::DoRelayout( const Size& size,
3450 OperationsMask operationsRequired,
3453 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3454 bool viewUpdated( false );
3456 // Calculate the operations to be done.
3457 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3459 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3460 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3462 // Get the current layout size.
3463 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3465 if( NO_OPERATION != ( LAYOUT & operations ) )
3467 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3469 // Some vectors with data needed to layout and reorder may be void
3470 // after the first time the text has been laid out.
3471 // Fill the vectors again.
3473 // Calculate the number of glyphs to layout.
3474 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3475 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3476 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3477 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3479 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3480 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3482 // Make sure the index is not out of bound
3483 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3484 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3485 ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3487 std::string currentText;
3488 GetText( currentText );
3490 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3491 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3492 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3497 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3498 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3500 if( 0u == totalNumberOfGlyphs )
3502 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3504 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3507 // Nothing else to do if there is no glyphs.
3508 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3512 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3513 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3514 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3515 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3516 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3517 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3518 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3519 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3521 // Set the layout parameters.
3522 const Vector2 sizeOffset = Vector2(outlineWidth * 2.0f, outlineWidth * 2.0f); // The outline should be fit into the bounding box
3523 Layout::Parameters layoutParameters( size - sizeOffset,
3525 lineBreakInfo.Begin(),
3526 wordBreakInfo.Begin(),
3527 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3529 glyphsToCharactersMap.Begin(),
3530 charactersPerGlyph.Begin(),
3531 charactersToGlyphBuffer,
3532 glyphsPerCharacterBuffer,
3533 totalNumberOfGlyphs,
3534 mImpl->mModel->mHorizontalAlignment,
3535 mImpl->mModel->mLineWrapMode,
3538 // Resize the vector of positions to have the same size than the vector of glyphs.
3539 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3540 glyphPositions.Resize( totalNumberOfGlyphs );
3542 // Whether the last character is a new paragraph character.
3543 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3544 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3546 // The initial glyph and the number of glyphs to layout.
3547 layoutParameters.startGlyphIndex = startGlyphIndex;
3548 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3549 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3550 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3552 // Update the ellipsis
3553 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3555 if( NULL != mImpl->mEventData )
3557 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3559 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3561 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3563 // Disable ellipsis when editing
3564 elideTextEnabled = false;
3567 // Reset the scroll position in inactive state
3568 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3570 ResetScrollPosition();
3574 // Update the visual model.
3576 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3578 mImpl->mModel->mVisualModel->mLines,
3582 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3586 layoutSize = newLayoutSize;
3588 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3590 mImpl->mIsTextDirectionRTL = false;
3593 // Reorder the lines
3594 if( NO_OPERATION != ( REORDER & operations ) )
3596 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3597 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3599 // Check first if there are paragraphs with bidirectional info.
3600 if( 0u != bidirectionalInfo.Count() )
3603 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3605 // Reorder the lines.
3606 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3607 ReorderLines( bidirectionalInfo,
3609 requestedNumberOfCharacters,
3610 mImpl->mModel->mVisualModel->mLines,
3611 bidirectionalLineInfo );
3613 // Set the bidirectional info per line into the layout parameters.
3614 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3615 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3617 // Re-layout the text. Reorder those lines with right to left characters.
3618 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3620 requestedNumberOfCharacters,
3623 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3625 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3628 mImpl->mIsTextDirectionRTL = firstline->direction;
3634 // Sets the layout size.
3635 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3637 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3642 if( NO_OPERATION != ( ALIGN & operations ) )
3644 // The laid-out lines.
3645 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3647 // Need to align with the control's size as the text may contain lines
3648 // starting either with left to right text or right to left.
3649 mImpl->mLayoutEngine.Align( size,
3651 requestedNumberOfCharacters,
3652 mImpl->mModel->mHorizontalAlignment,
3654 mImpl->mModel->mAlignmentOffset );
3658 #if defined(DEBUG_ENABLED)
3659 std::string currentText;
3660 GetText( currentText );
3661 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3663 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3667 void Controller::CalculateVerticalOffset( const Size& controlSize )
3669 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3671 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3673 // Get the line height of the default font.
3674 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3677 switch( mImpl->mModel->mVerticalAlignment )
3679 case VerticalAlignment::TOP:
3681 mImpl->mModel->mScrollPosition.y = 0.f;
3684 case VerticalAlignment::CENTER:
3686 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3689 case VerticalAlignment::BOTTOM:
3691 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3697 // private : Events.
3699 void Controller::ProcessModifyEvents()
3701 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3703 if( 0u == events.Count() )
3709 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3710 endIt = events.End();
3714 const ModifyEvent& event = *it;
3716 if( ModifyEvent::TEXT_REPLACED == event.type )
3718 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3719 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3721 TextReplacedEvent();
3723 else if( ModifyEvent::TEXT_INSERTED == event.type )
3725 TextInsertedEvent();
3727 else if( ModifyEvent::TEXT_DELETED == event.type )
3729 // Placeholder-text cannot be deleted
3730 if( !mImpl->IsShowingPlaceholderText() )
3737 if( NULL != mImpl->mEventData )
3739 // When the text is being modified, delay cursor blinking
3740 mImpl->mEventData->mDecorator->DelayCursorBlink();
3742 // Update selection position after modifying the text
3743 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3744 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3747 // Discard temporary text
3751 void Controller::TextReplacedEvent()
3753 // The natural size needs to be re-calculated.
3754 mImpl->mRecalculateNaturalSize = true;
3756 // The text direction needs to be updated.
3757 mImpl->mUpdateTextDirection = true;
3759 // Apply modifications to the model
3760 mImpl->mOperationsPending = ALL_OPERATIONS;
3763 void Controller::TextInsertedEvent()
3765 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3767 if( NULL == mImpl->mEventData )
3772 mImpl->mEventData->mCheckScrollAmount = true;
3774 // The natural size needs to be re-calculated.
3775 mImpl->mRecalculateNaturalSize = true;
3777 // The text direction needs to be updated.
3778 mImpl->mUpdateTextDirection = true;
3780 // Apply modifications to the model; TODO - Optimize this
3781 mImpl->mOperationsPending = ALL_OPERATIONS;
3784 void Controller::TextDeletedEvent()
3786 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3788 if( NULL == mImpl->mEventData )
3793 mImpl->mEventData->mCheckScrollAmount = true;
3795 // The natural size needs to be re-calculated.
3796 mImpl->mRecalculateNaturalSize = true;
3798 // The text direction needs to be updated.
3799 mImpl->mUpdateTextDirection = true;
3801 // Apply modifications to the model; TODO - Optimize this
3802 mImpl->mOperationsPending = ALL_OPERATIONS;
3805 void Controller::SelectEvent( float x, float y, bool selectAll )
3807 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3809 if( NULL != mImpl->mEventData )
3813 Event event( Event::SELECT_ALL );
3814 mImpl->mEventData->mEventQueue.push_back( event );
3818 Event event( Event::SELECT );
3819 event.p2.mFloat = x;
3820 event.p3.mFloat = y;
3821 mImpl->mEventData->mEventQueue.push_back( event );
3824 mImpl->mEventData->mCheckScrollAmount = true;
3825 mImpl->mEventData->mIsLeftHandleSelected = true;
3826 mImpl->mEventData->mIsRightHandleSelected = true;
3827 mImpl->RequestRelayout();
3831 bool Controller::DeleteEvent( int keyCode )
3833 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3835 bool removed = false;
3837 if( NULL == mImpl->mEventData )
3842 // InputMethodContext is no longer handling key-events
3843 mImpl->ClearPreEditFlag();
3845 if( EventData::SELECTING == mImpl->mEventData->mState )
3847 removed = RemoveSelectedText();
3849 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3851 // Remove the character before the current cursor position
3852 removed = RemoveText( -1,
3854 UPDATE_INPUT_STYLE );
3856 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
3858 // Remove the character after the current cursor position
3859 removed = RemoveText( 0,
3861 UPDATE_INPUT_STYLE );
3866 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3867 !mImpl->IsPlaceholderAvailable() )
3869 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3873 ShowPlaceholderText();
3875 mImpl->mEventData->mUpdateCursorPosition = true;
3876 mImpl->mEventData->mScrollAfterDelete = true;
3882 // private : Helpers.
3884 void Controller::ResetText()
3887 mImpl->mModel->mLogicalModel->mText.Clear();
3889 // We have cleared everything including the placeholder-text
3890 mImpl->PlaceholderCleared();
3892 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3893 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3894 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3896 // Clear any previous text.
3897 mImpl->mTextUpdateInfo.mClearAll = true;
3899 // The natural size needs to be re-calculated.
3900 mImpl->mRecalculateNaturalSize = true;
3902 // The text direction needs to be updated.
3903 mImpl->mUpdateTextDirection = true;
3905 // Apply modifications to the model
3906 mImpl->mOperationsPending = ALL_OPERATIONS;
3909 void Controller::ShowPlaceholderText()
3911 if( mImpl->IsPlaceholderAvailable() )
3913 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3915 if( NULL == mImpl->mEventData )
3920 mImpl->mEventData->mIsShowingPlaceholderText = true;
3922 // Disable handles when showing place-holder text
3923 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3924 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3925 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3927 const char* text( NULL );
3930 // TODO - Switch Placeholder text when changing state
3931 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3932 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3934 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3935 size = mImpl->mEventData->mPlaceholderTextActive.size();
3939 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3940 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3943 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3944 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3946 // Reset model for showing placeholder.
3947 mImpl->mModel->mLogicalModel->mText.Clear();
3948 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3950 // Convert text into UTF-32
3951 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3952 utf32Characters.Resize( size );
3954 // This is a bit horrible but std::string returns a (signed) char*
3955 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3957 // Transform a text array encoded in utf8 into an array encoded in utf32.
3958 // It returns the actual number of characters.
3959 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3960 utf32Characters.Resize( characterCount );
3962 // The characters to be added.
3963 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3965 // Reset the cursor position
3966 mImpl->mEventData->mPrimaryCursorPosition = 0;
3968 // The natural size needs to be re-calculated.
3969 mImpl->mRecalculateNaturalSize = true;
3971 // The text direction needs to be updated.
3972 mImpl->mUpdateTextDirection = true;
3974 // Apply modifications to the model
3975 mImpl->mOperationsPending = ALL_OPERATIONS;
3977 // Update the rest of the model during size negotiation
3978 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3982 void Controller::ClearFontData()
3984 if( mImpl->mFontDefaults )
3986 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3989 // Set flags to update the model.
3990 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3991 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3992 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3994 mImpl->mTextUpdateInfo.mClearAll = true;
3995 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3996 mImpl->mRecalculateNaturalSize = true;
3998 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4004 UPDATE_LAYOUT_SIZE |
4009 void Controller::ClearStyleData()
4011 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4012 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4015 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4017 // Reset the cursor position
4018 if( NULL != mImpl->mEventData )
4020 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4022 // Update the cursor if it's in editing mode.
4023 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4025 mImpl->mEventData->mUpdateCursorPosition = true;
4030 void Controller::ResetScrollPosition()
4032 if( NULL != mImpl->mEventData )
4034 // Reset the scroll position.
4035 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4036 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4040 void Controller::SetControlInterface( ControlInterface* controlInterface )
4042 mImpl->mControlInterface = controlInterface;
4045 bool Controller::ShouldClearFocusOnEscape() const
4047 return mImpl->mShouldClearFocusOnEscape;
4050 // private : Private contructors & copy operator.
4052 Controller::Controller()
4055 mImpl = new Controller::Impl( NULL, NULL );
4058 Controller::Controller( ControlInterface* controlInterface )
4060 mImpl = new Controller::Impl( controlInterface, NULL );
4063 Controller::Controller( ControlInterface* controlInterface,
4064 EditableControlInterface* editableControlInterface )
4066 mImpl = new Controller::Impl( controlInterface,
4067 editableControlInterface );
4070 // The copy constructor and operator are left unimplemented.
4072 // protected : Destructor.
4074 Controller::~Controller()
4081 } // namespace Toolkit