2 * Copyright (c) 2017 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 )
145 delete mImpl->mEventData;
146 mImpl->mEventData = NULL;
148 // Nothing else to do.
152 if( NULL == mImpl->mEventData )
154 mImpl->mEventData = new EventData( decorator );
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 mImpl->mMarkupProcessorEnabled = enable;
174 bool Controller::IsMarkupProcessorEnabled() const
176 return mImpl->mMarkupProcessorEnabled;
179 void Controller::SetAutoScrollEnabled( bool enable )
181 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 );
183 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
187 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
188 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
198 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
199 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
206 mImpl->mIsAutoScrollEnabled = enable;
207 mImpl->RequestRelayout();
211 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
212 mImpl->mIsAutoScrollEnabled = false;
216 bool Controller::IsAutoScrollEnabled() const
218 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
220 return mImpl->mIsAutoScrollEnabled;
223 CharacterDirection Controller::GetAutoScrollDirection() const
225 return mImpl->mAutoScrollDirectionRTL;
228 float Controller::GetAutoScrollLineAlignment() const
232 if( mImpl->mModel->mVisualModel &&
233 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
235 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
241 void Controller::SetHorizontalScrollEnabled( bool enable )
243 if( ( NULL != mImpl->mEventData ) &&
244 mImpl->mEventData->mDecorator )
246 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
249 bool Controller::IsHorizontalScrollEnabled() const
251 if( ( NULL != mImpl->mEventData ) &&
252 mImpl->mEventData->mDecorator )
254 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
260 void Controller::SetVerticalScrollEnabled( bool enable )
262 if( ( NULL != mImpl->mEventData ) &&
263 mImpl->mEventData->mDecorator )
265 if( mImpl->mEventData->mDecorator )
267 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
272 bool Controller::IsVerticalScrollEnabled() const
274 if( ( NULL != mImpl->mEventData ) &&
275 mImpl->mEventData->mDecorator )
277 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
283 void Controller::SetSmoothHandlePanEnabled( bool enable )
285 if( ( NULL != mImpl->mEventData ) &&
286 mImpl->mEventData->mDecorator )
288 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
292 bool Controller::IsSmoothHandlePanEnabled() const
294 if( ( NULL != mImpl->mEventData ) &&
295 mImpl->mEventData->mDecorator )
297 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
303 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
305 mImpl->mMaximumNumberOfCharacters = maxCharacters;
308 int Controller::GetMaximumNumberOfCharacters()
310 return mImpl->mMaximumNumberOfCharacters;
313 void Controller::SetEnableCursorBlink( bool enable )
315 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
317 if( NULL != mImpl->mEventData )
319 mImpl->mEventData->mCursorBlinkEnabled = enable;
322 mImpl->mEventData->mDecorator )
324 mImpl->mEventData->mDecorator->StopCursorBlink();
329 bool Controller::GetEnableCursorBlink() const
331 if( NULL != mImpl->mEventData )
333 return mImpl->mEventData->mCursorBlinkEnabled;
339 void Controller::SetMultiLineEnabled( bool enable )
341 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
343 if( layout != mImpl->mLayoutEngine.GetLayout() )
345 // Set the layout type.
346 mImpl->mLayoutEngine.SetLayout( layout );
348 // Set the flags to redo the layout operations
349 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
354 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
355 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
357 mImpl->RequestRelayout();
361 bool Controller::IsMultiLineEnabled() const
363 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
366 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
368 if( alignment != mImpl->mModel->mHorizontalAlignment )
370 // Set the alignment.
371 mImpl->mModel->mHorizontalAlignment = alignment;
373 // Set the flag to redo the alignment operation.
374 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
376 mImpl->RequestRelayout();
380 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
382 return mImpl->mModel->mHorizontalAlignment;
385 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
387 if( alignment != mImpl->mModel->mVerticalAlignment )
389 // Set the alignment.
390 mImpl->mModel->mVerticalAlignment = alignment;
392 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
394 mImpl->RequestRelayout();
398 VerticalAlignment::Type Controller::GetVerticalAlignment() const
400 return mImpl->mModel->mVerticalAlignment;
403 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
405 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
407 // Set the text wrap mode.
408 mImpl->mModel->mLineWrapMode = lineWrapMode;
411 // Update Text layout for applying wrap mode
412 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
417 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
418 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
419 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
422 mImpl->RequestRelayout();
426 Text::LineWrap::Mode Controller::GetLineWrapMode() const
428 return mImpl->mModel->mLineWrapMode;
431 void Controller::SetTextElideEnabled( bool enabled )
433 mImpl->mModel->mElideEnabled = enabled;
436 bool Controller::IsTextElideEnabled() const
438 return mImpl->mModel->mElideEnabled;
441 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
443 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
444 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
446 // Update placeholder if there is no text
447 if( mImpl->IsShowingPlaceholderText() ||
448 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
450 ShowPlaceholderText();
454 bool Controller::IsPlaceholderTextElideEnabled() const
456 return mImpl->mEventData->mIsPlaceholderElideEnabled;
459 void Controller::SetSelectionEnabled( bool enabled )
461 mImpl->mEventData->mSelectionEnabled = enabled;
464 bool Controller::IsSelectionEnabled() const
466 return mImpl->mEventData->mSelectionEnabled;
471 void Controller::SetText( const std::string& text )
473 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
475 // Reset keyboard as text changed
476 mImpl->ResetImfManager();
478 // Remove the previously set text and style.
484 CharacterIndex lastCursorIndex = 0u;
486 if( NULL != mImpl->mEventData )
488 // If popup shown then hide it by switching to Editing state
489 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
490 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
491 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
492 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
494 mImpl->ChangeState( EventData::EDITING );
500 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
502 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
503 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
505 Length textSize = 0u;
506 const uint8_t* utf8 = NULL;
507 if( mImpl->mMarkupProcessorEnabled )
509 ProcessMarkupString( text, markupProcessData );
510 textSize = markupProcessData.markupProcessedText.size();
512 // This is a bit horrible but std::string returns a (signed) char*
513 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
517 textSize = text.size();
519 // This is a bit horrible but std::string returns a (signed) char*
520 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
523 // Convert text into UTF-32
524 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
525 utf32Characters.Resize( textSize );
527 // Transform a text array encoded in utf8 into an array encoded in utf32.
528 // It returns the actual number of characters.
529 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
530 utf32Characters.Resize( characterCount );
532 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
533 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
535 // The characters to be added.
536 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
538 // To reset the cursor position
539 lastCursorIndex = characterCount;
541 // Update the rest of the model during size negotiation
542 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
544 // The natural size needs to be re-calculated.
545 mImpl->mRecalculateNaturalSize = true;
547 // Apply modifications to the model
548 mImpl->mOperationsPending = ALL_OPERATIONS;
552 ShowPlaceholderText();
555 // Resets the cursor position.
556 ResetCursorPosition( lastCursorIndex );
558 // Scrolls the text to make the cursor visible.
559 ResetScrollPosition();
561 mImpl->RequestRelayout();
563 if( NULL != mImpl->mEventData )
565 // Cancel previously queued events
566 mImpl->mEventData->mEventQueue.clear();
569 // Do this last since it provides callbacks into application code.
570 if( NULL != mImpl->mEditableControlInterface )
572 mImpl->mEditableControlInterface->TextChanged();
576 void Controller::GetText( std::string& text ) const
578 if( !mImpl->IsShowingPlaceholderText() )
580 // Retrieves the text string.
581 mImpl->GetText( 0u, text );
585 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
589 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
591 if( NULL != mImpl->mEventData )
593 if( PLACEHOLDER_TYPE_INACTIVE == type )
595 mImpl->mEventData->mPlaceholderTextInactive = text;
599 mImpl->mEventData->mPlaceholderTextActive = text;
602 // Update placeholder if there is no text
603 if( mImpl->IsShowingPlaceholderText() ||
604 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
606 ShowPlaceholderText();
611 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
613 if( NULL != mImpl->mEventData )
615 if( PLACEHOLDER_TYPE_INACTIVE == type )
617 text = mImpl->mEventData->mPlaceholderTextInactive;
621 text = mImpl->mEventData->mPlaceholderTextActive;
626 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
628 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
630 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
632 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
633 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
637 mImpl->RequestRelayout();
641 // public : Default style & Input style
643 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
645 if( NULL == mImpl->mFontDefaults )
647 mImpl->mFontDefaults = new FontDefaults();
650 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
651 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
652 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
654 // Clear the font-specific data
657 mImpl->RequestRelayout();
660 const std::string& Controller::GetDefaultFontFamily() const
662 if( NULL != mImpl->mFontDefaults )
664 return mImpl->mFontDefaults->mFontDescription.family;
670 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
672 if( NULL != mImpl->mEventData )
674 if( NULL == mImpl->mEventData->mPlaceholderFont )
676 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
679 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
680 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
681 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
683 mImpl->RequestRelayout();
687 const std::string& Controller::GetPlaceholderFontFamily() const
689 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
691 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
697 void Controller::SetDefaultFontWeight( FontWeight weight )
699 if( NULL == mImpl->mFontDefaults )
701 mImpl->mFontDefaults = new FontDefaults();
704 mImpl->mFontDefaults->mFontDescription.weight = weight;
705 mImpl->mFontDefaults->weightDefined = true;
707 // Clear the font-specific data
710 mImpl->RequestRelayout();
713 bool Controller::IsDefaultFontWeightDefined() const
715 if( NULL != mImpl->mFontDefaults )
717 return mImpl->mFontDefaults->weightDefined;
723 FontWeight Controller::GetDefaultFontWeight() const
725 if( NULL != mImpl->mFontDefaults )
727 return mImpl->mFontDefaults->mFontDescription.weight;
730 return TextAbstraction::FontWeight::NORMAL;
733 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
735 if( NULL != mImpl->mEventData )
737 if( NULL == mImpl->mEventData->mPlaceholderFont )
739 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
742 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
743 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
745 mImpl->RequestRelayout();
749 bool Controller::IsPlaceholderTextFontWeightDefined() const
751 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
753 return mImpl->mEventData->mPlaceholderFont->weightDefined;
758 FontWeight Controller::GetPlaceholderTextFontWeight() const
760 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
762 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
765 return TextAbstraction::FontWeight::NORMAL;
768 void Controller::SetDefaultFontWidth( FontWidth width )
770 if( NULL == mImpl->mFontDefaults )
772 mImpl->mFontDefaults = new FontDefaults();
775 mImpl->mFontDefaults->mFontDescription.width = width;
776 mImpl->mFontDefaults->widthDefined = true;
778 // Clear the font-specific data
781 mImpl->RequestRelayout();
784 bool Controller::IsDefaultFontWidthDefined() const
786 if( NULL != mImpl->mFontDefaults )
788 return mImpl->mFontDefaults->widthDefined;
794 FontWidth Controller::GetDefaultFontWidth() const
796 if( NULL != mImpl->mFontDefaults )
798 return mImpl->mFontDefaults->mFontDescription.width;
801 return TextAbstraction::FontWidth::NORMAL;
804 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
806 if( NULL != mImpl->mEventData )
808 if( NULL == mImpl->mEventData->mPlaceholderFont )
810 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
813 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
814 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
816 mImpl->RequestRelayout();
820 bool Controller::IsPlaceholderTextFontWidthDefined() const
822 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
824 return mImpl->mEventData->mPlaceholderFont->widthDefined;
829 FontWidth Controller::GetPlaceholderTextFontWidth() const
831 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
833 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
836 return TextAbstraction::FontWidth::NORMAL;
839 void Controller::SetDefaultFontSlant( FontSlant slant )
841 if( NULL == mImpl->mFontDefaults )
843 mImpl->mFontDefaults = new FontDefaults();
846 mImpl->mFontDefaults->mFontDescription.slant = slant;
847 mImpl->mFontDefaults->slantDefined = true;
849 // Clear the font-specific data
852 mImpl->RequestRelayout();
855 bool Controller::IsDefaultFontSlantDefined() const
857 if( NULL != mImpl->mFontDefaults )
859 return mImpl->mFontDefaults->slantDefined;
864 FontSlant Controller::GetDefaultFontSlant() const
866 if( NULL != mImpl->mFontDefaults )
868 return mImpl->mFontDefaults->mFontDescription.slant;
871 return TextAbstraction::FontSlant::NORMAL;
874 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
876 if( NULL != mImpl->mEventData )
878 if( NULL == mImpl->mEventData->mPlaceholderFont )
880 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
883 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
884 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
886 mImpl->RequestRelayout();
890 bool Controller::IsPlaceholderTextFontSlantDefined() const
892 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
894 return mImpl->mEventData->mPlaceholderFont->slantDefined;
899 FontSlant Controller::GetPlaceholderTextFontSlant() const
901 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
903 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
906 return TextAbstraction::FontSlant::NORMAL;
909 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
911 if( NULL == mImpl->mFontDefaults )
913 mImpl->mFontDefaults = new FontDefaults();
920 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
921 mImpl->mFontDefaults->sizeDefined = true;
926 // Point size = Pixel size * 72.f / DPI
927 unsigned int horizontalDpi = 0u;
928 unsigned int verticalDpi = 0u;
929 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
930 fontClient.GetDpi( horizontalDpi, verticalDpi );
932 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
933 mImpl->mFontDefaults->sizeDefined = true;
938 // Clear the font-specific data
941 mImpl->RequestRelayout();
944 float Controller::GetDefaultFontSize( FontSizeType type ) const
947 if( NULL != mImpl->mFontDefaults )
953 value = mImpl->mFontDefaults->mDefaultPointSize;
958 // Pixel size = Point size * DPI / 72.f
959 unsigned int horizontalDpi = 0u;
960 unsigned int verticalDpi = 0u;
961 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
962 fontClient.GetDpi( horizontalDpi, verticalDpi );
964 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
974 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
976 if( NULL != mImpl->mEventData )
978 if( NULL == mImpl->mEventData->mPlaceholderFont )
980 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
987 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
988 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
989 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
994 // Point size = Pixel size * 72.f / DPI
995 unsigned int horizontalDpi = 0u;
996 unsigned int verticalDpi = 0u;
997 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
998 fontClient.GetDpi( horizontalDpi, verticalDpi );
1000 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1001 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1002 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1007 mImpl->RequestRelayout();
1011 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1014 if( NULL != mImpl->mEventData )
1020 if( NULL != mImpl->mEventData->mPlaceholderFont )
1022 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1026 // If the placeholder text font size is not set, then return the default font size.
1027 value = GetDefaultFontSize( POINT_SIZE );
1033 if( NULL != mImpl->mEventData->mPlaceholderFont )
1035 // Pixel size = Point size * DPI / 72.f
1036 unsigned int horizontalDpi = 0u;
1037 unsigned int verticalDpi = 0u;
1038 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1039 fontClient.GetDpi( horizontalDpi, verticalDpi );
1041 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1045 // If the placeholder text font size is not set, then return the default font size.
1046 value = GetDefaultFontSize( PIXEL_SIZE );
1057 void Controller::SetDefaultColor( const Vector4& color )
1059 mImpl->mTextColor = color;
1061 if( !mImpl->IsShowingPlaceholderText() )
1063 mImpl->mModel->mVisualModel->SetTextColor( color );
1065 mImpl->RequestRelayout();
1069 const Vector4& Controller::GetDefaultColor() const
1071 return mImpl->mTextColor;
1074 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1076 if( NULL != mImpl->mEventData )
1078 mImpl->mEventData->mPlaceholderTextColor = textColor;
1081 if( mImpl->IsShowingPlaceholderText() )
1083 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1084 mImpl->RequestRelayout();
1088 const Vector4& Controller::GetPlaceholderTextColor() const
1090 if( NULL != mImpl->mEventData )
1092 return mImpl->mEventData->mPlaceholderTextColor;
1095 return Color::BLACK;
1098 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1100 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1102 mImpl->RequestRelayout();
1105 const Vector2& Controller::GetShadowOffset() const
1107 return mImpl->mModel->mVisualModel->GetShadowOffset();
1110 void Controller::SetShadowColor( const Vector4& shadowColor )
1112 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1114 mImpl->RequestRelayout();
1117 const Vector4& Controller::GetShadowColor() const
1119 return mImpl->mModel->mVisualModel->GetShadowColor();
1122 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1124 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1126 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1128 mImpl->RequestRelayout();
1132 const float& Controller::GetShadowBlurRadius() const
1134 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1137 void Controller::SetUnderlineColor( const Vector4& color )
1139 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1141 mImpl->RequestRelayout();
1144 const Vector4& Controller::GetUnderlineColor() const
1146 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1149 void Controller::SetUnderlineEnabled( bool enabled )
1151 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1153 mImpl->RequestRelayout();
1156 bool Controller::IsUnderlineEnabled() const
1158 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1161 void Controller::SetUnderlineHeight( float height )
1163 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1165 mImpl->RequestRelayout();
1168 float Controller::GetUnderlineHeight() const
1170 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1173 void Controller::SetOutlineColor( const Vector4& color )
1175 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1177 mImpl->RequestRelayout();
1180 const Vector4& Controller::GetOutlineColor() const
1182 return mImpl->mModel->mVisualModel->GetOutlineColor();
1185 void Controller::SetOutlineWidth( float width )
1187 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1189 mImpl->RequestRelayout();
1192 float Controller::GetOutlineWidth() const
1194 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1197 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1199 if( NULL == mImpl->mEmbossDefaults )
1201 mImpl->mEmbossDefaults = new EmbossDefaults();
1204 mImpl->mEmbossDefaults->properties = embossProperties;
1207 const std::string& Controller::GetDefaultEmbossProperties() const
1209 if( NULL != mImpl->mEmbossDefaults )
1211 return mImpl->mEmbossDefaults->properties;
1214 return EMPTY_STRING;
1217 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1219 if( NULL == mImpl->mOutlineDefaults )
1221 mImpl->mOutlineDefaults = new OutlineDefaults();
1224 mImpl->mOutlineDefaults->properties = outlineProperties;
1227 const std::string& Controller::GetDefaultOutlineProperties() const
1229 if( NULL != mImpl->mOutlineDefaults )
1231 return mImpl->mOutlineDefaults->properties;
1234 return EMPTY_STRING;
1237 void Controller::SetDefaultLineSpacing( float lineSpacing )
1239 //TODO finish implementation
1240 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1243 float Controller::GetDefaultLineSpacing() const
1245 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1248 void Controller::SetInputColor( const Vector4& color )
1250 if( NULL != mImpl->mEventData )
1252 mImpl->mEventData->mInputStyle.textColor = color;
1253 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1255 if( EventData::SELECTING == mImpl->mEventData->mState )
1257 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1259 // Get start and end position of selection
1260 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1261 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1263 // Add the color run.
1264 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1265 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1267 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1268 colorRun.color = color;
1269 colorRun.characterRun.characterIndex = startOfSelectedText;
1270 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1272 // Request to relayout.
1273 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1274 mImpl->RequestRelayout();
1276 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1277 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1278 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1283 const Vector4& Controller::GetInputColor() const
1285 if( NULL != mImpl->mEventData )
1287 return mImpl->mEventData->mInputStyle.textColor;
1290 // Return the default text's color if there is no EventData.
1291 return mImpl->mTextColor;
1295 void Controller::SetInputFontFamily( const std::string& fontFamily )
1297 if( NULL != mImpl->mEventData )
1299 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1300 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1302 if( EventData::SELECTING == mImpl->mEventData->mState )
1304 CharacterIndex startOfSelectedText = 0u;
1305 Length lengthOfSelectedText = 0u;
1306 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1307 mImpl->mModel->mLogicalModel,
1308 startOfSelectedText,
1309 lengthOfSelectedText );
1311 fontDescriptionRun.familyLength = fontFamily.size();
1312 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1313 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1314 fontDescriptionRun.familyDefined = true;
1316 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1318 // Request to relayout.
1319 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1324 UPDATE_LAYOUT_SIZE |
1327 mImpl->mRecalculateNaturalSize = true;
1328 mImpl->RequestRelayout();
1330 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1331 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1332 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1334 // As the font changes, recalculate the handle positions is needed.
1335 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1336 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1337 mImpl->mEventData->mUpdateHighlightBox = true;
1338 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1343 const std::string& Controller::GetInputFontFamily() const
1345 if( NULL != mImpl->mEventData )
1347 return mImpl->mEventData->mInputStyle.familyName;
1350 // Return the default font's family if there is no EventData.
1351 return GetDefaultFontFamily();
1354 void Controller::SetInputFontWeight( FontWeight weight )
1356 if( NULL != mImpl->mEventData )
1358 mImpl->mEventData->mInputStyle.weight = weight;
1359 mImpl->mEventData->mInputStyle.isWeightDefined = 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.weight = weight;
1371 fontDescriptionRun.weightDefined = true;
1373 // Request to relayout.
1374 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1379 UPDATE_LAYOUT_SIZE |
1382 mImpl->mRecalculateNaturalSize = true;
1383 mImpl->RequestRelayout();
1385 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1386 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1387 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1389 // As the font might change, recalculate the handle positions is needed.
1390 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1391 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1392 mImpl->mEventData->mUpdateHighlightBox = true;
1393 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1398 bool Controller::IsInputFontWeightDefined() const
1400 bool defined = false;
1402 if( NULL != mImpl->mEventData )
1404 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1410 FontWeight Controller::GetInputFontWeight() const
1412 if( NULL != mImpl->mEventData )
1414 return mImpl->mEventData->mInputStyle.weight;
1417 return GetDefaultFontWeight();
1420 void Controller::SetInputFontWidth( FontWidth width )
1422 if( NULL != mImpl->mEventData )
1424 mImpl->mEventData->mInputStyle.width = width;
1425 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1427 if( EventData::SELECTING == mImpl->mEventData->mState )
1429 CharacterIndex startOfSelectedText = 0u;
1430 Length lengthOfSelectedText = 0u;
1431 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1432 mImpl->mModel->mLogicalModel,
1433 startOfSelectedText,
1434 lengthOfSelectedText );
1436 fontDescriptionRun.width = width;
1437 fontDescriptionRun.widthDefined = true;
1439 // Request to relayout.
1440 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1445 UPDATE_LAYOUT_SIZE |
1448 mImpl->mRecalculateNaturalSize = true;
1449 mImpl->RequestRelayout();
1451 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1452 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1453 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1455 // As the font might change, recalculate the handle positions is needed.
1456 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1457 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1458 mImpl->mEventData->mUpdateHighlightBox = true;
1459 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1464 bool Controller::IsInputFontWidthDefined() const
1466 bool defined = false;
1468 if( NULL != mImpl->mEventData )
1470 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1476 FontWidth Controller::GetInputFontWidth() const
1478 if( NULL != mImpl->mEventData )
1480 return mImpl->mEventData->mInputStyle.width;
1483 return GetDefaultFontWidth();
1486 void Controller::SetInputFontSlant( FontSlant slant )
1488 if( NULL != mImpl->mEventData )
1490 mImpl->mEventData->mInputStyle.slant = slant;
1491 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1493 if( EventData::SELECTING == mImpl->mEventData->mState )
1495 CharacterIndex startOfSelectedText = 0u;
1496 Length lengthOfSelectedText = 0u;
1497 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1498 mImpl->mModel->mLogicalModel,
1499 startOfSelectedText,
1500 lengthOfSelectedText );
1502 fontDescriptionRun.slant = slant;
1503 fontDescriptionRun.slantDefined = true;
1505 // Request to relayout.
1506 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1511 UPDATE_LAYOUT_SIZE |
1514 mImpl->mRecalculateNaturalSize = true;
1515 mImpl->RequestRelayout();
1517 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1518 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1519 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1521 // As the font might change, recalculate the handle positions is needed.
1522 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1523 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1524 mImpl->mEventData->mUpdateHighlightBox = true;
1525 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1530 bool Controller::IsInputFontSlantDefined() const
1532 bool defined = false;
1534 if( NULL != mImpl->mEventData )
1536 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1542 FontSlant Controller::GetInputFontSlant() const
1544 if( NULL != mImpl->mEventData )
1546 return mImpl->mEventData->mInputStyle.slant;
1549 return GetDefaultFontSlant();
1552 void Controller::SetInputFontPointSize( float size )
1554 if( NULL != mImpl->mEventData )
1556 mImpl->mEventData->mInputStyle.size = size;
1557 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1559 if( EventData::SELECTING == mImpl->mEventData->mState )
1561 CharacterIndex startOfSelectedText = 0u;
1562 Length lengthOfSelectedText = 0u;
1563 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1564 mImpl->mModel->mLogicalModel,
1565 startOfSelectedText,
1566 lengthOfSelectedText );
1568 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1569 fontDescriptionRun.sizeDefined = true;
1571 // Request to relayout.
1572 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1577 UPDATE_LAYOUT_SIZE |
1580 mImpl->mRecalculateNaturalSize = true;
1581 mImpl->RequestRelayout();
1583 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1584 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1585 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1587 // As the font might change, recalculate the handle positions is needed.
1588 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1589 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1590 mImpl->mEventData->mUpdateHighlightBox = true;
1591 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1596 float Controller::GetInputFontPointSize() const
1598 if( NULL != mImpl->mEventData )
1600 return mImpl->mEventData->mInputStyle.size;
1603 // Return the default font's point size if there is no EventData.
1604 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1607 void Controller::SetInputLineSpacing( float lineSpacing )
1609 if( NULL != mImpl->mEventData )
1611 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1612 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1616 float Controller::GetInputLineSpacing() const
1618 if( NULL != mImpl->mEventData )
1620 return mImpl->mEventData->mInputStyle.lineSpacing;
1626 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1628 if( NULL != mImpl->mEventData )
1630 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1634 const std::string& Controller::GetInputShadowProperties() const
1636 if( NULL != mImpl->mEventData )
1638 return mImpl->mEventData->mInputStyle.shadowProperties;
1641 return EMPTY_STRING;
1644 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1646 if( NULL != mImpl->mEventData )
1648 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1652 const std::string& Controller::GetInputUnderlineProperties() const
1654 if( NULL != mImpl->mEventData )
1656 return mImpl->mEventData->mInputStyle.underlineProperties;
1659 return EMPTY_STRING;
1662 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1664 if( NULL != mImpl->mEventData )
1666 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1670 const std::string& Controller::GetInputEmbossProperties() const
1672 if( NULL != mImpl->mEventData )
1674 return mImpl->mEventData->mInputStyle.embossProperties;
1677 return GetDefaultEmbossProperties();
1680 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1682 if( NULL != mImpl->mEventData )
1684 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1688 const std::string& Controller::GetInputOutlineProperties() const
1690 if( NULL != mImpl->mEventData )
1692 return mImpl->mEventData->mInputStyle.outlineProperties;
1695 return GetDefaultOutlineProperties();
1698 void Controller::SetInputModePassword( bool passwordInput )
1700 if( NULL != mImpl->mEventData )
1702 mImpl->mEventData->mPasswordInput = passwordInput;
1706 bool Controller::IsInputModePassword()
1708 if( NULL != mImpl->mEventData )
1710 return mImpl->mEventData->mPasswordInput;
1715 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1717 if( NULL != mImpl->mEventData )
1719 mImpl->mEventData->mDoubleTapAction = action;
1723 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1725 NoTextTap::Action action = NoTextTap::NO_ACTION;
1727 if( NULL != mImpl->mEventData )
1729 action = mImpl->mEventData->mDoubleTapAction;
1735 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1737 if( NULL != mImpl->mEventData )
1739 mImpl->mEventData->mLongPressAction = action;
1743 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1745 NoTextTap::Action action = NoTextTap::NO_ACTION;
1747 if( NULL != mImpl->mEventData )
1749 action = mImpl->mEventData->mLongPressAction;
1755 bool Controller::IsUnderlineSetByString()
1757 return mImpl->mUnderlineSetByString;
1760 void Controller::UnderlineSetByString( bool setByString )
1762 mImpl->mUnderlineSetByString = setByString;
1765 bool Controller::IsShadowSetByString()
1767 return mImpl->mShadowSetByString;
1770 void Controller::ShadowSetByString( bool setByString )
1772 mImpl->mShadowSetByString = setByString;
1775 bool Controller::IsOutlineSetByString()
1777 return mImpl->mOutlineSetByString;
1780 void Controller::OutlineSetByString( bool setByString )
1782 mImpl->mOutlineSetByString = setByString;
1785 bool Controller::IsFontStyleSetByString()
1787 return mImpl->mFontStyleSetByString;
1790 void Controller::FontStyleSetByString( bool setByString )
1792 mImpl->mFontStyleSetByString = setByString;
1795 // public : Queries & retrieves.
1797 Layout::Engine& Controller::GetLayoutEngine()
1799 return mImpl->mLayoutEngine;
1802 View& Controller::GetView()
1804 return mImpl->mView;
1807 Vector3 Controller::GetNaturalSize()
1809 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1810 Vector3 naturalSize;
1812 // Make sure the model is up-to-date before layouting
1813 ProcessModifyEvents();
1815 if( mImpl->mRecalculateNaturalSize )
1817 // Operations that can be done only once until the text changes.
1818 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1825 GET_GLYPH_METRICS );
1827 // Set the update info to relayout the whole text.
1828 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1829 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1831 // Make sure the model is up-to-date before layouting
1832 mImpl->UpdateModel( onlyOnceOperations );
1834 // Layout the text for the new width.
1835 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1837 // Store the actual control's size to restore later.
1838 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1840 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1841 static_cast<OperationsMask>( onlyOnceOperations |
1843 naturalSize.GetVectorXY() );
1845 // Do not do again the only once operations.
1846 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1848 // Do the size related operations again.
1849 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1852 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1854 // Stores the natural size to avoid recalculate it again
1855 // unless the text/style changes.
1856 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1858 mImpl->mRecalculateNaturalSize = false;
1860 // Clear the update info. This info will be set the next time the text is updated.
1861 mImpl->mTextUpdateInfo.Clear();
1863 // Restore the actual control's size.
1864 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1866 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1870 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1872 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1875 naturalSize.x = ConvertToEven( naturalSize.x );
1876 naturalSize.y = ConvertToEven( naturalSize.y );
1881 float Controller::GetHeightForWidth( float width )
1883 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1884 // Make sure the model is up-to-date before layouting
1885 ProcessModifyEvents();
1888 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1889 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1890 mImpl->mTextUpdateInfo.mClearAll )
1892 // Operations that can be done only once until the text changes.
1893 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1900 GET_GLYPH_METRICS );
1902 // Set the update info to relayout the whole text.
1903 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1904 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1906 // Make sure the model is up-to-date before layouting
1907 mImpl->UpdateModel( onlyOnceOperations );
1910 // Layout the text for the new width.
1911 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1913 // Store the actual control's width.
1914 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1916 DoRelayout( Size( width, MAX_FLOAT ),
1917 static_cast<OperationsMask>( onlyOnceOperations |
1921 // Do not do again the only once operations.
1922 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1924 // Do the size related operations again.
1925 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1929 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1931 // Clear the update info. This info will be set the next time the text is updated.
1932 mImpl->mTextUpdateInfo.Clear();
1934 // Restore the actual control's width.
1935 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1937 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1941 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1942 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1945 return layoutSize.height;
1948 int Controller::GetLineCount( float width )
1950 GetHeightForWidth( width );
1951 int numberofLines = mImpl->mModel->GetNumberOfLines();
1952 return numberofLines;
1955 const ModelInterface* const Controller::GetTextModel() const
1957 return mImpl->mModel.Get();
1960 float Controller::GetScrollAmountByUserInput()
1962 float scrollAmount = 0.0f;
1964 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1966 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1967 mImpl->mEventData->mCheckScrollAmount = false;
1969 return scrollAmount;
1972 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1974 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1977 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1978 layoutHeight = layout.height;
1979 scrollPosition = mImpl->mModel->mScrollPosition.y;
1980 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1984 void Controller::SetHiddenInputOption(const Property::Map& options )
1986 if( NULL == mImpl->mHiddenInput )
1988 mImpl->mHiddenInput = new HiddenText( this );
1990 mImpl->mHiddenInput->SetProperties(options);
1993 void Controller::GetHiddenInputOption(Property::Map& options )
1995 if( NULL != mImpl->mHiddenInput )
1997 mImpl->mHiddenInput->GetProperties(options);
2001 void Controller::SetPlaceholderProperty( const Property::Map& map )
2003 const Property::Map::SizeType count = map.Count();
2005 for( Property::Map::SizeType position = 0; position < count; ++position )
2007 KeyValuePair keyValue = map.GetKeyValue( position );
2008 Property::Key& key = keyValue.first;
2009 Property::Value& value = keyValue.second;
2011 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2013 std::string text = "";
2015 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2017 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2019 std::string text = "";
2021 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2023 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2026 value.Get( textColor );
2027 if( GetPlaceholderTextColor() != textColor )
2029 SetPlaceholderTextColor( textColor );
2032 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2034 std::string fontFamily = "";
2035 value.Get( fontFamily );
2036 SetPlaceholderFontFamily( fontFamily );
2038 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2040 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2042 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2045 value.Get( pointSize );
2046 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2048 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2051 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2054 value.Get( pixelSize );
2055 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2057 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2060 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2063 value.Get( ellipsis );
2064 SetPlaceholderTextElideEnabled( ellipsis );
2069 void Controller::GetPlaceholderProperty( Property::Map& map )
2071 if( NULL != mImpl->mEventData )
2073 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2075 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2077 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2079 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2082 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2083 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2085 Property::Value fontStyleMapGet;
2086 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2087 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2089 // Choose font size : POINT_SIZE or PIXEL_SIZE
2090 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2092 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2096 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2099 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2101 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2106 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2108 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
2109 if ( firstline && firstline->direction )
2111 return Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT;
2114 return Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2117 // public : Relayout.
2119 Controller::UpdateTextType Controller::Relayout( const Size& size )
2121 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2123 UpdateTextType updateTextType = NONE_UPDATED;
2125 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2127 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2129 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2130 updateTextType = MODEL_UPDATED;
2133 // Clear the update info. This info will be set the next time the text is updated.
2134 mImpl->mTextUpdateInfo.Clear();
2136 // Not worth to relayout if width or height is equal to zero.
2137 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2139 return updateTextType;
2142 // Whether a new size has been set.
2143 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2147 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2149 // Layout operations that need to be done if the size changes.
2150 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2153 UPDATE_LAYOUT_SIZE |
2155 // Set the update info to relayout the whole text.
2156 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2157 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2159 // Store the size used to layout the text.
2160 mImpl->mModel->mVisualModel->mControlSize = size;
2163 // Whether there are modify events.
2164 if( 0u != mImpl->mModifyEvents.Count() )
2166 // Style operations that need to be done if the text is modified.
2167 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2171 // Set the update info to elide the text.
2172 if( mImpl->mModel->mElideEnabled ||
2173 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2175 // Update Text layout for applying elided
2176 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2179 UPDATE_LAYOUT_SIZE |
2181 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2182 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2185 // Make sure the model is up-to-date before layouting.
2186 ProcessModifyEvents();
2187 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2191 updated = DoRelayout( size,
2192 mImpl->mOperationsPending,
2193 layoutSize ) || updated;
2197 updateTextType = MODEL_UPDATED;
2200 // Do not re-do any operation until something changes.
2201 mImpl->mOperationsPending = NO_OPERATION;
2202 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2204 // Whether the text control is editable
2205 const bool isEditable = NULL != mImpl->mEventData;
2207 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2209 if( newSize && isEditable )
2211 offset = mImpl->mModel->mScrollPosition;
2214 if( !isEditable || !IsMultiLineEnabled() )
2216 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2217 CalculateVerticalOffset( size );
2224 // If there is a new size, the scroll position needs to be clamped.
2225 mImpl->ClampHorizontalScroll( layoutSize );
2227 // Update the decorator's positions is needed if there is a new size.
2228 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2231 // Move the cursor, grab handle etc.
2232 if( mImpl->ProcessInputEvents() )
2234 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2238 // Clear the update info. This info will be set the next time the text is updated.
2239 mImpl->mTextUpdateInfo.Clear();
2240 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2242 return updateTextType;
2245 void Controller::RequestRelayout()
2247 mImpl->RequestRelayout();
2250 // public : Input style change signals.
2252 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2254 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2257 void Controller::ProcessInputStyleChangedSignals()
2259 if( NULL == mImpl->mEventData )
2265 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2266 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2270 const InputStyle::Mask mask = *it;
2272 if( NULL != mImpl->mEditableControlInterface )
2274 // Emit the input style changed signal.
2275 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2279 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2282 // public : Text-input Event Queuing.
2284 void Controller::KeyboardFocusGainEvent()
2286 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2288 if( NULL != mImpl->mEventData )
2290 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2291 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2293 mImpl->ChangeState( EventData::EDITING );
2294 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2295 mImpl->mEventData->mUpdateInputStyle = true;
2297 mImpl->NotifyImfMultiLineStatus();
2298 if( mImpl->IsShowingPlaceholderText() )
2300 // Show alternative placeholder-text when editing
2301 ShowPlaceholderText();
2304 mImpl->RequestRelayout();
2308 void Controller::KeyboardFocusLostEvent()
2310 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2312 if( NULL != mImpl->mEventData )
2314 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2316 mImpl->ChangeState( EventData::INACTIVE );
2318 if( !mImpl->IsShowingRealText() )
2320 // Revert to regular placeholder-text when not editing
2321 ShowPlaceholderText();
2325 mImpl->RequestRelayout();
2328 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2330 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2332 bool textChanged = false;
2333 bool relayoutNeeded = false;
2335 if( ( NULL != mImpl->mEventData ) &&
2336 ( keyEvent.state == KeyEvent::Down ) )
2338 int keyCode = keyEvent.keyCode;
2339 const std::string& keyString = keyEvent.keyPressed;
2340 const std::string keyName = keyEvent.keyPressedName;
2342 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2344 // Pre-process to separate modifying events from non-modifying input events.
2347 // In some platforms arrive key events with no key code.
2351 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2356 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2357 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2358 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2359 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2361 // If don't have any text, do nothing.
2362 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2367 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2368 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2369 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2370 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2372 // Logic to determine whether this text control will lose focus or not.
2373 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2374 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2375 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2376 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2377 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2378 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2383 mImpl->mEventData->mCheckScrollAmount = true;
2384 Event event( Event::CURSOR_KEY_EVENT );
2385 event.p1.mInt = keyCode;
2386 event.p2.mBool = keyEvent.IsShiftModifier();
2387 mImpl->mEventData->mEventQueue.push_back( event );
2389 // Will request for relayout.
2390 relayoutNeeded = true;
2392 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2394 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2395 // If not handle it here, any selected text will be deleted
2400 else if ( keyEvent.IsCtrlModifier() )
2402 bool consumed = false;
2403 if (keyName == KEY_C_NAME)
2405 // Ctrl-C to copy the selected text
2406 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2409 else if (keyName == KEY_V_NAME)
2411 // Ctrl-V to paste the copied text
2412 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2415 else if (keyName == KEY_X_NAME)
2417 // Ctrl-X to cut the selected text
2418 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2423 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2424 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2426 textChanged = DeleteEvent( keyCode );
2428 // Will request for relayout.
2429 relayoutNeeded = true;
2431 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2432 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2433 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2435 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2436 mImpl->ChangeState( EventData::INACTIVE );
2438 // Will request for relayout.
2439 relayoutNeeded = true;
2441 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2443 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2445 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2446 // and a character is typed after the type of a upper case latin character.
2451 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2453 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2459 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2461 // IMF manager is no longer handling key-events
2462 mImpl->ClearPreEditFlag();
2464 InsertText( keyString, COMMIT );
2467 // Will request for relayout.
2468 relayoutNeeded = true;
2471 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2472 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2474 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2475 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2476 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2478 // Should not change the state if the key is the shift send by the imf manager.
2479 // Otherwise, when the state is SELECTING the text controller can't send the right
2480 // surrounding info to the imf.
2481 mImpl->ChangeState( EventData::EDITING );
2483 // Will request for relayout.
2484 relayoutNeeded = true;
2487 if( relayoutNeeded )
2489 mImpl->RequestRelayout();
2494 ( NULL != mImpl->mEditableControlInterface ) )
2496 // Do this last since it provides callbacks into application code
2497 mImpl->mEditableControlInterface->TextChanged();
2503 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2505 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2507 if( NULL != mImpl->mEventData )
2509 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2510 EventData::State state( mImpl->mEventData->mState );
2511 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2513 if( mImpl->IsClipboardVisible() )
2515 if( EventData::INACTIVE == state || EventData::EDITING == state)
2517 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2519 relayoutNeeded = true;
2521 else if( 1u == tapCount )
2523 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2525 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2528 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2530 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2531 relayoutNeeded = true;
2535 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2537 // Hide placeholder text
2541 if( EventData::INACTIVE == state )
2543 mImpl->ChangeState( EventData::EDITING );
2545 else if( !mImpl->IsClipboardEmpty() )
2547 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2549 relayoutNeeded = true;
2552 else if( 2u == tapCount )
2554 if( mImpl->mEventData->mSelectionEnabled &&
2555 mImpl->IsShowingRealText() )
2557 relayoutNeeded = true;
2558 mImpl->mEventData->mIsLeftHandleSelected = true;
2559 mImpl->mEventData->mIsRightHandleSelected = true;
2563 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2564 if( relayoutNeeded )
2566 Event event( Event::TAP_EVENT );
2567 event.p1.mUint = tapCount;
2568 event.p2.mFloat = x;
2569 event.p3.mFloat = y;
2570 mImpl->mEventData->mEventQueue.push_back( event );
2572 mImpl->RequestRelayout();
2576 // Reset keyboard as tap event has occurred.
2577 mImpl->ResetImfManager();
2580 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2582 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2584 if( NULL != mImpl->mEventData )
2586 Event event( Event::PAN_EVENT );
2587 event.p1.mInt = state;
2588 event.p2.mFloat = displacement.x;
2589 event.p3.mFloat = displacement.y;
2590 mImpl->mEventData->mEventQueue.push_back( event );
2592 mImpl->RequestRelayout();
2596 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2598 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2600 if( ( state == Gesture::Started ) &&
2601 ( NULL != mImpl->mEventData ) )
2603 // The 1st long-press on inactive text-field is treated as tap
2604 if( EventData::INACTIVE == mImpl->mEventData->mState )
2606 mImpl->ChangeState( EventData::EDITING );
2608 Event event( Event::TAP_EVENT );
2610 event.p2.mFloat = x;
2611 event.p3.mFloat = y;
2612 mImpl->mEventData->mEventQueue.push_back( event );
2614 mImpl->RequestRelayout();
2616 else if( !mImpl->IsShowingRealText() )
2618 Event event( Event::LONG_PRESS_EVENT );
2619 event.p1.mInt = state;
2620 event.p2.mFloat = x;
2621 event.p3.mFloat = y;
2622 mImpl->mEventData->mEventQueue.push_back( event );
2623 mImpl->RequestRelayout();
2625 else if( !mImpl->IsClipboardVisible() )
2627 // Reset the imf manager to commit the pre-edit before selecting the text.
2628 mImpl->ResetImfManager();
2630 Event event( Event::LONG_PRESS_EVENT );
2631 event.p1.mInt = state;
2632 event.p2.mFloat = x;
2633 event.p3.mFloat = y;
2634 mImpl->mEventData->mEventQueue.push_back( event );
2635 mImpl->RequestRelayout();
2637 mImpl->mEventData->mIsLeftHandleSelected = true;
2638 mImpl->mEventData->mIsRightHandleSelected = true;
2643 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2645 // Whether the text needs to be relaid-out.
2646 bool requestRelayout = false;
2648 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2649 bool retrieveText = false;
2650 bool retrieveCursor = false;
2652 switch( imfEvent.eventName )
2654 case ImfManager::COMMIT:
2656 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2657 requestRelayout = true;
2658 retrieveCursor = true;
2661 case ImfManager::PREEDIT:
2663 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2664 requestRelayout = true;
2665 retrieveCursor = true;
2668 case ImfManager::DELETESURROUNDING:
2670 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2671 imfEvent.numberOfChars,
2672 DONT_UPDATE_INPUT_STYLE );
2676 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2677 !mImpl->IsPlaceholderAvailable() )
2679 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2683 ShowPlaceholderText();
2685 mImpl->mEventData->mUpdateCursorPosition = true;
2686 mImpl->mEventData->mScrollAfterDelete = true;
2688 requestRelayout = true;
2692 case ImfManager::GETSURROUNDING:
2694 retrieveText = true;
2695 retrieveCursor = true;
2698 case ImfManager::PRIVATECOMMAND:
2700 // PRIVATECOMMAND event is just for getting the private command message
2701 retrieveText = true;
2702 retrieveCursor = true;
2705 case ImfManager::VOID:
2712 if( requestRelayout )
2714 mImpl->mOperationsPending = ALL_OPERATIONS;
2715 mImpl->RequestRelayout();
2719 CharacterIndex cursorPosition = 0u;
2720 Length numberOfWhiteSpaces = 0u;
2722 if( retrieveCursor )
2724 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2726 cursorPosition = mImpl->GetLogicalCursorPosition();
2728 if( cursorPosition < numberOfWhiteSpaces )
2730 cursorPosition = 0u;
2734 cursorPosition -= numberOfWhiteSpaces;
2740 mImpl->GetText( numberOfWhiteSpaces, text );
2743 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2745 if( requestRelayout &&
2746 ( NULL != mImpl->mEditableControlInterface ) )
2748 // Do this last since it provides callbacks into application code
2749 mImpl->mEditableControlInterface->TextChanged();
2752 return callbackData;
2755 void Controller::PasteClipboardItemEvent()
2757 // Retrieve the clipboard contents first
2758 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2759 std::string stringToPaste( notifier.GetContent() );
2761 // Commit the current pre-edit text; the contents of the clipboard should be appended
2762 mImpl->ResetImfManager();
2764 // Temporary disable hiding clipboard
2765 mImpl->SetClipboardHideEnable( false );
2768 PasteText( stringToPaste );
2770 mImpl->SetClipboardHideEnable( true );
2773 // protected : Inherit from Text::Decorator::ControllerInterface.
2775 void Controller::GetTargetSize( Vector2& targetSize )
2777 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2780 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2782 if( NULL != mImpl->mEditableControlInterface )
2784 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2788 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2790 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2792 if( NULL != mImpl->mEventData )
2794 switch( handleType )
2798 Event event( Event::GRAB_HANDLE_EVENT );
2799 event.p1.mUint = state;
2800 event.p2.mFloat = x;
2801 event.p3.mFloat = y;
2803 mImpl->mEventData->mEventQueue.push_back( event );
2806 case LEFT_SELECTION_HANDLE:
2808 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2809 event.p1.mUint = state;
2810 event.p2.mFloat = x;
2811 event.p3.mFloat = y;
2813 mImpl->mEventData->mEventQueue.push_back( event );
2816 case RIGHT_SELECTION_HANDLE:
2818 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2819 event.p1.mUint = state;
2820 event.p2.mFloat = x;
2821 event.p3.mFloat = y;
2823 mImpl->mEventData->mEventQueue.push_back( event );
2826 case LEFT_SELECTION_HANDLE_MARKER:
2827 case RIGHT_SELECTION_HANDLE_MARKER:
2829 // Markers do not move the handles.
2832 case HANDLE_TYPE_COUNT:
2834 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2838 mImpl->RequestRelayout();
2842 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2844 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2846 if( NULL == mImpl->mEventData )
2853 case Toolkit::TextSelectionPopup::CUT:
2855 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2856 mImpl->mOperationsPending = ALL_OPERATIONS;
2858 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2859 !mImpl->IsPlaceholderAvailable() )
2861 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2865 ShowPlaceholderText();
2868 mImpl->mEventData->mUpdateCursorPosition = true;
2869 mImpl->mEventData->mScrollAfterDelete = true;
2871 mImpl->RequestRelayout();
2873 if( NULL != mImpl->mEditableControlInterface )
2875 mImpl->mEditableControlInterface->TextChanged();
2879 case Toolkit::TextSelectionPopup::COPY:
2881 mImpl->SendSelectionToClipboard( false ); // Text not modified
2883 mImpl->mEventData->mUpdateCursorPosition = true;
2885 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2888 case Toolkit::TextSelectionPopup::PASTE:
2890 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2893 case Toolkit::TextSelectionPopup::SELECT:
2895 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2897 if( mImpl->mEventData->mSelectionEnabled )
2899 // Creates a SELECT event.
2900 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2904 case Toolkit::TextSelectionPopup::SELECT_ALL:
2906 // Creates a SELECT_ALL event
2907 SelectEvent( 0.f, 0.f, true );
2910 case Toolkit::TextSelectionPopup::CLIPBOARD:
2912 mImpl->ShowClipboard();
2915 case Toolkit::TextSelectionPopup::NONE:
2923 void Controller::DisplayTimeExpired()
2925 mImpl->mEventData->mUpdateCursorPosition = true;
2926 // Apply modifications to the model
2927 mImpl->mOperationsPending = ALL_OPERATIONS;
2929 mImpl->RequestRelayout();
2932 // private : Update.
2934 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2936 bool removedPrevious = false;
2937 bool removedSelected = false;
2938 bool maxLengthReached = false;
2940 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2942 if( NULL == mImpl->mEventData )
2947 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2948 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2949 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2951 // TODO: At the moment the underline runs are only for pre-edit.
2952 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2954 // Remove the previous IMF pre-edit.
2955 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2957 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2958 mImpl->mEventData->mPreEditLength,
2959 DONT_UPDATE_INPUT_STYLE );
2961 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2962 mImpl->mEventData->mPreEditLength = 0u;
2966 // Remove the previous Selection.
2967 removedSelected = RemoveSelectedText();
2971 Vector<Character> utf32Characters;
2972 Length characterCount = 0u;
2976 // Convert text into UTF-32
2977 utf32Characters.Resize( text.size() );
2979 // This is a bit horrible but std::string returns a (signed) char*
2980 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2982 // Transform a text array encoded in utf8 into an array encoded in utf32.
2983 // It returns the actual number of characters.
2984 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2985 utf32Characters.Resize( characterCount );
2987 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2988 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2991 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2993 // The placeholder text is no longer needed
2994 if( mImpl->IsShowingPlaceholderText() )
2999 mImpl->ChangeState( EventData::EDITING );
3001 // Handle the IMF (predicitive text) state changes
3002 if( COMMIT == type )
3004 // IMF manager is no longer handling key-events
3005 mImpl->ClearPreEditFlag();
3009 if( !mImpl->mEventData->mPreEditFlag )
3011 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3013 // Record the start of the pre-edit text
3014 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3017 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3018 mImpl->mEventData->mPreEditFlag = true;
3020 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3023 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3025 // Restrict new text to fit within Maximum characters setting.
3026 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3027 maxLengthReached = ( characterCount > maxSizeOfNewText );
3029 // The cursor position.
3030 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3032 // Update the text's style.
3034 // Updates the text style runs by adding characters.
3035 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3037 // Get the character index from the cursor index.
3038 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3040 // Retrieve the text's style for the given index.
3042 mImpl->RetrieveDefaultInputStyle( style );
3043 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3045 // Whether to add a new text color run.
3046 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3048 // Whether to add a new font run.
3049 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3050 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3051 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3052 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3053 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3058 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3059 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3061 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3062 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3063 colorRun.characterRun.characterIndex = cursorIndex;
3064 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3067 if( addFontNameRun ||
3073 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3074 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3076 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3078 if( addFontNameRun )
3080 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3081 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3082 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3083 fontDescriptionRun.familyDefined = true;
3085 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3088 if( addFontWeightRun )
3090 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3091 fontDescriptionRun.weightDefined = true;
3094 if( addFontWidthRun )
3096 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3097 fontDescriptionRun.widthDefined = true;
3100 if( addFontSlantRun )
3102 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3103 fontDescriptionRun.slantDefined = true;
3106 if( addFontSizeRun )
3108 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3109 fontDescriptionRun.sizeDefined = true;
3112 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3113 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3116 // Insert at current cursor position.
3117 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3119 if( cursorIndex < numberOfCharactersInModel )
3121 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3125 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3128 // Mark the first paragraph to be updated.
3129 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3131 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3132 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3133 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3134 mImpl->mTextUpdateInfo.mClearAll = true;
3138 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3139 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3142 // Update the cursor index.
3143 cursorIndex += maxSizeOfNewText;
3145 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 );
3148 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3149 mImpl->IsPlaceholderAvailable() )
3151 // Show place-holder if empty after removing the pre-edit text
3152 ShowPlaceholderText();
3153 mImpl->mEventData->mUpdateCursorPosition = true;
3154 mImpl->ClearPreEditFlag();
3156 else if( removedPrevious ||
3158 ( 0 != utf32Characters.Count() ) )
3160 // Queue an inserted event
3161 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3163 mImpl->mEventData->mUpdateCursorPosition = true;
3164 if( removedSelected )
3166 mImpl->mEventData->mScrollAfterDelete = true;
3170 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3174 if( maxLengthReached )
3176 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3178 mImpl->ResetImfManager();