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->mIsTextDirectionRTL;
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;
469 void Controller::SetShiftSelectionEnabled( bool enabled )
471 mImpl->mEventData->mShiftSelectionFlag = enabled;
474 bool Controller::IsShiftSelectionEnabled() const
476 return mImpl->mEventData->mShiftSelectionFlag;
479 void Controller::SetGrabHandleEnabled( bool enabled )
481 mImpl->mEventData->mGrabHandleEnabled = enabled;
484 bool Controller::IsGrabHandleEnabled() const
486 return mImpl->mEventData->mGrabHandleEnabled;
491 void Controller::SetText( const std::string& text )
493 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
495 // Reset keyboard as text changed
496 mImpl->ResetImfManager();
498 // Remove the previously set text and style.
504 CharacterIndex lastCursorIndex = 0u;
506 if( NULL != mImpl->mEventData )
508 // If popup shown then hide it by switching to Editing state
509 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
510 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
511 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
512 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
514 mImpl->ChangeState( EventData::EDITING );
520 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
522 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
523 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
525 Length textSize = 0u;
526 const uint8_t* utf8 = NULL;
527 if( mImpl->mMarkupProcessorEnabled )
529 ProcessMarkupString( text, markupProcessData );
530 textSize = markupProcessData.markupProcessedText.size();
532 // This is a bit horrible but std::string returns a (signed) char*
533 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
537 textSize = text.size();
539 // This is a bit horrible but std::string returns a (signed) char*
540 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
543 // Convert text into UTF-32
544 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
545 utf32Characters.Resize( textSize );
547 // Transform a text array encoded in utf8 into an array encoded in utf32.
548 // It returns the actual number of characters.
549 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
550 utf32Characters.Resize( characterCount );
552 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
553 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
555 // The characters to be added.
556 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
558 // To reset the cursor position
559 lastCursorIndex = characterCount;
561 // Update the rest of the model during size negotiation
562 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
564 // The natural size needs to be re-calculated.
565 mImpl->mRecalculateNaturalSize = true;
567 // The text direction needs to be updated.
568 mImpl->mUpdateTextDirection = true;
570 // Apply modifications to the model
571 mImpl->mOperationsPending = ALL_OPERATIONS;
575 ShowPlaceholderText();
578 // Resets the cursor position.
579 ResetCursorPosition( lastCursorIndex );
581 // Scrolls the text to make the cursor visible.
582 ResetScrollPosition();
584 mImpl->RequestRelayout();
586 if( NULL != mImpl->mEventData )
588 // Cancel previously queued events
589 mImpl->mEventData->mEventQueue.clear();
592 // Do this last since it provides callbacks into application code.
593 if( NULL != mImpl->mEditableControlInterface )
595 mImpl->mEditableControlInterface->TextChanged();
599 void Controller::GetText( std::string& text ) const
601 if( !mImpl->IsShowingPlaceholderText() )
603 // Retrieves the text string.
604 mImpl->GetText( 0u, text );
608 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
612 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
614 if( NULL != mImpl->mEventData )
616 if( PLACEHOLDER_TYPE_INACTIVE == type )
618 mImpl->mEventData->mPlaceholderTextInactive = text;
622 mImpl->mEventData->mPlaceholderTextActive = text;
625 // Update placeholder if there is no text
626 if( mImpl->IsShowingPlaceholderText() ||
627 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
629 ShowPlaceholderText();
634 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
636 if( NULL != mImpl->mEventData )
638 if( PLACEHOLDER_TYPE_INACTIVE == type )
640 text = mImpl->mEventData->mPlaceholderTextInactive;
644 text = mImpl->mEventData->mPlaceholderTextActive;
649 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
651 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
653 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
655 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
656 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
660 mImpl->RequestRelayout();
664 // public : Default style & Input style
666 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
668 if( NULL == mImpl->mFontDefaults )
670 mImpl->mFontDefaults = new FontDefaults();
673 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
674 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
675 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
677 // Clear the font-specific data
680 mImpl->RequestRelayout();
683 const std::string& Controller::GetDefaultFontFamily() const
685 if( NULL != mImpl->mFontDefaults )
687 return mImpl->mFontDefaults->mFontDescription.family;
693 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
695 if( NULL != mImpl->mEventData )
697 if( NULL == mImpl->mEventData->mPlaceholderFont )
699 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
702 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
703 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
704 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
706 mImpl->RequestRelayout();
710 const std::string& Controller::GetPlaceholderFontFamily() const
712 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
714 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
720 void Controller::SetDefaultFontWeight( FontWeight weight )
722 if( NULL == mImpl->mFontDefaults )
724 mImpl->mFontDefaults = new FontDefaults();
727 mImpl->mFontDefaults->mFontDescription.weight = weight;
728 mImpl->mFontDefaults->weightDefined = true;
730 // Clear the font-specific data
733 mImpl->RequestRelayout();
736 bool Controller::IsDefaultFontWeightDefined() const
738 if( NULL != mImpl->mFontDefaults )
740 return mImpl->mFontDefaults->weightDefined;
746 FontWeight Controller::GetDefaultFontWeight() const
748 if( NULL != mImpl->mFontDefaults )
750 return mImpl->mFontDefaults->mFontDescription.weight;
753 return TextAbstraction::FontWeight::NORMAL;
756 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
758 if( NULL != mImpl->mEventData )
760 if( NULL == mImpl->mEventData->mPlaceholderFont )
762 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
765 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
766 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
768 mImpl->RequestRelayout();
772 bool Controller::IsPlaceholderTextFontWeightDefined() const
774 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
776 return mImpl->mEventData->mPlaceholderFont->weightDefined;
781 FontWeight Controller::GetPlaceholderTextFontWeight() const
783 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
785 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
788 return TextAbstraction::FontWeight::NORMAL;
791 void Controller::SetDefaultFontWidth( FontWidth width )
793 if( NULL == mImpl->mFontDefaults )
795 mImpl->mFontDefaults = new FontDefaults();
798 mImpl->mFontDefaults->mFontDescription.width = width;
799 mImpl->mFontDefaults->widthDefined = true;
801 // Clear the font-specific data
804 mImpl->RequestRelayout();
807 bool Controller::IsDefaultFontWidthDefined() const
809 if( NULL != mImpl->mFontDefaults )
811 return mImpl->mFontDefaults->widthDefined;
817 FontWidth Controller::GetDefaultFontWidth() const
819 if( NULL != mImpl->mFontDefaults )
821 return mImpl->mFontDefaults->mFontDescription.width;
824 return TextAbstraction::FontWidth::NORMAL;
827 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
829 if( NULL != mImpl->mEventData )
831 if( NULL == mImpl->mEventData->mPlaceholderFont )
833 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
836 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
837 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
839 mImpl->RequestRelayout();
843 bool Controller::IsPlaceholderTextFontWidthDefined() const
845 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
847 return mImpl->mEventData->mPlaceholderFont->widthDefined;
852 FontWidth Controller::GetPlaceholderTextFontWidth() const
854 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
856 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
859 return TextAbstraction::FontWidth::NORMAL;
862 void Controller::SetDefaultFontSlant( FontSlant slant )
864 if( NULL == mImpl->mFontDefaults )
866 mImpl->mFontDefaults = new FontDefaults();
869 mImpl->mFontDefaults->mFontDescription.slant = slant;
870 mImpl->mFontDefaults->slantDefined = true;
872 // Clear the font-specific data
875 mImpl->RequestRelayout();
878 bool Controller::IsDefaultFontSlantDefined() const
880 if( NULL != mImpl->mFontDefaults )
882 return mImpl->mFontDefaults->slantDefined;
887 FontSlant Controller::GetDefaultFontSlant() const
889 if( NULL != mImpl->mFontDefaults )
891 return mImpl->mFontDefaults->mFontDescription.slant;
894 return TextAbstraction::FontSlant::NORMAL;
897 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
899 if( NULL != mImpl->mEventData )
901 if( NULL == mImpl->mEventData->mPlaceholderFont )
903 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
906 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
907 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
909 mImpl->RequestRelayout();
913 bool Controller::IsPlaceholderTextFontSlantDefined() const
915 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
917 return mImpl->mEventData->mPlaceholderFont->slantDefined;
922 FontSlant Controller::GetPlaceholderTextFontSlant() const
924 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
926 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
929 return TextAbstraction::FontSlant::NORMAL;
932 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
934 if( NULL == mImpl->mFontDefaults )
936 mImpl->mFontDefaults = new FontDefaults();
943 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
944 mImpl->mFontDefaults->sizeDefined = true;
949 // Point size = Pixel size * 72.f / DPI
950 unsigned int horizontalDpi = 0u;
951 unsigned int verticalDpi = 0u;
952 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
953 fontClient.GetDpi( horizontalDpi, verticalDpi );
955 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
956 mImpl->mFontDefaults->sizeDefined = true;
961 // Clear the font-specific data
964 mImpl->RequestRelayout();
967 float Controller::GetDefaultFontSize( FontSizeType type ) const
970 if( NULL != mImpl->mFontDefaults )
976 value = mImpl->mFontDefaults->mDefaultPointSize;
981 // Pixel size = Point size * DPI / 72.f
982 unsigned int horizontalDpi = 0u;
983 unsigned int verticalDpi = 0u;
984 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
985 fontClient.GetDpi( horizontalDpi, verticalDpi );
987 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
997 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
999 if( NULL != mImpl->mEventData )
1001 if( NULL == mImpl->mEventData->mPlaceholderFont )
1003 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1010 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1011 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1012 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1017 // Point size = Pixel size * 72.f / DPI
1018 unsigned int horizontalDpi = 0u;
1019 unsigned int verticalDpi = 0u;
1020 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1021 fontClient.GetDpi( horizontalDpi, verticalDpi );
1023 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1024 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1025 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1030 mImpl->RequestRelayout();
1034 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1037 if( NULL != mImpl->mEventData )
1043 if( NULL != mImpl->mEventData->mPlaceholderFont )
1045 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1049 // If the placeholder text font size is not set, then return the default font size.
1050 value = GetDefaultFontSize( POINT_SIZE );
1056 if( NULL != mImpl->mEventData->mPlaceholderFont )
1058 // Pixel size = Point size * DPI / 72.f
1059 unsigned int horizontalDpi = 0u;
1060 unsigned int verticalDpi = 0u;
1061 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1062 fontClient.GetDpi( horizontalDpi, verticalDpi );
1064 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1068 // If the placeholder text font size is not set, then return the default font size.
1069 value = GetDefaultFontSize( PIXEL_SIZE );
1080 void Controller::SetDefaultColor( const Vector4& color )
1082 mImpl->mTextColor = color;
1084 if( !mImpl->IsShowingPlaceholderText() )
1086 mImpl->mModel->mVisualModel->SetTextColor( color );
1088 mImpl->RequestRelayout();
1092 const Vector4& Controller::GetDefaultColor() const
1094 return mImpl->mTextColor;
1097 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1099 if( NULL != mImpl->mEventData )
1101 mImpl->mEventData->mPlaceholderTextColor = textColor;
1104 if( mImpl->IsShowingPlaceholderText() )
1106 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1107 mImpl->RequestRelayout();
1111 const Vector4& Controller::GetPlaceholderTextColor() const
1113 if( NULL != mImpl->mEventData )
1115 return mImpl->mEventData->mPlaceholderTextColor;
1118 return Color::BLACK;
1121 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1123 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1125 mImpl->RequestRelayout();
1128 const Vector2& Controller::GetShadowOffset() const
1130 return mImpl->mModel->mVisualModel->GetShadowOffset();
1133 void Controller::SetShadowColor( const Vector4& shadowColor )
1135 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1137 mImpl->RequestRelayout();
1140 const Vector4& Controller::GetShadowColor() const
1142 return mImpl->mModel->mVisualModel->GetShadowColor();
1145 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1147 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1149 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1151 mImpl->RequestRelayout();
1155 const float& Controller::GetShadowBlurRadius() const
1157 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1160 void Controller::SetUnderlineColor( const Vector4& color )
1162 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1164 mImpl->RequestRelayout();
1167 const Vector4& Controller::GetUnderlineColor() const
1169 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1172 void Controller::SetUnderlineEnabled( bool enabled )
1174 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1176 mImpl->RequestRelayout();
1179 bool Controller::IsUnderlineEnabled() const
1181 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1184 void Controller::SetUnderlineHeight( float height )
1186 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1188 mImpl->RequestRelayout();
1191 float Controller::GetUnderlineHeight() const
1193 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1196 void Controller::SetOutlineColor( const Vector4& color )
1198 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1200 mImpl->RequestRelayout();
1203 const Vector4& Controller::GetOutlineColor() const
1205 return mImpl->mModel->mVisualModel->GetOutlineColor();
1208 void Controller::SetOutlineWidth( unsigned int width )
1210 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1212 mImpl->RequestRelayout();
1215 unsigned int Controller::GetOutlineWidth() const
1217 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1220 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1222 if( NULL == mImpl->mEmbossDefaults )
1224 mImpl->mEmbossDefaults = new EmbossDefaults();
1227 mImpl->mEmbossDefaults->properties = embossProperties;
1230 const std::string& Controller::GetDefaultEmbossProperties() const
1232 if( NULL != mImpl->mEmbossDefaults )
1234 return mImpl->mEmbossDefaults->properties;
1237 return EMPTY_STRING;
1240 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1242 if( NULL == mImpl->mOutlineDefaults )
1244 mImpl->mOutlineDefaults = new OutlineDefaults();
1247 mImpl->mOutlineDefaults->properties = outlineProperties;
1250 const std::string& Controller::GetDefaultOutlineProperties() const
1252 if( NULL != mImpl->mOutlineDefaults )
1254 return mImpl->mOutlineDefaults->properties;
1257 return EMPTY_STRING;
1260 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1262 if( std::abs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000 )
1264 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1265 mImpl->mRecalculateNaturalSize = true;
1271 float Controller::GetDefaultLineSpacing() const
1273 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1276 void Controller::SetInputColor( const Vector4& color )
1278 if( NULL != mImpl->mEventData )
1280 mImpl->mEventData->mInputStyle.textColor = color;
1281 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1283 if( EventData::SELECTING == mImpl->mEventData->mState )
1285 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1287 // Get start and end position of selection
1288 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1289 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1291 // Add the color run.
1292 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1293 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1295 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1296 colorRun.color = color;
1297 colorRun.characterRun.characterIndex = startOfSelectedText;
1298 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1300 // Request to relayout.
1301 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1302 mImpl->RequestRelayout();
1304 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1305 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1306 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1311 const Vector4& Controller::GetInputColor() const
1313 if( NULL != mImpl->mEventData )
1315 return mImpl->mEventData->mInputStyle.textColor;
1318 // Return the default text's color if there is no EventData.
1319 return mImpl->mTextColor;
1323 void Controller::SetInputFontFamily( const std::string& fontFamily )
1325 if( NULL != mImpl->mEventData )
1327 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1328 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1330 if( EventData::SELECTING == mImpl->mEventData->mState )
1332 CharacterIndex startOfSelectedText = 0u;
1333 Length lengthOfSelectedText = 0u;
1334 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1335 mImpl->mModel->mLogicalModel,
1336 startOfSelectedText,
1337 lengthOfSelectedText );
1339 fontDescriptionRun.familyLength = fontFamily.size();
1340 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1341 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1342 fontDescriptionRun.familyDefined = true;
1344 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1346 // Request to relayout.
1347 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1352 UPDATE_LAYOUT_SIZE |
1355 mImpl->mRecalculateNaturalSize = true;
1356 mImpl->RequestRelayout();
1358 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1359 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1360 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1362 // As the font changes, recalculate the handle positions is needed.
1363 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1364 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1365 mImpl->mEventData->mUpdateHighlightBox = true;
1366 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1371 const std::string& Controller::GetInputFontFamily() const
1373 if( NULL != mImpl->mEventData )
1375 return mImpl->mEventData->mInputStyle.familyName;
1378 // Return the default font's family if there is no EventData.
1379 return GetDefaultFontFamily();
1382 void Controller::SetInputFontWeight( FontWeight weight )
1384 if( NULL != mImpl->mEventData )
1386 mImpl->mEventData->mInputStyle.weight = weight;
1387 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1389 if( EventData::SELECTING == mImpl->mEventData->mState )
1391 CharacterIndex startOfSelectedText = 0u;
1392 Length lengthOfSelectedText = 0u;
1393 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1394 mImpl->mModel->mLogicalModel,
1395 startOfSelectedText,
1396 lengthOfSelectedText );
1398 fontDescriptionRun.weight = weight;
1399 fontDescriptionRun.weightDefined = true;
1401 // Request to relayout.
1402 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1407 UPDATE_LAYOUT_SIZE |
1410 mImpl->mRecalculateNaturalSize = true;
1411 mImpl->RequestRelayout();
1413 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1414 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1415 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1417 // As the font might change, recalculate the handle positions is needed.
1418 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1419 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1420 mImpl->mEventData->mUpdateHighlightBox = true;
1421 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1426 bool Controller::IsInputFontWeightDefined() const
1428 bool defined = false;
1430 if( NULL != mImpl->mEventData )
1432 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1438 FontWeight Controller::GetInputFontWeight() const
1440 if( NULL != mImpl->mEventData )
1442 return mImpl->mEventData->mInputStyle.weight;
1445 return GetDefaultFontWeight();
1448 void Controller::SetInputFontWidth( FontWidth width )
1450 if( NULL != mImpl->mEventData )
1452 mImpl->mEventData->mInputStyle.width = width;
1453 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1455 if( EventData::SELECTING == mImpl->mEventData->mState )
1457 CharacterIndex startOfSelectedText = 0u;
1458 Length lengthOfSelectedText = 0u;
1459 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1460 mImpl->mModel->mLogicalModel,
1461 startOfSelectedText,
1462 lengthOfSelectedText );
1464 fontDescriptionRun.width = width;
1465 fontDescriptionRun.widthDefined = true;
1467 // Request to relayout.
1468 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1473 UPDATE_LAYOUT_SIZE |
1476 mImpl->mRecalculateNaturalSize = true;
1477 mImpl->RequestRelayout();
1479 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1480 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1481 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1483 // As the font might change, recalculate the handle positions is needed.
1484 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1485 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1486 mImpl->mEventData->mUpdateHighlightBox = true;
1487 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1492 bool Controller::IsInputFontWidthDefined() const
1494 bool defined = false;
1496 if( NULL != mImpl->mEventData )
1498 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1504 FontWidth Controller::GetInputFontWidth() const
1506 if( NULL != mImpl->mEventData )
1508 return mImpl->mEventData->mInputStyle.width;
1511 return GetDefaultFontWidth();
1514 void Controller::SetInputFontSlant( FontSlant slant )
1516 if( NULL != mImpl->mEventData )
1518 mImpl->mEventData->mInputStyle.slant = slant;
1519 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1521 if( EventData::SELECTING == mImpl->mEventData->mState )
1523 CharacterIndex startOfSelectedText = 0u;
1524 Length lengthOfSelectedText = 0u;
1525 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1526 mImpl->mModel->mLogicalModel,
1527 startOfSelectedText,
1528 lengthOfSelectedText );
1530 fontDescriptionRun.slant = slant;
1531 fontDescriptionRun.slantDefined = true;
1533 // Request to relayout.
1534 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1539 UPDATE_LAYOUT_SIZE |
1542 mImpl->mRecalculateNaturalSize = true;
1543 mImpl->RequestRelayout();
1545 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1546 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1547 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1549 // As the font might change, recalculate the handle positions is needed.
1550 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1551 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1552 mImpl->mEventData->mUpdateHighlightBox = true;
1553 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1558 bool Controller::IsInputFontSlantDefined() const
1560 bool defined = false;
1562 if( NULL != mImpl->mEventData )
1564 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1570 FontSlant Controller::GetInputFontSlant() const
1572 if( NULL != mImpl->mEventData )
1574 return mImpl->mEventData->mInputStyle.slant;
1577 return GetDefaultFontSlant();
1580 void Controller::SetInputFontPointSize( float size )
1582 if( NULL != mImpl->mEventData )
1584 mImpl->mEventData->mInputStyle.size = size;
1585 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1587 if( EventData::SELECTING == mImpl->mEventData->mState )
1589 CharacterIndex startOfSelectedText = 0u;
1590 Length lengthOfSelectedText = 0u;
1591 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1592 mImpl->mModel->mLogicalModel,
1593 startOfSelectedText,
1594 lengthOfSelectedText );
1596 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1597 fontDescriptionRun.sizeDefined = true;
1599 // Request to relayout.
1600 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1605 UPDATE_LAYOUT_SIZE |
1608 mImpl->mRecalculateNaturalSize = true;
1609 mImpl->RequestRelayout();
1611 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1612 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1613 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1615 // As the font might change, recalculate the handle positions is needed.
1616 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1617 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1618 mImpl->mEventData->mUpdateHighlightBox = true;
1619 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1624 float Controller::GetInputFontPointSize() const
1626 if( NULL != mImpl->mEventData )
1628 return mImpl->mEventData->mInputStyle.size;
1631 // Return the default font's point size if there is no EventData.
1632 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1635 void Controller::SetInputLineSpacing( float lineSpacing )
1637 if( NULL != mImpl->mEventData )
1639 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1640 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1644 float Controller::GetInputLineSpacing() const
1646 if( NULL != mImpl->mEventData )
1648 return mImpl->mEventData->mInputStyle.lineSpacing;
1654 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1656 if( NULL != mImpl->mEventData )
1658 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1662 const std::string& Controller::GetInputShadowProperties() const
1664 if( NULL != mImpl->mEventData )
1666 return mImpl->mEventData->mInputStyle.shadowProperties;
1669 return EMPTY_STRING;
1672 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1674 if( NULL != mImpl->mEventData )
1676 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1680 const std::string& Controller::GetInputUnderlineProperties() const
1682 if( NULL != mImpl->mEventData )
1684 return mImpl->mEventData->mInputStyle.underlineProperties;
1687 return EMPTY_STRING;
1690 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1692 if( NULL != mImpl->mEventData )
1694 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1698 const std::string& Controller::GetInputEmbossProperties() const
1700 if( NULL != mImpl->mEventData )
1702 return mImpl->mEventData->mInputStyle.embossProperties;
1705 return GetDefaultEmbossProperties();
1708 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1710 if( NULL != mImpl->mEventData )
1712 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1716 const std::string& Controller::GetInputOutlineProperties() const
1718 if( NULL != mImpl->mEventData )
1720 return mImpl->mEventData->mInputStyle.outlineProperties;
1723 return GetDefaultOutlineProperties();
1726 void Controller::SetInputModePassword( bool passwordInput )
1728 if( NULL != mImpl->mEventData )
1730 mImpl->mEventData->mPasswordInput = passwordInput;
1734 bool Controller::IsInputModePassword()
1736 if( NULL != mImpl->mEventData )
1738 return mImpl->mEventData->mPasswordInput;
1743 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1745 if( NULL != mImpl->mEventData )
1747 mImpl->mEventData->mDoubleTapAction = action;
1751 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1753 NoTextTap::Action action = NoTextTap::NO_ACTION;
1755 if( NULL != mImpl->mEventData )
1757 action = mImpl->mEventData->mDoubleTapAction;
1763 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1765 if( NULL != mImpl->mEventData )
1767 mImpl->mEventData->mLongPressAction = action;
1771 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1773 NoTextTap::Action action = NoTextTap::NO_ACTION;
1775 if( NULL != mImpl->mEventData )
1777 action = mImpl->mEventData->mLongPressAction;
1783 bool Controller::IsUnderlineSetByString()
1785 return mImpl->mUnderlineSetByString;
1788 void Controller::UnderlineSetByString( bool setByString )
1790 mImpl->mUnderlineSetByString = setByString;
1793 bool Controller::IsShadowSetByString()
1795 return mImpl->mShadowSetByString;
1798 void Controller::ShadowSetByString( bool setByString )
1800 mImpl->mShadowSetByString = setByString;
1803 bool Controller::IsOutlineSetByString()
1805 return mImpl->mOutlineSetByString;
1808 void Controller::OutlineSetByString( bool setByString )
1810 mImpl->mOutlineSetByString = setByString;
1813 bool Controller::IsFontStyleSetByString()
1815 return mImpl->mFontStyleSetByString;
1818 void Controller::FontStyleSetByString( bool setByString )
1820 mImpl->mFontStyleSetByString = setByString;
1823 // public : Queries & retrieves.
1825 Layout::Engine& Controller::GetLayoutEngine()
1827 return mImpl->mLayoutEngine;
1830 View& Controller::GetView()
1832 return mImpl->mView;
1835 Vector3 Controller::GetNaturalSize()
1837 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1838 Vector3 naturalSize;
1840 // Make sure the model is up-to-date before layouting
1841 ProcessModifyEvents();
1843 if( mImpl->mRecalculateNaturalSize )
1845 // Operations that can be done only once until the text changes.
1846 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1853 GET_GLYPH_METRICS );
1855 // Set the update info to relayout the whole text.
1856 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1857 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1859 // Make sure the model is up-to-date before layouting
1860 mImpl->UpdateModel( onlyOnceOperations );
1862 // Layout the text for the new width.
1863 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1865 // Store the actual control's size to restore later.
1866 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1868 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1869 static_cast<OperationsMask>( onlyOnceOperations |
1871 naturalSize.GetVectorXY() );
1873 // Do not do again the only once operations.
1874 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1876 // Do the size related operations again.
1877 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1880 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1882 // Stores the natural size to avoid recalculate it again
1883 // unless the text/style changes.
1884 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1886 mImpl->mRecalculateNaturalSize = false;
1888 // Clear the update info. This info will be set the next time the text is updated.
1889 mImpl->mTextUpdateInfo.Clear();
1890 mImpl->mTextUpdateInfo.mClearAll = true;
1892 // Restore the actual control's size.
1893 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1895 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1899 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1901 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1904 naturalSize.x = ConvertToEven( naturalSize.x );
1905 naturalSize.y = ConvertToEven( naturalSize.y );
1910 float Controller::GetHeightForWidth( float width )
1912 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1913 // Make sure the model is up-to-date before layouting
1914 ProcessModifyEvents();
1917 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1918 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1919 mImpl->mTextUpdateInfo.mClearAll )
1921 // Operations that can be done only once until the text changes.
1922 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1929 GET_GLYPH_METRICS );
1931 // Set the update info to relayout the whole text.
1932 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1933 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1935 // Make sure the model is up-to-date before layouting
1936 mImpl->UpdateModel( onlyOnceOperations );
1939 // Layout the text for the new width.
1940 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1942 // Store the actual control's width.
1943 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1945 DoRelayout( Size( width, MAX_FLOAT ),
1946 static_cast<OperationsMask>( onlyOnceOperations |
1950 // Do not do again the only once operations.
1951 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1953 // Do the size related operations again.
1954 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1958 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1960 // Clear the update info. This info will be set the next time the text is updated.
1961 mImpl->mTextUpdateInfo.Clear();
1963 // Restore the actual control's width.
1964 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1966 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1970 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1971 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1974 return layoutSize.height;
1977 int Controller::GetLineCount( float width )
1979 GetHeightForWidth( width );
1980 int numberofLines = mImpl->mModel->GetNumberOfLines();
1981 return numberofLines;
1984 const ModelInterface* const Controller::GetTextModel() const
1986 return mImpl->mModel.Get();
1989 float Controller::GetScrollAmountByUserInput()
1991 float scrollAmount = 0.0f;
1993 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1995 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1996 mImpl->mEventData->mCheckScrollAmount = false;
1998 return scrollAmount;
2001 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2003 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2006 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2007 layoutHeight = layout.height;
2008 scrollPosition = mImpl->mModel->mScrollPosition.y;
2009 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2013 void Controller::SetHiddenInputOption(const Property::Map& options )
2015 if( NULL == mImpl->mHiddenInput )
2017 mImpl->mHiddenInput = new HiddenText( this );
2019 mImpl->mHiddenInput->SetProperties(options);
2022 void Controller::GetHiddenInputOption(Property::Map& options )
2024 if( NULL != mImpl->mHiddenInput )
2026 mImpl->mHiddenInput->GetProperties(options);
2030 void Controller::SetPlaceholderProperty( const Property::Map& map )
2032 const Property::Map::SizeType count = map.Count();
2034 for( Property::Map::SizeType position = 0; position < count; ++position )
2036 KeyValuePair keyValue = map.GetKeyValue( position );
2037 Property::Key& key = keyValue.first;
2038 Property::Value& value = keyValue.second;
2040 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2042 std::string text = "";
2044 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2046 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2048 std::string text = "";
2050 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2052 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2055 value.Get( textColor );
2056 if( GetPlaceholderTextColor() != textColor )
2058 SetPlaceholderTextColor( textColor );
2061 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2063 std::string fontFamily = "";
2064 value.Get( fontFamily );
2065 SetPlaceholderFontFamily( fontFamily );
2067 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2069 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2071 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2074 value.Get( pointSize );
2075 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2077 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2080 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2083 value.Get( pixelSize );
2084 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2086 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2089 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2092 value.Get( ellipsis );
2093 SetPlaceholderTextElideEnabled( ellipsis );
2098 void Controller::GetPlaceholderProperty( Property::Map& map )
2100 if( NULL != mImpl->mEventData )
2102 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2104 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2106 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2108 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2111 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2112 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2114 Property::Value fontStyleMapGet;
2115 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2116 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2118 // Choose font size : POINT_SIZE or PIXEL_SIZE
2119 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2121 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2125 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2128 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2130 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2135 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2137 // Make sure the model is up-to-date before layouting
2138 ProcessModifyEvents();
2140 if ( mImpl->mUpdateTextDirection )
2142 // Operations that can be done only once until the text changes.
2143 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( GET_SCRIPTS |
2150 // Set the update info to relayout the whole text.
2151 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2152 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2154 // Make sure the model is up-to-date before layouting
2155 mImpl->UpdateModel( onlyOnceOperations );
2157 Vector3 naturalSize;
2158 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2159 static_cast<OperationsMask>( onlyOnceOperations |
2160 LAYOUT | REORDER | UPDATE_DIRECTION ),
2161 naturalSize.GetVectorXY() );
2163 // Clear the update info. This info will be set the next time the text is updated.
2164 mImpl->mTextUpdateInfo.Clear();
2166 mImpl->mUpdateTextDirection = false;
2169 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2172 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2174 return mImpl->mModel->GetVerticalLineAlignment();
2177 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2179 mImpl->mModel->mVerticalLineAlignment = alignment;
2182 // public : Relayout.
2184 Controller::UpdateTextType Controller::Relayout( const Size& size )
2186 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2188 UpdateTextType updateTextType = NONE_UPDATED;
2190 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2192 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2194 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2195 updateTextType = MODEL_UPDATED;
2198 // Clear the update info. This info will be set the next time the text is updated.
2199 mImpl->mTextUpdateInfo.Clear();
2201 // Not worth to relayout if width or height is equal to zero.
2202 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2204 return updateTextType;
2207 // Whether a new size has been set.
2208 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2212 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2214 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2215 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2216 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2218 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2221 // Layout operations that need to be done if the size changes.
2222 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2225 UPDATE_LAYOUT_SIZE |
2227 // Set the update info to relayout the whole text.
2228 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2229 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2231 // Store the size used to layout the text.
2232 mImpl->mModel->mVisualModel->mControlSize = size;
2235 // Whether there are modify events.
2236 if( 0u != mImpl->mModifyEvents.Count() )
2238 // Style operations that need to be done if the text is modified.
2239 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2243 // Set the update info to elide the text.
2244 if( mImpl->mModel->mElideEnabled ||
2245 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2247 // Update Text layout for applying elided
2248 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2251 UPDATE_LAYOUT_SIZE |
2253 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2254 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2257 // Make sure the model is up-to-date before layouting.
2258 ProcessModifyEvents();
2259 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2263 updated = DoRelayout( size,
2264 mImpl->mOperationsPending,
2265 layoutSize ) || updated;
2269 updateTextType = MODEL_UPDATED;
2272 // Do not re-do any operation until something changes.
2273 mImpl->mOperationsPending = NO_OPERATION;
2274 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2276 // Whether the text control is editable
2277 const bool isEditable = NULL != mImpl->mEventData;
2279 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2281 if( newSize && isEditable )
2283 offset = mImpl->mModel->mScrollPosition;
2286 if( !isEditable || !IsMultiLineEnabled() )
2288 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2289 CalculateVerticalOffset( size );
2296 // If there is a new size, the scroll position needs to be clamped.
2297 mImpl->ClampHorizontalScroll( layoutSize );
2299 // Update the decorator's positions is needed if there is a new size.
2300 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2303 // Move the cursor, grab handle etc.
2304 if( mImpl->ProcessInputEvents() )
2306 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2310 // Clear the update info. This info will be set the next time the text is updated.
2311 mImpl->mTextUpdateInfo.Clear();
2312 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2314 return updateTextType;
2317 void Controller::RequestRelayout()
2319 mImpl->RequestRelayout();
2322 // public : Input style change signals.
2324 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2326 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2329 void Controller::ProcessInputStyleChangedSignals()
2331 if( NULL == mImpl->mEventData )
2337 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2338 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2342 const InputStyle::Mask mask = *it;
2344 if( NULL != mImpl->mEditableControlInterface )
2346 // Emit the input style changed signal.
2347 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2351 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2354 // public : Text-input Event Queuing.
2356 void Controller::KeyboardFocusGainEvent()
2358 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2360 if( NULL != mImpl->mEventData )
2362 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2363 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2365 mImpl->ChangeState( EventData::EDITING );
2366 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2367 mImpl->mEventData->mUpdateInputStyle = true;
2369 mImpl->NotifyImfMultiLineStatus();
2370 if( mImpl->IsShowingPlaceholderText() )
2372 // Show alternative placeholder-text when editing
2373 ShowPlaceholderText();
2376 mImpl->RequestRelayout();
2380 void Controller::KeyboardFocusLostEvent()
2382 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2384 if( NULL != mImpl->mEventData )
2386 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2388 mImpl->ChangeState( EventData::INACTIVE );
2390 if( !mImpl->IsShowingRealText() )
2392 // Revert to regular placeholder-text when not editing
2393 ShowPlaceholderText();
2397 mImpl->RequestRelayout();
2400 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2402 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2404 bool textChanged = false;
2405 bool relayoutNeeded = false;
2407 if( ( NULL != mImpl->mEventData ) &&
2408 ( keyEvent.state == KeyEvent::Down ) )
2410 int keyCode = keyEvent.keyCode;
2411 const std::string& keyString = keyEvent.keyPressed;
2412 const std::string keyName = keyEvent.keyPressedName;
2414 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2416 // Pre-process to separate modifying events from non-modifying input events.
2419 // In some platforms arrive key events with no key code.
2423 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2428 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2429 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2430 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2431 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2433 // If don't have any text, do nothing.
2434 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2439 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2440 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2441 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2442 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2444 // Logic to determine whether this text control will lose focus or not.
2445 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2446 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2447 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2448 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2449 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2450 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2452 // Release the active highlight.
2453 if( mImpl->mEventData->mState == EventData::SELECTING )
2455 mImpl->ChangeState( EventData::EDITING );
2457 // Update selection position.
2458 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2459 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2460 mImpl->mEventData->mUpdateCursorPosition = true;
2461 mImpl->RequestRelayout();
2466 mImpl->mEventData->mCheckScrollAmount = true;
2467 Event event( Event::CURSOR_KEY_EVENT );
2468 event.p1.mInt = keyCode;
2469 event.p2.mBool = keyEvent.IsShiftModifier();
2470 mImpl->mEventData->mEventQueue.push_back( event );
2472 // Will request for relayout.
2473 relayoutNeeded = true;
2475 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2477 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2478 // If not handle it here, any selected text will be deleted
2483 else if ( keyEvent.IsCtrlModifier() )
2485 bool consumed = false;
2486 if (keyName == KEY_C_NAME)
2488 // Ctrl-C to copy the selected text
2489 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2492 else if (keyName == KEY_V_NAME)
2494 // Ctrl-V to paste the copied text
2495 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2498 else if (keyName == KEY_X_NAME)
2500 // Ctrl-X to cut the selected text
2501 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2506 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2507 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2509 textChanged = DeleteEvent( keyCode );
2511 // Will request for relayout.
2512 relayoutNeeded = true;
2514 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2515 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2516 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2518 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2519 mImpl->ChangeState( EventData::INACTIVE );
2521 // Will request for relayout.
2522 relayoutNeeded = true;
2524 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2526 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2528 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2529 // and a character is typed after the type of a upper case latin character.
2534 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2536 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2542 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2544 // IMF manager is no longer handling key-events
2545 mImpl->ClearPreEditFlag();
2547 InsertText( keyString, COMMIT );
2550 // Will request for relayout.
2551 relayoutNeeded = true;
2554 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2555 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2557 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2558 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2559 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2561 // Should not change the state if the key is the shift send by the imf manager.
2562 // Otherwise, when the state is SELECTING the text controller can't send the right
2563 // surrounding info to the imf.
2564 mImpl->ChangeState( EventData::EDITING );
2566 // Will request for relayout.
2567 relayoutNeeded = true;
2570 if( relayoutNeeded )
2572 mImpl->RequestRelayout();
2577 ( NULL != mImpl->mEditableControlInterface ) )
2579 // Do this last since it provides callbacks into application code
2580 mImpl->mEditableControlInterface->TextChanged();
2586 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2588 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2590 if( NULL != mImpl->mEventData )
2592 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2593 EventData::State state( mImpl->mEventData->mState );
2594 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2596 if( mImpl->IsClipboardVisible() )
2598 if( EventData::INACTIVE == state || EventData::EDITING == state)
2600 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2602 relayoutNeeded = true;
2604 else if( 1u == tapCount )
2606 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2608 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2611 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2613 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2614 relayoutNeeded = true;
2618 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2620 // Hide placeholder text
2624 if( EventData::INACTIVE == state )
2626 mImpl->ChangeState( EventData::EDITING );
2628 else if( !mImpl->IsClipboardEmpty() )
2630 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2632 relayoutNeeded = true;
2635 else if( 2u == tapCount )
2637 if( mImpl->mEventData->mSelectionEnabled &&
2638 mImpl->IsShowingRealText() )
2640 relayoutNeeded = true;
2641 mImpl->mEventData->mIsLeftHandleSelected = true;
2642 mImpl->mEventData->mIsRightHandleSelected = true;
2646 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2647 if( relayoutNeeded )
2649 Event event( Event::TAP_EVENT );
2650 event.p1.mUint = tapCount;
2651 event.p2.mFloat = x;
2652 event.p3.mFloat = y;
2653 mImpl->mEventData->mEventQueue.push_back( event );
2655 mImpl->RequestRelayout();
2659 // Reset keyboard as tap event has occurred.
2660 mImpl->ResetImfManager();
2663 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2665 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2667 if( NULL != mImpl->mEventData )
2669 Event event( Event::PAN_EVENT );
2670 event.p1.mInt = state;
2671 event.p2.mFloat = displacement.x;
2672 event.p3.mFloat = displacement.y;
2673 mImpl->mEventData->mEventQueue.push_back( event );
2675 mImpl->RequestRelayout();
2679 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2681 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2683 if( ( state == Gesture::Started ) &&
2684 ( NULL != mImpl->mEventData ) )
2686 // The 1st long-press on inactive text-field is treated as tap
2687 if( EventData::INACTIVE == mImpl->mEventData->mState )
2689 mImpl->ChangeState( EventData::EDITING );
2691 Event event( Event::TAP_EVENT );
2693 event.p2.mFloat = x;
2694 event.p3.mFloat = y;
2695 mImpl->mEventData->mEventQueue.push_back( event );
2697 mImpl->RequestRelayout();
2699 else if( !mImpl->IsShowingRealText() )
2701 Event event( Event::LONG_PRESS_EVENT );
2702 event.p1.mInt = state;
2703 event.p2.mFloat = x;
2704 event.p3.mFloat = y;
2705 mImpl->mEventData->mEventQueue.push_back( event );
2706 mImpl->RequestRelayout();
2708 else if( !mImpl->IsClipboardVisible() )
2710 // Reset the imf manager to commit the pre-edit before selecting the text.
2711 mImpl->ResetImfManager();
2713 Event event( Event::LONG_PRESS_EVENT );
2714 event.p1.mInt = state;
2715 event.p2.mFloat = x;
2716 event.p3.mFloat = y;
2717 mImpl->mEventData->mEventQueue.push_back( event );
2718 mImpl->RequestRelayout();
2720 mImpl->mEventData->mIsLeftHandleSelected = true;
2721 mImpl->mEventData->mIsRightHandleSelected = true;
2726 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2728 // Whether the text needs to be relaid-out.
2729 bool requestRelayout = false;
2731 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2732 bool retrieveText = false;
2733 bool retrieveCursor = false;
2735 switch( imfEvent.eventName )
2737 case ImfManager::COMMIT:
2739 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2740 requestRelayout = true;
2741 retrieveCursor = true;
2744 case ImfManager::PREEDIT:
2746 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2747 requestRelayout = true;
2748 retrieveCursor = true;
2751 case ImfManager::DELETESURROUNDING:
2753 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2754 imfEvent.numberOfChars,
2755 DONT_UPDATE_INPUT_STYLE );
2759 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2760 !mImpl->IsPlaceholderAvailable() )
2762 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2766 ShowPlaceholderText();
2768 mImpl->mEventData->mUpdateCursorPosition = true;
2769 mImpl->mEventData->mScrollAfterDelete = true;
2771 requestRelayout = true;
2775 case ImfManager::GETSURROUNDING:
2777 retrieveText = true;
2778 retrieveCursor = true;
2781 case ImfManager::PRIVATECOMMAND:
2783 // PRIVATECOMMAND event is just for getting the private command message
2784 retrieveText = true;
2785 retrieveCursor = true;
2788 case ImfManager::VOID:
2795 if( requestRelayout )
2797 mImpl->mOperationsPending = ALL_OPERATIONS;
2798 mImpl->RequestRelayout();
2802 CharacterIndex cursorPosition = 0u;
2803 Length numberOfWhiteSpaces = 0u;
2805 if( retrieveCursor )
2807 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2809 cursorPosition = mImpl->GetLogicalCursorPosition();
2811 if( cursorPosition < numberOfWhiteSpaces )
2813 cursorPosition = 0u;
2817 cursorPosition -= numberOfWhiteSpaces;
2823 if( !mImpl->IsShowingPlaceholderText() )
2825 // Retrieves the normal text string.
2826 mImpl->GetText( numberOfWhiteSpaces, text );
2830 // When the current text is Placeholder Text, the surrounding text should be empty string.
2831 // It means DALi should send empty string ("") to IME.
2836 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2838 if( requestRelayout &&
2839 ( NULL != mImpl->mEditableControlInterface ) )
2841 // Do this last since it provides callbacks into application code
2842 mImpl->mEditableControlInterface->TextChanged();
2845 return callbackData;
2848 void Controller::PasteClipboardItemEvent()
2850 // Retrieve the clipboard contents first
2851 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2852 std::string stringToPaste( notifier.GetContent() );
2854 // Commit the current pre-edit text; the contents of the clipboard should be appended
2855 mImpl->ResetImfManager();
2857 // Temporary disable hiding clipboard
2858 mImpl->SetClipboardHideEnable( false );
2861 PasteText( stringToPaste );
2863 mImpl->SetClipboardHideEnable( true );
2866 // protected : Inherit from Text::Decorator::ControllerInterface.
2868 void Controller::GetTargetSize( Vector2& targetSize )
2870 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2873 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2875 if( NULL != mImpl->mEditableControlInterface )
2877 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2881 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2883 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2885 if( NULL != mImpl->mEventData )
2887 switch( handleType )
2891 Event event( Event::GRAB_HANDLE_EVENT );
2892 event.p1.mUint = state;
2893 event.p2.mFloat = x;
2894 event.p3.mFloat = y;
2896 mImpl->mEventData->mEventQueue.push_back( event );
2899 case LEFT_SELECTION_HANDLE:
2901 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2902 event.p1.mUint = state;
2903 event.p2.mFloat = x;
2904 event.p3.mFloat = y;
2906 mImpl->mEventData->mEventQueue.push_back( event );
2909 case RIGHT_SELECTION_HANDLE:
2911 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2912 event.p1.mUint = state;
2913 event.p2.mFloat = x;
2914 event.p3.mFloat = y;
2916 mImpl->mEventData->mEventQueue.push_back( event );
2919 case LEFT_SELECTION_HANDLE_MARKER:
2920 case RIGHT_SELECTION_HANDLE_MARKER:
2922 // Markers do not move the handles.
2925 case HANDLE_TYPE_COUNT:
2927 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2931 mImpl->RequestRelayout();
2935 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2937 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2939 if( NULL == mImpl->mEventData )
2946 case Toolkit::TextSelectionPopup::CUT:
2948 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2949 mImpl->mOperationsPending = ALL_OPERATIONS;
2951 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2952 !mImpl->IsPlaceholderAvailable() )
2954 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2958 ShowPlaceholderText();
2961 mImpl->mEventData->mUpdateCursorPosition = true;
2962 mImpl->mEventData->mScrollAfterDelete = true;
2964 mImpl->RequestRelayout();
2966 if( NULL != mImpl->mEditableControlInterface )
2968 mImpl->mEditableControlInterface->TextChanged();
2972 case Toolkit::TextSelectionPopup::COPY:
2974 mImpl->SendSelectionToClipboard( false ); // Text not modified
2976 mImpl->mEventData->mUpdateCursorPosition = true;
2978 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2981 case Toolkit::TextSelectionPopup::PASTE:
2983 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2986 case Toolkit::TextSelectionPopup::SELECT:
2988 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2990 if( mImpl->mEventData->mSelectionEnabled )
2992 // Creates a SELECT event.
2993 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2997 case Toolkit::TextSelectionPopup::SELECT_ALL:
2999 // Creates a SELECT_ALL event
3000 SelectEvent( 0.f, 0.f, true );
3003 case Toolkit::TextSelectionPopup::CLIPBOARD:
3005 mImpl->ShowClipboard();
3008 case Toolkit::TextSelectionPopup::NONE:
3016 void Controller::DisplayTimeExpired()
3018 mImpl->mEventData->mUpdateCursorPosition = true;
3019 // Apply modifications to the model
3020 mImpl->mOperationsPending = ALL_OPERATIONS;
3022 mImpl->RequestRelayout();
3025 // private : Update.
3027 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3029 bool removedPrevious = false;
3030 bool removedSelected = false;
3031 bool maxLengthReached = false;
3033 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3035 if( NULL == mImpl->mEventData )
3040 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3041 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3042 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3044 // TODO: At the moment the underline runs are only for pre-edit.
3045 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3047 // Remove the previous IMF pre-edit.
3048 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3050 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3051 mImpl->mEventData->mPreEditLength,
3052 DONT_UPDATE_INPUT_STYLE );
3054 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3055 mImpl->mEventData->mPreEditLength = 0u;
3059 // Remove the previous Selection.
3060 removedSelected = RemoveSelectedText();
3064 Vector<Character> utf32Characters;
3065 Length characterCount = 0u;
3069 // Convert text into UTF-32
3070 utf32Characters.Resize( text.size() );
3072 // This is a bit horrible but std::string returns a (signed) char*
3073 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3075 // Transform a text array encoded in utf8 into an array encoded in utf32.
3076 // It returns the actual number of characters.
3077 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3078 utf32Characters.Resize( characterCount );
3080 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3081 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3084 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3086 // The placeholder text is no longer needed
3087 if( mImpl->IsShowingPlaceholderText() )
3092 mImpl->ChangeState( EventData::EDITING );
3094 // Handle the IMF (predicitive text) state changes
3095 if( COMMIT == type )
3097 // IMF manager is no longer handling key-events
3098 mImpl->ClearPreEditFlag();
3102 if( !mImpl->mEventData->mPreEditFlag )
3104 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3106 // Record the start of the pre-edit text
3107 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3110 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3111 mImpl->mEventData->mPreEditFlag = true;
3113 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3116 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3118 // Restrict new text to fit within Maximum characters setting.
3119 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3120 maxLengthReached = ( characterCount > maxSizeOfNewText );
3122 // The cursor position.
3123 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3125 // Update the text's style.
3127 // Updates the text style runs by adding characters.
3128 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3130 // Get the character index from the cursor index.
3131 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3133 // Retrieve the text's style for the given index.
3135 mImpl->RetrieveDefaultInputStyle( style );
3136 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3138 // Whether to add a new text color run.
3139 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3141 // Whether to add a new font run.
3142 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3143 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3144 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3145 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3146 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3151 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3152 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3154 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3155 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3156 colorRun.characterRun.characterIndex = cursorIndex;
3157 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3160 if( addFontNameRun ||
3166 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3167 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3169 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3171 if( addFontNameRun )
3173 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3174 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3175 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3176 fontDescriptionRun.familyDefined = true;
3178 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3181 if( addFontWeightRun )
3183 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3184 fontDescriptionRun.weightDefined = true;
3187 if( addFontWidthRun )
3189 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3190 fontDescriptionRun.widthDefined = true;
3193 if( addFontSlantRun )
3195 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3196 fontDescriptionRun.slantDefined = true;
3199 if( addFontSizeRun )
3201 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3202 fontDescriptionRun.sizeDefined = true;
3205 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3206 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3209 // Insert at current cursor position.
3210 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3212 if( cursorIndex < numberOfCharactersInModel )
3214 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3218 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3221 // Mark the first paragraph to be updated.
3222 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3224 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3225 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3226 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3227 mImpl->mTextUpdateInfo.mClearAll = true;
3231 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3232 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3235 // Update the cursor index.
3236 cursorIndex += maxSizeOfNewText;
3238 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 );
3241 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3242 mImpl->IsPlaceholderAvailable() )
3244 // Show place-holder if empty after removing the pre-edit text
3245 ShowPlaceholderText();
3246 mImpl->mEventData->mUpdateCursorPosition = true;
3247 mImpl->ClearPreEditFlag();
3249 else if( removedPrevious ||
3251 ( 0 != utf32Characters.Count() ) )
3253 // Queue an inserted event
3254 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3256 mImpl->mEventData->mUpdateCursorPosition = true;
3257 if( removedSelected )
3259 mImpl->mEventData->mScrollAfterDelete = true;
3263 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3267 if( maxLengthReached )
3269 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3271 mImpl->ResetImfManager();
3273 if( NULL != mImpl->mEditableControlInterface )
3275 // Do this last since it provides callbacks into application code
3276 mImpl->mEditableControlInterface->MaxLengthReached();
3281 void Controller::PasteText( const std::string& stringToPaste )
3283 InsertText( stringToPaste, Text::Controller::COMMIT );
3284 mImpl->ChangeState( EventData::EDITING );
3285 mImpl->RequestRelayout();
3287 if( NULL != mImpl->mEditableControlInterface )
3289 // Do this last since it provides callbacks into application code
3290 mImpl->mEditableControlInterface->TextChanged();
3294 bool Controller::RemoveText( int cursorOffset,
3295 int numberOfCharacters,
3296 UpdateInputStyleType type )
3298 bool removed = false;
3300 if( NULL == mImpl->mEventData )
3305 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3306 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3308 if( !mImpl->IsShowingPlaceholderText() )
3310 // Delete at current cursor position
3311 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3312 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3314 CharacterIndex cursorIndex = 0;
3316 // Validate the cursor position & number of characters
3317 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3319 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3322 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3324 numberOfCharacters = currentText.Count() - cursorIndex;
3327 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.
3328 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3330 // Mark the paragraphs to be updated.
3331 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3333 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3334 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3335 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3336 mImpl->mTextUpdateInfo.mClearAll = true;
3340 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3341 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3344 // Update the input style and remove the text's style before removing the text.
3346 if( UPDATE_INPUT_STYLE == type )
3348 // Keep a copy of the current input style.
3349 InputStyle currentInputStyle;
3350 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3352 // Set first the default input style.
3353 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3355 // Update the input style.
3356 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3358 // Compare if the input style has changed.
3359 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3361 if( hasInputStyleChanged )
3363 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3364 // Queue the input style changed signal.
3365 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3369 // Updates the text style runs by removing characters. Runs with no characters are removed.
3370 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3372 // Remove the characters.
3373 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3374 Vector<Character>::Iterator last = first + numberOfCharacters;
3376 currentText.Erase( first, last );
3378 // Cursor position retreat
3379 oldCursorIndex = cursorIndex;
3381 mImpl->mEventData->mScrollAfterDelete = true;
3383 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3391 bool Controller::RemoveSelectedText()
3393 bool textRemoved( false );
3395 if( EventData::SELECTING == mImpl->mEventData->mState )
3397 std::string removedString;
3398 mImpl->RetrieveSelection( removedString, true );
3400 if( !removedString.empty() )
3403 mImpl->ChangeState( EventData::EDITING );
3410 // private : Relayout.
3412 bool Controller::DoRelayout( const Size& size,
3413 OperationsMask operationsRequired,
3416 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3417 bool viewUpdated( false );
3419 // Calculate the operations to be done.
3420 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3422 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3423 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3425 // Get the current layout size.
3426 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3428 if( NO_OPERATION != ( LAYOUT & operations ) )
3430 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3432 // Some vectors with data needed to layout and reorder may be void
3433 // after the first time the text has been laid out.
3434 // Fill the vectors again.
3436 // Calculate the number of glyphs to layout.
3437 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3438 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3439 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3440 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3442 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3443 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3445 // Make sure the index is not out of bound
3446 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3447 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3448 ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3450 std::string currentText;
3451 GetText( currentText );
3453 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3454 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3455 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3460 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3461 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3463 if( 0u == totalNumberOfGlyphs )
3465 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3467 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3470 // Nothing else to do if there is no glyphs.
3471 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3475 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3476 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3477 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3478 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3479 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3480 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3481 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3482 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3484 // Set the layout parameters.
3485 const Vector2 sizeOffset = Vector2(outlineWidth * 2.0f, outlineWidth * 2.0f); // The outline should be fit into the bounding box
3486 Layout::Parameters layoutParameters( size - sizeOffset,
3488 lineBreakInfo.Begin(),
3489 wordBreakInfo.Begin(),
3490 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3492 glyphsToCharactersMap.Begin(),
3493 charactersPerGlyph.Begin(),
3494 charactersToGlyphBuffer,
3495 glyphsPerCharacterBuffer,
3496 totalNumberOfGlyphs,
3497 mImpl->mModel->mHorizontalAlignment,
3498 mImpl->mModel->mLineWrapMode,
3501 // Resize the vector of positions to have the same size than the vector of glyphs.
3502 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3503 glyphPositions.Resize( totalNumberOfGlyphs );
3505 // Whether the last character is a new paragraph character.
3506 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3507 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3509 // The initial glyph and the number of glyphs to layout.
3510 layoutParameters.startGlyphIndex = startGlyphIndex;
3511 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3512 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3513 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3515 // Update the ellipsis
3516 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3518 if( NULL != mImpl->mEventData )
3520 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3522 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3524 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3526 // Disable ellipsis when editing
3527 elideTextEnabled = false;
3530 // Reset the scroll position in inactive state
3531 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3533 ResetScrollPosition();
3537 // Update the visual model.
3539 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3541 mImpl->mModel->mVisualModel->mLines,
3545 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3549 layoutSize = newLayoutSize;
3551 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3553 mImpl->mIsTextDirectionRTL = false;
3556 // Reorder the lines
3557 if( NO_OPERATION != ( REORDER & operations ) )
3559 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3560 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3562 // Check first if there are paragraphs with bidirectional info.
3563 if( 0u != bidirectionalInfo.Count() )
3566 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3568 // Reorder the lines.
3569 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3570 ReorderLines( bidirectionalInfo,
3572 requestedNumberOfCharacters,
3573 mImpl->mModel->mVisualModel->mLines,
3574 bidirectionalLineInfo );
3576 // Set the bidirectional info per line into the layout parameters.
3577 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3578 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3580 // Re-layout the text. Reorder those lines with right to left characters.
3581 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3583 requestedNumberOfCharacters,
3586 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3588 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3591 mImpl->mIsTextDirectionRTL = firstline->direction;
3597 // Sets the layout size.
3598 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3600 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3605 if( NO_OPERATION != ( ALIGN & operations ) )
3607 // The laid-out lines.
3608 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3610 // Need to align with the control's size as the text may contain lines
3611 // starting either with left to right text or right to left.
3612 mImpl->mLayoutEngine.Align( size,
3614 requestedNumberOfCharacters,
3615 mImpl->mModel->mHorizontalAlignment,
3617 mImpl->mModel->mAlignmentOffset );
3621 #if defined(DEBUG_ENABLED)
3622 std::string currentText;
3623 GetText( currentText );
3624 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3626 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3630 void Controller::CalculateVerticalOffset( const Size& controlSize )
3632 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3634 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3636 // Get the line height of the default font.
3637 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3640 switch( mImpl->mModel->mVerticalAlignment )
3642 case VerticalAlignment::TOP:
3644 mImpl->mModel->mScrollPosition.y = 0.f;
3647 case VerticalAlignment::CENTER:
3649 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3652 case VerticalAlignment::BOTTOM:
3654 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3660 // private : Events.
3662 void Controller::ProcessModifyEvents()
3664 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3666 if( 0u == events.Count() )
3672 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3673 endIt = events.End();
3677 const ModifyEvent& event = *it;
3679 if( ModifyEvent::TEXT_REPLACED == event.type )
3681 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3682 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3684 TextReplacedEvent();
3686 else if( ModifyEvent::TEXT_INSERTED == event.type )
3688 TextInsertedEvent();
3690 else if( ModifyEvent::TEXT_DELETED == event.type )
3692 // Placeholder-text cannot be deleted
3693 if( !mImpl->IsShowingPlaceholderText() )
3700 if( NULL != mImpl->mEventData )
3702 // When the text is being modified, delay cursor blinking
3703 mImpl->mEventData->mDecorator->DelayCursorBlink();
3705 // Update selection position after modifying the text
3706 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3707 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3710 // Discard temporary text
3714 void Controller::TextReplacedEvent()
3716 // The natural size needs to be re-calculated.
3717 mImpl->mRecalculateNaturalSize = true;
3719 // The text direction needs to be updated.
3720 mImpl->mUpdateTextDirection = true;
3722 // Apply modifications to the model
3723 mImpl->mOperationsPending = ALL_OPERATIONS;
3726 void Controller::TextInsertedEvent()
3728 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3730 if( NULL == mImpl->mEventData )
3735 mImpl->mEventData->mCheckScrollAmount = true;
3737 // The natural size needs to be re-calculated.
3738 mImpl->mRecalculateNaturalSize = true;
3740 // The text direction needs to be updated.
3741 mImpl->mUpdateTextDirection = true;
3743 // Apply modifications to the model; TODO - Optimize this
3744 mImpl->mOperationsPending = ALL_OPERATIONS;
3747 void Controller::TextDeletedEvent()
3749 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3751 if( NULL == mImpl->mEventData )
3756 mImpl->mEventData->mCheckScrollAmount = true;
3758 // The natural size needs to be re-calculated.
3759 mImpl->mRecalculateNaturalSize = true;
3761 // The text direction needs to be updated.
3762 mImpl->mUpdateTextDirection = true;
3764 // Apply modifications to the model; TODO - Optimize this
3765 mImpl->mOperationsPending = ALL_OPERATIONS;
3768 void Controller::SelectEvent( float x, float y, bool selectAll )
3770 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3772 if( NULL != mImpl->mEventData )
3776 Event event( Event::SELECT_ALL );
3777 mImpl->mEventData->mEventQueue.push_back( event );
3781 Event event( Event::SELECT );
3782 event.p2.mFloat = x;
3783 event.p3.mFloat = y;
3784 mImpl->mEventData->mEventQueue.push_back( event );
3787 mImpl->mEventData->mCheckScrollAmount = true;
3788 mImpl->mEventData->mIsLeftHandleSelected = true;
3789 mImpl->mEventData->mIsRightHandleSelected = true;
3790 mImpl->RequestRelayout();
3794 bool Controller::DeleteEvent( int keyCode )
3796 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3798 bool removed = false;
3800 if( NULL == mImpl->mEventData )
3805 // IMF manager is no longer handling key-events
3806 mImpl->ClearPreEditFlag();
3808 if( EventData::SELECTING == mImpl->mEventData->mState )
3810 removed = RemoveSelectedText();
3812 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3814 // Remove the character before the current cursor position
3815 removed = RemoveText( -1,
3817 UPDATE_INPUT_STYLE );
3819 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
3821 // Remove the character after the current cursor position
3822 removed = RemoveText( 0,
3824 UPDATE_INPUT_STYLE );
3829 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3830 !mImpl->IsPlaceholderAvailable() )
3832 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3836 ShowPlaceholderText();
3838 mImpl->mEventData->mUpdateCursorPosition = true;
3839 mImpl->mEventData->mScrollAfterDelete = true;
3845 // private : Helpers.
3847 void Controller::ResetText()
3850 mImpl->mModel->mLogicalModel->mText.Clear();
3852 // We have cleared everything including the placeholder-text
3853 mImpl->PlaceholderCleared();
3855 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3856 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3857 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3859 // Clear any previous text.
3860 mImpl->mTextUpdateInfo.mClearAll = true;
3862 // The natural size needs to be re-calculated.
3863 mImpl->mRecalculateNaturalSize = true;
3865 // The text direction needs to be updated.
3866 mImpl->mUpdateTextDirection = true;
3868 // Apply modifications to the model
3869 mImpl->mOperationsPending = ALL_OPERATIONS;
3872 void Controller::ShowPlaceholderText()
3874 if( mImpl->IsPlaceholderAvailable() )
3876 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3878 if( NULL == mImpl->mEventData )
3883 mImpl->mEventData->mIsShowingPlaceholderText = true;
3885 // Disable handles when showing place-holder text
3886 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3887 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3888 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3890 const char* text( NULL );
3893 // TODO - Switch Placeholder text when changing state
3894 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3895 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3897 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3898 size = mImpl->mEventData->mPlaceholderTextActive.size();
3902 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3903 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3906 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3907 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3909 // Reset model for showing placeholder.
3910 mImpl->mModel->mLogicalModel->mText.Clear();
3911 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3913 // Convert text into UTF-32
3914 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3915 utf32Characters.Resize( size );
3917 // This is a bit horrible but std::string returns a (signed) char*
3918 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3920 // Transform a text array encoded in utf8 into an array encoded in utf32.
3921 // It returns the actual number of characters.
3922 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3923 utf32Characters.Resize( characterCount );
3925 // The characters to be added.
3926 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3928 // Reset the cursor position
3929 mImpl->mEventData->mPrimaryCursorPosition = 0;
3931 // The natural size needs to be re-calculated.
3932 mImpl->mRecalculateNaturalSize = true;
3934 // The text direction needs to be updated.
3935 mImpl->mUpdateTextDirection = true;
3937 // Apply modifications to the model
3938 mImpl->mOperationsPending = ALL_OPERATIONS;
3940 // Update the rest of the model during size negotiation
3941 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3945 void Controller::ClearFontData()
3947 if( mImpl->mFontDefaults )
3949 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3952 // Set flags to update the model.
3953 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3954 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3955 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3957 mImpl->mTextUpdateInfo.mClearAll = true;
3958 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3959 mImpl->mRecalculateNaturalSize = true;
3961 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3967 UPDATE_LAYOUT_SIZE |
3972 void Controller::ClearStyleData()
3974 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3975 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3978 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3980 // Reset the cursor position
3981 if( NULL != mImpl->mEventData )
3983 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3985 // Update the cursor if it's in editing mode.
3986 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3988 mImpl->mEventData->mUpdateCursorPosition = true;
3993 void Controller::ResetScrollPosition()
3995 if( NULL != mImpl->mEventData )
3997 // Reset the scroll position.
3998 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3999 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4003 void Controller::SetControlInterface( ControlInterface* controlInterface )
4005 mImpl->mControlInterface = controlInterface;
4008 bool Controller::ShouldClearFocusOnEscape() const
4010 return mImpl->mShouldClearFocusOnEscape;
4013 // private : Private contructors & copy operator.
4015 Controller::Controller()
4018 mImpl = new Controller::Impl( NULL, NULL );
4021 Controller::Controller( ControlInterface* controlInterface )
4023 mImpl = new Controller::Impl( controlInterface, NULL );
4026 Controller::Controller( ControlInterface* controlInterface,
4027 EditableControlInterface* editableControlInterface )
4029 mImpl = new Controller::Impl( controlInterface,
4030 editableControlInterface );
4033 // The copy constructor and operator are left unimplemented.
4035 // protected : Destructor.
4037 Controller::~Controller()
4044 } // namespace Toolkit