2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
28 #include <dali/devel-api/adaptor-framework/key-devel.h>
31 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
32 #include <dali-toolkit/internal/text/bidirectional-support.h>
33 #include <dali-toolkit/internal/text/character-set-conversion.h>
34 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
35 #include <dali-toolkit/internal/text/markup-processor.h>
36 #include <dali-toolkit/internal/text/multi-language-support.h>
37 #include <dali-toolkit/internal/text/text-controller-impl.h>
38 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
39 #include <dali-toolkit/internal/text/text-font-style.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
48 const float MAX_FLOAT = std::numeric_limits<float>::max();
50 const std::string EMPTY_STRING("");
52 const std::string KEY_C_NAME = "c";
53 const std::string KEY_V_NAME = "v";
54 const std::string KEY_X_NAME = "x";
56 const char * const PLACEHOLDER_TEXT = "text";
57 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
58 const char * const PLACEHOLDER_COLOR = "color";
59 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
60 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
61 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
62 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
63 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 float ConvertToEven( float value )
67 int intValue(static_cast<int>( value ));
68 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
83 * @brief Adds a new font description run for the selected text.
85 * The new font parameters are added after the call to this method.
87 * @param[in] eventData The event data pointer.
88 * @param[in] logicalModel The logical model where to add the new font description run.
89 * @param[out] startOfSelectedText Index to the first selected character.
90 * @param[out] lengthOfSelectedText Number of selected characters.
92 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
93 LogicalModelPtr logicalModel,
94 CharacterIndex& startOfSelectedText,
95 Length& lengthOfSelectedText )
97 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
99 // Get start and end position of selection
100 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
101 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
104 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
105 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
107 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
109 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
110 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
112 // Recalculate the selection highlight as the metrics may have changed.
113 eventData->mUpdateLeftSelectionPosition = true;
114 eventData->mUpdateRightSelectionPosition = true;
115 eventData->mUpdateHighlightBox = true;
117 return fontDescriptionRun;
120 // public : Constructor.
122 ControllerPtr Controller::New()
124 return ControllerPtr( new Controller() );
127 ControllerPtr Controller::New( ControlInterface* controlInterface )
129 return ControllerPtr( new Controller( controlInterface ) );
132 ControllerPtr Controller::New( ControlInterface* controlInterface,
133 EditableControlInterface* editableControlInterface )
135 return ControllerPtr( new Controller( controlInterface,
136 editableControlInterface ) );
139 // public : Configure the text controller.
141 void Controller::EnableTextInput( DecoratorPtr decorator )
145 delete mImpl->mEventData;
146 mImpl->mEventData = NULL;
148 // Nothing else to do.
152 if( NULL == mImpl->mEventData )
154 mImpl->mEventData = new EventData( decorator );
158 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
160 // Metrics for bitmap & vector based glyphs are different
161 mImpl->mMetrics->SetGlyphType( glyphType );
163 // Clear the font-specific data
166 mImpl->RequestRelayout();
169 void Controller::SetMarkupProcessorEnabled( bool enable )
171 mImpl->mMarkupProcessorEnabled = enable;
174 bool Controller::IsMarkupProcessorEnabled() const
176 return mImpl->mMarkupProcessorEnabled;
179 void Controller::SetAutoScrollEnabled( bool enable )
181 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
183 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
187 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
188 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
198 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
199 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
206 mImpl->mIsAutoScrollEnabled = enable;
207 mImpl->RequestRelayout();
211 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
212 mImpl->mIsAutoScrollEnabled = false;
216 bool Controller::IsAutoScrollEnabled() const
218 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
220 return mImpl->mIsAutoScrollEnabled;
223 CharacterDirection Controller::GetAutoScrollDirection() const
225 return mImpl->mAutoScrollDirectionRTL;
228 float Controller::GetAutoScrollLineAlignment() const
232 if( mImpl->mModel->mVisualModel &&
233 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
235 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
241 void Controller::SetHorizontalScrollEnabled( bool enable )
243 if( ( NULL != mImpl->mEventData ) &&
244 mImpl->mEventData->mDecorator )
246 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
249 bool Controller::IsHorizontalScrollEnabled() const
251 if( ( NULL != mImpl->mEventData ) &&
252 mImpl->mEventData->mDecorator )
254 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
260 void Controller::SetVerticalScrollEnabled( bool enable )
262 if( ( NULL != mImpl->mEventData ) &&
263 mImpl->mEventData->mDecorator )
265 if( mImpl->mEventData->mDecorator )
267 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
272 bool Controller::IsVerticalScrollEnabled() const
274 if( ( NULL != mImpl->mEventData ) &&
275 mImpl->mEventData->mDecorator )
277 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
283 void Controller::SetSmoothHandlePanEnabled( bool enable )
285 if( ( NULL != mImpl->mEventData ) &&
286 mImpl->mEventData->mDecorator )
288 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
292 bool Controller::IsSmoothHandlePanEnabled() const
294 if( ( NULL != mImpl->mEventData ) &&
295 mImpl->mEventData->mDecorator )
297 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
303 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
305 mImpl->mMaximumNumberOfCharacters = maxCharacters;
308 int Controller::GetMaximumNumberOfCharacters()
310 return mImpl->mMaximumNumberOfCharacters;
313 void Controller::SetEnableCursorBlink( bool enable )
315 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
317 if( NULL != mImpl->mEventData )
319 mImpl->mEventData->mCursorBlinkEnabled = enable;
322 mImpl->mEventData->mDecorator )
324 mImpl->mEventData->mDecorator->StopCursorBlink();
329 bool Controller::GetEnableCursorBlink() const
331 if( NULL != mImpl->mEventData )
333 return mImpl->mEventData->mCursorBlinkEnabled;
339 void Controller::SetMultiLineEnabled( bool enable )
341 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
343 if( layout != mImpl->mLayoutEngine.GetLayout() )
345 // Set the layout type.
346 mImpl->mLayoutEngine.SetLayout( layout );
348 // Set the flags to redo the layout operations
349 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
354 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
355 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
357 mImpl->RequestRelayout();
361 bool Controller::IsMultiLineEnabled() const
363 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
366 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
368 if( alignment != mImpl->mModel->mHorizontalAlignment )
370 // Set the alignment.
371 mImpl->mModel->mHorizontalAlignment = alignment;
373 // Set the flag to redo the alignment operation.
374 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
376 mImpl->RequestRelayout();
380 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
382 return mImpl->mModel->mHorizontalAlignment;
385 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
387 if( alignment != mImpl->mModel->mVerticalAlignment )
389 // Set the alignment.
390 mImpl->mModel->mVerticalAlignment = alignment;
392 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
394 mImpl->RequestRelayout();
398 VerticalAlignment::Type Controller::GetVerticalAlignment() const
400 return mImpl->mModel->mVerticalAlignment;
403 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
405 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
407 // Set the text wrap mode.
408 mImpl->mModel->mLineWrapMode = lineWrapMode;
411 // Update Text layout for applying wrap mode
412 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
417 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
418 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
419 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
422 mImpl->RequestRelayout();
426 Text::LineWrap::Mode Controller::GetLineWrapMode() const
428 return mImpl->mModel->mLineWrapMode;
431 void Controller::SetTextElideEnabled( bool enabled )
433 mImpl->mModel->mElideEnabled = enabled;
436 bool Controller::IsTextElideEnabled() const
438 return mImpl->mModel->mElideEnabled;
441 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
443 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
444 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
446 // Update placeholder if there is no text
447 if( mImpl->IsShowingPlaceholderText() ||
448 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
450 ShowPlaceholderText();
454 bool Controller::IsPlaceholderTextElideEnabled() const
456 return mImpl->mEventData->mIsPlaceholderElideEnabled;
459 void Controller::SetSelectionEnabled( bool enabled )
461 mImpl->mEventData->mSelectionEnabled = enabled;
464 bool Controller::IsSelectionEnabled() const
466 return mImpl->mEventData->mSelectionEnabled;
469 void Controller::SetShiftSelectionEnabled( bool enabled )
471 mImpl->mEventData->mShiftSelectionFlag = enabled;
474 bool Controller::IsShiftSelectionEnabled() const
476 return mImpl->mEventData->mShiftSelectionFlag;
481 void Controller::SetText( const std::string& text )
483 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
485 // Reset keyboard as text changed
486 mImpl->ResetImfManager();
488 // Remove the previously set text and style.
494 CharacterIndex lastCursorIndex = 0u;
496 if( NULL != mImpl->mEventData )
498 // If popup shown then hide it by switching to Editing state
499 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
500 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
501 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
502 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
504 mImpl->ChangeState( EventData::EDITING );
510 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
512 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
513 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
515 Length textSize = 0u;
516 const uint8_t* utf8 = NULL;
517 if( mImpl->mMarkupProcessorEnabled )
519 ProcessMarkupString( text, markupProcessData );
520 textSize = markupProcessData.markupProcessedText.size();
522 // This is a bit horrible but std::string returns a (signed) char*
523 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
527 textSize = text.size();
529 // This is a bit horrible but std::string returns a (signed) char*
530 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
533 // Convert text into UTF-32
534 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
535 utf32Characters.Resize( textSize );
537 // Transform a text array encoded in utf8 into an array encoded in utf32.
538 // It returns the actual number of characters.
539 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
540 utf32Characters.Resize( characterCount );
542 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
543 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
545 // The characters to be added.
546 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
548 // To reset the cursor position
549 lastCursorIndex = characterCount;
551 // Update the rest of the model during size negotiation
552 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
554 // The natural size needs to be re-calculated.
555 mImpl->mRecalculateNaturalSize = true;
557 // Apply modifications to the model
558 mImpl->mOperationsPending = ALL_OPERATIONS;
562 ShowPlaceholderText();
565 // Resets the cursor position.
566 ResetCursorPosition( lastCursorIndex );
568 // Scrolls the text to make the cursor visible.
569 ResetScrollPosition();
571 mImpl->RequestRelayout();
573 if( NULL != mImpl->mEventData )
575 // Cancel previously queued events
576 mImpl->mEventData->mEventQueue.clear();
579 // Do this last since it provides callbacks into application code.
580 if( NULL != mImpl->mEditableControlInterface )
582 mImpl->mEditableControlInterface->TextChanged();
586 void Controller::GetText( std::string& text ) const
588 if( !mImpl->IsShowingPlaceholderText() )
590 // Retrieves the text string.
591 mImpl->GetText( 0u, text );
595 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
599 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
601 if( NULL != mImpl->mEventData )
603 if( PLACEHOLDER_TYPE_INACTIVE == type )
605 mImpl->mEventData->mPlaceholderTextInactive = text;
609 mImpl->mEventData->mPlaceholderTextActive = text;
612 // Update placeholder if there is no text
613 if( mImpl->IsShowingPlaceholderText() ||
614 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
616 ShowPlaceholderText();
621 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
623 if( NULL != mImpl->mEventData )
625 if( PLACEHOLDER_TYPE_INACTIVE == type )
627 text = mImpl->mEventData->mPlaceholderTextInactive;
631 text = mImpl->mEventData->mPlaceholderTextActive;
636 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
638 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
640 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
642 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
643 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
647 mImpl->RequestRelayout();
651 // public : Default style & Input style
653 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
655 if( NULL == mImpl->mFontDefaults )
657 mImpl->mFontDefaults = new FontDefaults();
660 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
661 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
662 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
664 // Clear the font-specific data
667 mImpl->RequestRelayout();
670 const std::string& Controller::GetDefaultFontFamily() const
672 if( NULL != mImpl->mFontDefaults )
674 return mImpl->mFontDefaults->mFontDescription.family;
680 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
682 if( NULL != mImpl->mEventData )
684 if( NULL == mImpl->mEventData->mPlaceholderFont )
686 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
689 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
690 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
691 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
693 mImpl->RequestRelayout();
697 const std::string& Controller::GetPlaceholderFontFamily() const
699 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
701 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
707 void Controller::SetDefaultFontWeight( FontWeight weight )
709 if( NULL == mImpl->mFontDefaults )
711 mImpl->mFontDefaults = new FontDefaults();
714 mImpl->mFontDefaults->mFontDescription.weight = weight;
715 mImpl->mFontDefaults->weightDefined = true;
717 // Clear the font-specific data
720 mImpl->RequestRelayout();
723 bool Controller::IsDefaultFontWeightDefined() const
725 if( NULL != mImpl->mFontDefaults )
727 return mImpl->mFontDefaults->weightDefined;
733 FontWeight Controller::GetDefaultFontWeight() const
735 if( NULL != mImpl->mFontDefaults )
737 return mImpl->mFontDefaults->mFontDescription.weight;
740 return TextAbstraction::FontWeight::NORMAL;
743 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
745 if( NULL != mImpl->mEventData )
747 if( NULL == mImpl->mEventData->mPlaceholderFont )
749 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
752 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
753 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
755 mImpl->RequestRelayout();
759 bool Controller::IsPlaceholderTextFontWeightDefined() const
761 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
763 return mImpl->mEventData->mPlaceholderFont->weightDefined;
768 FontWeight Controller::GetPlaceholderTextFontWeight() const
770 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
772 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
775 return TextAbstraction::FontWeight::NORMAL;
778 void Controller::SetDefaultFontWidth( FontWidth width )
780 if( NULL == mImpl->mFontDefaults )
782 mImpl->mFontDefaults = new FontDefaults();
785 mImpl->mFontDefaults->mFontDescription.width = width;
786 mImpl->mFontDefaults->widthDefined = true;
788 // Clear the font-specific data
791 mImpl->RequestRelayout();
794 bool Controller::IsDefaultFontWidthDefined() const
796 if( NULL != mImpl->mFontDefaults )
798 return mImpl->mFontDefaults->widthDefined;
804 FontWidth Controller::GetDefaultFontWidth() const
806 if( NULL != mImpl->mFontDefaults )
808 return mImpl->mFontDefaults->mFontDescription.width;
811 return TextAbstraction::FontWidth::NORMAL;
814 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
816 if( NULL != mImpl->mEventData )
818 if( NULL == mImpl->mEventData->mPlaceholderFont )
820 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
823 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
824 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
826 mImpl->RequestRelayout();
830 bool Controller::IsPlaceholderTextFontWidthDefined() const
832 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
834 return mImpl->mEventData->mPlaceholderFont->widthDefined;
839 FontWidth Controller::GetPlaceholderTextFontWidth() const
841 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
843 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
846 return TextAbstraction::FontWidth::NORMAL;
849 void Controller::SetDefaultFontSlant( FontSlant slant )
851 if( NULL == mImpl->mFontDefaults )
853 mImpl->mFontDefaults = new FontDefaults();
856 mImpl->mFontDefaults->mFontDescription.slant = slant;
857 mImpl->mFontDefaults->slantDefined = true;
859 // Clear the font-specific data
862 mImpl->RequestRelayout();
865 bool Controller::IsDefaultFontSlantDefined() const
867 if( NULL != mImpl->mFontDefaults )
869 return mImpl->mFontDefaults->slantDefined;
874 FontSlant Controller::GetDefaultFontSlant() const
876 if( NULL != mImpl->mFontDefaults )
878 return mImpl->mFontDefaults->mFontDescription.slant;
881 return TextAbstraction::FontSlant::NORMAL;
884 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
886 if( NULL != mImpl->mEventData )
888 if( NULL == mImpl->mEventData->mPlaceholderFont )
890 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
893 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
894 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
896 mImpl->RequestRelayout();
900 bool Controller::IsPlaceholderTextFontSlantDefined() const
902 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
904 return mImpl->mEventData->mPlaceholderFont->slantDefined;
909 FontSlant Controller::GetPlaceholderTextFontSlant() const
911 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
913 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
916 return TextAbstraction::FontSlant::NORMAL;
919 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
921 if( NULL == mImpl->mFontDefaults )
923 mImpl->mFontDefaults = new FontDefaults();
930 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
931 mImpl->mFontDefaults->sizeDefined = true;
936 // Point size = Pixel size * 72.f / DPI
937 unsigned int horizontalDpi = 0u;
938 unsigned int verticalDpi = 0u;
939 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
940 fontClient.GetDpi( horizontalDpi, verticalDpi );
942 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
943 mImpl->mFontDefaults->sizeDefined = true;
948 // Clear the font-specific data
951 mImpl->RequestRelayout();
954 float Controller::GetDefaultFontSize( FontSizeType type ) const
957 if( NULL != mImpl->mFontDefaults )
963 value = mImpl->mFontDefaults->mDefaultPointSize;
968 // Pixel size = Point size * DPI / 72.f
969 unsigned int horizontalDpi = 0u;
970 unsigned int verticalDpi = 0u;
971 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
972 fontClient.GetDpi( horizontalDpi, verticalDpi );
974 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
984 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
986 if( NULL != mImpl->mEventData )
988 if( NULL == mImpl->mEventData->mPlaceholderFont )
990 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
997 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
998 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
999 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1004 // Point size = Pixel size * 72.f / DPI
1005 unsigned int horizontalDpi = 0u;
1006 unsigned int verticalDpi = 0u;
1007 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1008 fontClient.GetDpi( horizontalDpi, verticalDpi );
1010 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1011 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1012 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1017 mImpl->RequestRelayout();
1021 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1024 if( NULL != mImpl->mEventData )
1030 if( NULL != mImpl->mEventData->mPlaceholderFont )
1032 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1036 // If the placeholder text font size is not set, then return the default font size.
1037 value = GetDefaultFontSize( POINT_SIZE );
1043 if( NULL != mImpl->mEventData->mPlaceholderFont )
1045 // Pixel size = Point size * DPI / 72.f
1046 unsigned int horizontalDpi = 0u;
1047 unsigned int verticalDpi = 0u;
1048 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1049 fontClient.GetDpi( horizontalDpi, verticalDpi );
1051 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1055 // If the placeholder text font size is not set, then return the default font size.
1056 value = GetDefaultFontSize( PIXEL_SIZE );
1067 void Controller::SetDefaultColor( const Vector4& color )
1069 mImpl->mTextColor = color;
1071 if( !mImpl->IsShowingPlaceholderText() )
1073 mImpl->mModel->mVisualModel->SetTextColor( color );
1075 mImpl->RequestRelayout();
1079 const Vector4& Controller::GetDefaultColor() const
1081 return mImpl->mTextColor;
1084 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1086 if( NULL != mImpl->mEventData )
1088 mImpl->mEventData->mPlaceholderTextColor = textColor;
1091 if( mImpl->IsShowingPlaceholderText() )
1093 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1094 mImpl->RequestRelayout();
1098 const Vector4& Controller::GetPlaceholderTextColor() const
1100 if( NULL != mImpl->mEventData )
1102 return mImpl->mEventData->mPlaceholderTextColor;
1105 return Color::BLACK;
1108 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1110 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1112 mImpl->RequestRelayout();
1115 const Vector2& Controller::GetShadowOffset() const
1117 return mImpl->mModel->mVisualModel->GetShadowOffset();
1120 void Controller::SetShadowColor( const Vector4& shadowColor )
1122 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1124 mImpl->RequestRelayout();
1127 const Vector4& Controller::GetShadowColor() const
1129 return mImpl->mModel->mVisualModel->GetShadowColor();
1132 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1134 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1136 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1138 mImpl->RequestRelayout();
1142 const float& Controller::GetShadowBlurRadius() const
1144 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1147 void Controller::SetUnderlineColor( const Vector4& color )
1149 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1151 mImpl->RequestRelayout();
1154 const Vector4& Controller::GetUnderlineColor() const
1156 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1159 void Controller::SetUnderlineEnabled( bool enabled )
1161 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1163 mImpl->RequestRelayout();
1166 bool Controller::IsUnderlineEnabled() const
1168 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1171 void Controller::SetUnderlineHeight( float height )
1173 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1175 mImpl->RequestRelayout();
1178 float Controller::GetUnderlineHeight() const
1180 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1183 void Controller::SetOutlineColor( const Vector4& color )
1185 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1187 mImpl->RequestRelayout();
1190 const Vector4& Controller::GetOutlineColor() const
1192 return mImpl->mModel->mVisualModel->GetOutlineColor();
1195 void Controller::SetOutlineWidth( unsigned int width )
1197 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1199 mImpl->RequestRelayout();
1202 unsigned int Controller::GetOutlineWidth() const
1204 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1207 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1209 if( NULL == mImpl->mEmbossDefaults )
1211 mImpl->mEmbossDefaults = new EmbossDefaults();
1214 mImpl->mEmbossDefaults->properties = embossProperties;
1217 const std::string& Controller::GetDefaultEmbossProperties() const
1219 if( NULL != mImpl->mEmbossDefaults )
1221 return mImpl->mEmbossDefaults->properties;
1224 return EMPTY_STRING;
1227 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1229 if( NULL == mImpl->mOutlineDefaults )
1231 mImpl->mOutlineDefaults = new OutlineDefaults();
1234 mImpl->mOutlineDefaults->properties = outlineProperties;
1237 const std::string& Controller::GetDefaultOutlineProperties() const
1239 if( NULL != mImpl->mOutlineDefaults )
1241 return mImpl->mOutlineDefaults->properties;
1244 return EMPTY_STRING;
1247 void Controller::SetDefaultLineSpacing( float lineSpacing )
1249 //TODO finish implementation
1250 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1253 float Controller::GetDefaultLineSpacing() const
1255 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1258 void Controller::SetInputColor( const Vector4& color )
1260 if( NULL != mImpl->mEventData )
1262 mImpl->mEventData->mInputStyle.textColor = color;
1263 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1265 if( EventData::SELECTING == mImpl->mEventData->mState )
1267 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1269 // Get start and end position of selection
1270 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1271 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1273 // Add the color run.
1274 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1275 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1277 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1278 colorRun.color = color;
1279 colorRun.characterRun.characterIndex = startOfSelectedText;
1280 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1282 // Request to relayout.
1283 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1284 mImpl->RequestRelayout();
1286 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1287 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1288 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1293 const Vector4& Controller::GetInputColor() const
1295 if( NULL != mImpl->mEventData )
1297 return mImpl->mEventData->mInputStyle.textColor;
1300 // Return the default text's color if there is no EventData.
1301 return mImpl->mTextColor;
1305 void Controller::SetInputFontFamily( const std::string& fontFamily )
1307 if( NULL != mImpl->mEventData )
1309 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1310 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1312 if( EventData::SELECTING == mImpl->mEventData->mState )
1314 CharacterIndex startOfSelectedText = 0u;
1315 Length lengthOfSelectedText = 0u;
1316 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1317 mImpl->mModel->mLogicalModel,
1318 startOfSelectedText,
1319 lengthOfSelectedText );
1321 fontDescriptionRun.familyLength = fontFamily.size();
1322 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1323 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1324 fontDescriptionRun.familyDefined = true;
1326 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1328 // Request to relayout.
1329 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1334 UPDATE_LAYOUT_SIZE |
1337 mImpl->mRecalculateNaturalSize = true;
1338 mImpl->RequestRelayout();
1340 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1341 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1342 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1344 // As the font changes, recalculate the handle positions is needed.
1345 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1346 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1347 mImpl->mEventData->mUpdateHighlightBox = true;
1348 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1353 const std::string& Controller::GetInputFontFamily() const
1355 if( NULL != mImpl->mEventData )
1357 return mImpl->mEventData->mInputStyle.familyName;
1360 // Return the default font's family if there is no EventData.
1361 return GetDefaultFontFamily();
1364 void Controller::SetInputFontWeight( FontWeight weight )
1366 if( NULL != mImpl->mEventData )
1368 mImpl->mEventData->mInputStyle.weight = weight;
1369 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1371 if( EventData::SELECTING == mImpl->mEventData->mState )
1373 CharacterIndex startOfSelectedText = 0u;
1374 Length lengthOfSelectedText = 0u;
1375 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1376 mImpl->mModel->mLogicalModel,
1377 startOfSelectedText,
1378 lengthOfSelectedText );
1380 fontDescriptionRun.weight = weight;
1381 fontDescriptionRun.weightDefined = true;
1383 // Request to relayout.
1384 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1389 UPDATE_LAYOUT_SIZE |
1392 mImpl->mRecalculateNaturalSize = true;
1393 mImpl->RequestRelayout();
1395 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1396 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1397 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1399 // As the font might change, recalculate the handle positions is needed.
1400 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1401 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1402 mImpl->mEventData->mUpdateHighlightBox = true;
1403 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1408 bool Controller::IsInputFontWeightDefined() const
1410 bool defined = false;
1412 if( NULL != mImpl->mEventData )
1414 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1420 FontWeight Controller::GetInputFontWeight() const
1422 if( NULL != mImpl->mEventData )
1424 return mImpl->mEventData->mInputStyle.weight;
1427 return GetDefaultFontWeight();
1430 void Controller::SetInputFontWidth( FontWidth width )
1432 if( NULL != mImpl->mEventData )
1434 mImpl->mEventData->mInputStyle.width = width;
1435 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1437 if( EventData::SELECTING == mImpl->mEventData->mState )
1439 CharacterIndex startOfSelectedText = 0u;
1440 Length lengthOfSelectedText = 0u;
1441 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1442 mImpl->mModel->mLogicalModel,
1443 startOfSelectedText,
1444 lengthOfSelectedText );
1446 fontDescriptionRun.width = width;
1447 fontDescriptionRun.widthDefined = true;
1449 // Request to relayout.
1450 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1455 UPDATE_LAYOUT_SIZE |
1458 mImpl->mRecalculateNaturalSize = true;
1459 mImpl->RequestRelayout();
1461 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1462 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1463 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1465 // As the font might change, recalculate the handle positions is needed.
1466 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1467 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1468 mImpl->mEventData->mUpdateHighlightBox = true;
1469 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1474 bool Controller::IsInputFontWidthDefined() const
1476 bool defined = false;
1478 if( NULL != mImpl->mEventData )
1480 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1486 FontWidth Controller::GetInputFontWidth() const
1488 if( NULL != mImpl->mEventData )
1490 return mImpl->mEventData->mInputStyle.width;
1493 return GetDefaultFontWidth();
1496 void Controller::SetInputFontSlant( FontSlant slant )
1498 if( NULL != mImpl->mEventData )
1500 mImpl->mEventData->mInputStyle.slant = slant;
1501 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1503 if( EventData::SELECTING == mImpl->mEventData->mState )
1505 CharacterIndex startOfSelectedText = 0u;
1506 Length lengthOfSelectedText = 0u;
1507 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1508 mImpl->mModel->mLogicalModel,
1509 startOfSelectedText,
1510 lengthOfSelectedText );
1512 fontDescriptionRun.slant = slant;
1513 fontDescriptionRun.slantDefined = true;
1515 // Request to relayout.
1516 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1521 UPDATE_LAYOUT_SIZE |
1524 mImpl->mRecalculateNaturalSize = true;
1525 mImpl->RequestRelayout();
1527 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1528 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1529 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1531 // As the font might change, recalculate the handle positions is needed.
1532 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1533 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1534 mImpl->mEventData->mUpdateHighlightBox = true;
1535 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1540 bool Controller::IsInputFontSlantDefined() const
1542 bool defined = false;
1544 if( NULL != mImpl->mEventData )
1546 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1552 FontSlant Controller::GetInputFontSlant() const
1554 if( NULL != mImpl->mEventData )
1556 return mImpl->mEventData->mInputStyle.slant;
1559 return GetDefaultFontSlant();
1562 void Controller::SetInputFontPointSize( float size )
1564 if( NULL != mImpl->mEventData )
1566 mImpl->mEventData->mInputStyle.size = size;
1567 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1569 if( EventData::SELECTING == mImpl->mEventData->mState )
1571 CharacterIndex startOfSelectedText = 0u;
1572 Length lengthOfSelectedText = 0u;
1573 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1574 mImpl->mModel->mLogicalModel,
1575 startOfSelectedText,
1576 lengthOfSelectedText );
1578 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1579 fontDescriptionRun.sizeDefined = true;
1581 // Request to relayout.
1582 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1587 UPDATE_LAYOUT_SIZE |
1590 mImpl->mRecalculateNaturalSize = true;
1591 mImpl->RequestRelayout();
1593 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1594 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1595 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1597 // As the font might change, recalculate the handle positions is needed.
1598 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1599 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1600 mImpl->mEventData->mUpdateHighlightBox = true;
1601 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1606 float Controller::GetInputFontPointSize() const
1608 if( NULL != mImpl->mEventData )
1610 return mImpl->mEventData->mInputStyle.size;
1613 // Return the default font's point size if there is no EventData.
1614 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1617 void Controller::SetInputLineSpacing( float lineSpacing )
1619 if( NULL != mImpl->mEventData )
1621 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1622 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1626 float Controller::GetInputLineSpacing() const
1628 if( NULL != mImpl->mEventData )
1630 return mImpl->mEventData->mInputStyle.lineSpacing;
1636 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1638 if( NULL != mImpl->mEventData )
1640 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1644 const std::string& Controller::GetInputShadowProperties() const
1646 if( NULL != mImpl->mEventData )
1648 return mImpl->mEventData->mInputStyle.shadowProperties;
1651 return EMPTY_STRING;
1654 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1656 if( NULL != mImpl->mEventData )
1658 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1662 const std::string& Controller::GetInputUnderlineProperties() const
1664 if( NULL != mImpl->mEventData )
1666 return mImpl->mEventData->mInputStyle.underlineProperties;
1669 return EMPTY_STRING;
1672 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1674 if( NULL != mImpl->mEventData )
1676 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1680 const std::string& Controller::GetInputEmbossProperties() const
1682 if( NULL != mImpl->mEventData )
1684 return mImpl->mEventData->mInputStyle.embossProperties;
1687 return GetDefaultEmbossProperties();
1690 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1692 if( NULL != mImpl->mEventData )
1694 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1698 const std::string& Controller::GetInputOutlineProperties() const
1700 if( NULL != mImpl->mEventData )
1702 return mImpl->mEventData->mInputStyle.outlineProperties;
1705 return GetDefaultOutlineProperties();
1708 void Controller::SetInputModePassword( bool passwordInput )
1710 if( NULL != mImpl->mEventData )
1712 mImpl->mEventData->mPasswordInput = passwordInput;
1716 bool Controller::IsInputModePassword()
1718 if( NULL != mImpl->mEventData )
1720 return mImpl->mEventData->mPasswordInput;
1725 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1727 if( NULL != mImpl->mEventData )
1729 mImpl->mEventData->mDoubleTapAction = action;
1733 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1735 NoTextTap::Action action = NoTextTap::NO_ACTION;
1737 if( NULL != mImpl->mEventData )
1739 action = mImpl->mEventData->mDoubleTapAction;
1745 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1747 if( NULL != mImpl->mEventData )
1749 mImpl->mEventData->mLongPressAction = action;
1753 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1755 NoTextTap::Action action = NoTextTap::NO_ACTION;
1757 if( NULL != mImpl->mEventData )
1759 action = mImpl->mEventData->mLongPressAction;
1765 bool Controller::IsUnderlineSetByString()
1767 return mImpl->mUnderlineSetByString;
1770 void Controller::UnderlineSetByString( bool setByString )
1772 mImpl->mUnderlineSetByString = setByString;
1775 bool Controller::IsShadowSetByString()
1777 return mImpl->mShadowSetByString;
1780 void Controller::ShadowSetByString( bool setByString )
1782 mImpl->mShadowSetByString = setByString;
1785 bool Controller::IsOutlineSetByString()
1787 return mImpl->mOutlineSetByString;
1790 void Controller::OutlineSetByString( bool setByString )
1792 mImpl->mOutlineSetByString = setByString;
1795 bool Controller::IsFontStyleSetByString()
1797 return mImpl->mFontStyleSetByString;
1800 void Controller::FontStyleSetByString( bool setByString )
1802 mImpl->mFontStyleSetByString = setByString;
1805 // public : Queries & retrieves.
1807 Layout::Engine& Controller::GetLayoutEngine()
1809 return mImpl->mLayoutEngine;
1812 View& Controller::GetView()
1814 return mImpl->mView;
1817 Vector3 Controller::GetNaturalSize()
1819 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1820 Vector3 naturalSize;
1822 // Make sure the model is up-to-date before layouting
1823 ProcessModifyEvents();
1825 if( mImpl->mRecalculateNaturalSize )
1827 // Operations that can be done only once until the text changes.
1828 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1835 GET_GLYPH_METRICS );
1837 // Set the update info to relayout the whole text.
1838 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1839 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1841 // Make sure the model is up-to-date before layouting
1842 mImpl->UpdateModel( onlyOnceOperations );
1844 // Layout the text for the new width.
1845 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1847 // Store the actual control's size to restore later.
1848 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1850 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1851 static_cast<OperationsMask>( onlyOnceOperations |
1853 naturalSize.GetVectorXY() );
1855 // Do not do again the only once operations.
1856 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1858 // Do the size related operations again.
1859 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1862 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1864 // Stores the natural size to avoid recalculate it again
1865 // unless the text/style changes.
1866 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1868 mImpl->mRecalculateNaturalSize = false;
1870 // Clear the update info. This info will be set the next time the text is updated.
1871 mImpl->mTextUpdateInfo.Clear();
1873 // Restore the actual control's size.
1874 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1876 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1880 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1882 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1885 naturalSize.x = ConvertToEven( naturalSize.x );
1886 naturalSize.y = ConvertToEven( naturalSize.y );
1891 float Controller::GetHeightForWidth( float width )
1893 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1894 // Make sure the model is up-to-date before layouting
1895 ProcessModifyEvents();
1898 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1899 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1900 mImpl->mTextUpdateInfo.mClearAll )
1902 // Operations that can be done only once until the text changes.
1903 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1910 GET_GLYPH_METRICS );
1912 // Set the update info to relayout the whole text.
1913 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1914 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1916 // Make sure the model is up-to-date before layouting
1917 mImpl->UpdateModel( onlyOnceOperations );
1920 // Layout the text for the new width.
1921 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1923 // Store the actual control's width.
1924 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1926 DoRelayout( Size( width, MAX_FLOAT ),
1927 static_cast<OperationsMask>( onlyOnceOperations |
1931 // Do not do again the only once operations.
1932 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1934 // Do the size related operations again.
1935 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1939 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1941 // Clear the update info. This info will be set the next time the text is updated.
1942 mImpl->mTextUpdateInfo.Clear();
1944 // Restore the actual control's width.
1945 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1947 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1951 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1952 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1955 return layoutSize.height;
1958 int Controller::GetLineCount( float width )
1960 GetHeightForWidth( width );
1961 int numberofLines = mImpl->mModel->GetNumberOfLines();
1962 return numberofLines;
1965 const ModelInterface* const Controller::GetTextModel() const
1967 return mImpl->mModel.Get();
1970 float Controller::GetScrollAmountByUserInput()
1972 float scrollAmount = 0.0f;
1974 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1976 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1977 mImpl->mEventData->mCheckScrollAmount = false;
1979 return scrollAmount;
1982 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1984 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1987 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1988 layoutHeight = layout.height;
1989 scrollPosition = mImpl->mModel->mScrollPosition.y;
1990 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1994 void Controller::SetHiddenInputOption(const Property::Map& options )
1996 if( NULL == mImpl->mHiddenInput )
1998 mImpl->mHiddenInput = new HiddenText( this );
2000 mImpl->mHiddenInput->SetProperties(options);
2003 void Controller::GetHiddenInputOption(Property::Map& options )
2005 if( NULL != mImpl->mHiddenInput )
2007 mImpl->mHiddenInput->GetProperties(options);
2011 void Controller::SetPlaceholderProperty( const Property::Map& map )
2013 const Property::Map::SizeType count = map.Count();
2015 for( Property::Map::SizeType position = 0; position < count; ++position )
2017 KeyValuePair keyValue = map.GetKeyValue( position );
2018 Property::Key& key = keyValue.first;
2019 Property::Value& value = keyValue.second;
2021 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2023 std::string text = "";
2025 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2027 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2029 std::string text = "";
2031 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2033 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2036 value.Get( textColor );
2037 if( GetPlaceholderTextColor() != textColor )
2039 SetPlaceholderTextColor( textColor );
2042 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2044 std::string fontFamily = "";
2045 value.Get( fontFamily );
2046 SetPlaceholderFontFamily( fontFamily );
2048 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2050 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2052 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2055 value.Get( pointSize );
2056 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2058 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2061 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2064 value.Get( pixelSize );
2065 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2067 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2070 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2073 value.Get( ellipsis );
2074 SetPlaceholderTextElideEnabled( ellipsis );
2079 void Controller::GetPlaceholderProperty( Property::Map& map )
2081 if( NULL != mImpl->mEventData )
2083 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2085 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2087 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2089 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2092 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2093 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2095 Property::Value fontStyleMapGet;
2096 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2097 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2099 // Choose font size : POINT_SIZE or PIXEL_SIZE
2100 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2102 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2106 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2109 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2111 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2116 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2118 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
2120 return Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2123 const Character character = mImpl->mModel->mLogicalModel->mText[0];
2124 Script script = TextAbstraction::GetCharacterScript( character );
2126 if( TextAbstraction::IsRightToLeftScript( script ) )
2128 return Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT;
2131 return Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2134 // public : Relayout.
2136 Controller::UpdateTextType Controller::Relayout( const Size& size )
2138 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2140 UpdateTextType updateTextType = NONE_UPDATED;
2142 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2144 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2146 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2147 updateTextType = MODEL_UPDATED;
2150 // Clear the update info. This info will be set the next time the text is updated.
2151 mImpl->mTextUpdateInfo.Clear();
2153 // Not worth to relayout if width or height is equal to zero.
2154 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2156 return updateTextType;
2159 // Whether a new size has been set.
2160 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2164 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2166 // Layout operations that need to be done if the size changes.
2167 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2170 UPDATE_LAYOUT_SIZE |
2172 // Set the update info to relayout the whole text.
2173 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2174 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2176 // Store the size used to layout the text.
2177 mImpl->mModel->mVisualModel->mControlSize = size;
2180 // Whether there are modify events.
2181 if( 0u != mImpl->mModifyEvents.Count() )
2183 // Style operations that need to be done if the text is modified.
2184 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2188 // Set the update info to elide the text.
2189 if( mImpl->mModel->mElideEnabled ||
2190 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2192 // Update Text layout for applying elided
2193 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2196 UPDATE_LAYOUT_SIZE |
2198 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2199 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2202 // Make sure the model is up-to-date before layouting.
2203 ProcessModifyEvents();
2204 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2208 updated = DoRelayout( size,
2209 mImpl->mOperationsPending,
2210 layoutSize ) || updated;
2214 updateTextType = MODEL_UPDATED;
2217 // Do not re-do any operation until something changes.
2218 mImpl->mOperationsPending = NO_OPERATION;
2219 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2221 // Whether the text control is editable
2222 const bool isEditable = NULL != mImpl->mEventData;
2224 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2226 if( newSize && isEditable )
2228 offset = mImpl->mModel->mScrollPosition;
2231 if( !isEditable || !IsMultiLineEnabled() )
2233 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2234 CalculateVerticalOffset( size );
2241 // If there is a new size, the scroll position needs to be clamped.
2242 mImpl->ClampHorizontalScroll( layoutSize );
2244 // Update the decorator's positions is needed if there is a new size.
2245 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2248 // Move the cursor, grab handle etc.
2249 if( mImpl->ProcessInputEvents() )
2251 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2255 // Clear the update info. This info will be set the next time the text is updated.
2256 mImpl->mTextUpdateInfo.Clear();
2257 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2259 return updateTextType;
2262 void Controller::RequestRelayout()
2264 mImpl->RequestRelayout();
2267 // public : Input style change signals.
2269 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2271 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2274 void Controller::ProcessInputStyleChangedSignals()
2276 if( NULL == mImpl->mEventData )
2282 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2283 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2287 const InputStyle::Mask mask = *it;
2289 if( NULL != mImpl->mEditableControlInterface )
2291 // Emit the input style changed signal.
2292 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2296 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2299 // public : Text-input Event Queuing.
2301 void Controller::KeyboardFocusGainEvent()
2303 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2305 if( NULL != mImpl->mEventData )
2307 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2308 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2310 mImpl->ChangeState( EventData::EDITING );
2311 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2312 mImpl->mEventData->mUpdateInputStyle = true;
2314 mImpl->NotifyImfMultiLineStatus();
2315 if( mImpl->IsShowingPlaceholderText() )
2317 // Show alternative placeholder-text when editing
2318 ShowPlaceholderText();
2321 mImpl->RequestRelayout();
2325 void Controller::KeyboardFocusLostEvent()
2327 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2329 if( NULL != mImpl->mEventData )
2331 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2333 mImpl->ChangeState( EventData::INACTIVE );
2335 if( !mImpl->IsShowingRealText() )
2337 // Revert to regular placeholder-text when not editing
2338 ShowPlaceholderText();
2342 mImpl->RequestRelayout();
2345 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2347 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2349 bool textChanged = false;
2350 bool relayoutNeeded = false;
2352 if( ( NULL != mImpl->mEventData ) &&
2353 ( keyEvent.state == KeyEvent::Down ) )
2355 int keyCode = keyEvent.keyCode;
2356 const std::string& keyString = keyEvent.keyPressed;
2357 const std::string keyName = keyEvent.keyPressedName;
2359 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2361 // Pre-process to separate modifying events from non-modifying input events.
2364 // In some platforms arrive key events with no key code.
2368 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2373 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2374 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2375 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2376 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2378 // If don't have any text, do nothing.
2379 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2384 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2385 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2386 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2387 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2389 // Logic to determine whether this text control will lose focus or not.
2390 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2391 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2392 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2393 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2394 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2395 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2400 mImpl->mEventData->mCheckScrollAmount = true;
2401 Event event( Event::CURSOR_KEY_EVENT );
2402 event.p1.mInt = keyCode;
2403 event.p2.mBool = keyEvent.IsShiftModifier();
2404 mImpl->mEventData->mEventQueue.push_back( event );
2406 // Will request for relayout.
2407 relayoutNeeded = true;
2409 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2411 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2412 // If not handle it here, any selected text will be deleted
2417 else if ( keyEvent.IsCtrlModifier() )
2419 bool consumed = false;
2420 if (keyName == KEY_C_NAME)
2422 // Ctrl-C to copy the selected text
2423 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2426 else if (keyName == KEY_V_NAME)
2428 // Ctrl-V to paste the copied text
2429 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2432 else if (keyName == KEY_X_NAME)
2434 // Ctrl-X to cut the selected text
2435 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2440 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2441 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2443 textChanged = DeleteEvent( keyCode );
2445 // Will request for relayout.
2446 relayoutNeeded = true;
2448 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2449 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2450 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2452 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2453 mImpl->ChangeState( EventData::INACTIVE );
2455 // Will request for relayout.
2456 relayoutNeeded = true;
2458 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2460 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2462 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2463 // and a character is typed after the type of a upper case latin character.
2468 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2470 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2476 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2478 // IMF manager is no longer handling key-events
2479 mImpl->ClearPreEditFlag();
2481 InsertText( keyString, COMMIT );
2484 // Will request for relayout.
2485 relayoutNeeded = true;
2488 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2489 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2491 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2492 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2493 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2495 // Should not change the state if the key is the shift send by the imf manager.
2496 // Otherwise, when the state is SELECTING the text controller can't send the right
2497 // surrounding info to the imf.
2498 mImpl->ChangeState( EventData::EDITING );
2500 // Will request for relayout.
2501 relayoutNeeded = true;
2504 if( relayoutNeeded )
2506 mImpl->RequestRelayout();
2511 ( NULL != mImpl->mEditableControlInterface ) )
2513 // Do this last since it provides callbacks into application code
2514 mImpl->mEditableControlInterface->TextChanged();
2520 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2522 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2524 if( NULL != mImpl->mEventData )
2526 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2527 EventData::State state( mImpl->mEventData->mState );
2528 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2530 if( mImpl->IsClipboardVisible() )
2532 if( EventData::INACTIVE == state || EventData::EDITING == state)
2534 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2536 relayoutNeeded = true;
2538 else if( 1u == tapCount )
2540 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2542 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2545 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2547 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2548 relayoutNeeded = true;
2552 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2554 // Hide placeholder text
2558 if( EventData::INACTIVE == state )
2560 mImpl->ChangeState( EventData::EDITING );
2562 else if( !mImpl->IsClipboardEmpty() )
2564 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2566 relayoutNeeded = true;
2569 else if( 2u == tapCount )
2571 if( mImpl->mEventData->mSelectionEnabled &&
2572 mImpl->IsShowingRealText() )
2574 relayoutNeeded = true;
2575 mImpl->mEventData->mIsLeftHandleSelected = true;
2576 mImpl->mEventData->mIsRightHandleSelected = true;
2580 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2581 if( relayoutNeeded )
2583 Event event( Event::TAP_EVENT );
2584 event.p1.mUint = tapCount;
2585 event.p2.mFloat = x;
2586 event.p3.mFloat = y;
2587 mImpl->mEventData->mEventQueue.push_back( event );
2589 mImpl->RequestRelayout();
2593 // Reset keyboard as tap event has occurred.
2594 mImpl->ResetImfManager();
2597 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2599 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2601 if( NULL != mImpl->mEventData )
2603 Event event( Event::PAN_EVENT );
2604 event.p1.mInt = state;
2605 event.p2.mFloat = displacement.x;
2606 event.p3.mFloat = displacement.y;
2607 mImpl->mEventData->mEventQueue.push_back( event );
2609 mImpl->RequestRelayout();
2613 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2615 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2617 if( ( state == Gesture::Started ) &&
2618 ( NULL != mImpl->mEventData ) )
2620 // The 1st long-press on inactive text-field is treated as tap
2621 if( EventData::INACTIVE == mImpl->mEventData->mState )
2623 mImpl->ChangeState( EventData::EDITING );
2625 Event event( Event::TAP_EVENT );
2627 event.p2.mFloat = x;
2628 event.p3.mFloat = y;
2629 mImpl->mEventData->mEventQueue.push_back( event );
2631 mImpl->RequestRelayout();
2633 else if( !mImpl->IsShowingRealText() )
2635 Event event( Event::LONG_PRESS_EVENT );
2636 event.p1.mInt = state;
2637 event.p2.mFloat = x;
2638 event.p3.mFloat = y;
2639 mImpl->mEventData->mEventQueue.push_back( event );
2640 mImpl->RequestRelayout();
2642 else if( !mImpl->IsClipboardVisible() )
2644 // Reset the imf manager to commit the pre-edit before selecting the text.
2645 mImpl->ResetImfManager();
2647 Event event( Event::LONG_PRESS_EVENT );
2648 event.p1.mInt = state;
2649 event.p2.mFloat = x;
2650 event.p3.mFloat = y;
2651 mImpl->mEventData->mEventQueue.push_back( event );
2652 mImpl->RequestRelayout();
2654 mImpl->mEventData->mIsLeftHandleSelected = true;
2655 mImpl->mEventData->mIsRightHandleSelected = true;
2660 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2662 // Whether the text needs to be relaid-out.
2663 bool requestRelayout = false;
2665 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2666 bool retrieveText = false;
2667 bool retrieveCursor = false;
2669 switch( imfEvent.eventName )
2671 case ImfManager::COMMIT:
2673 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2674 requestRelayout = true;
2675 retrieveCursor = true;
2678 case ImfManager::PREEDIT:
2680 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2681 requestRelayout = true;
2682 retrieveCursor = true;
2685 case ImfManager::DELETESURROUNDING:
2687 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2688 imfEvent.numberOfChars,
2689 DONT_UPDATE_INPUT_STYLE );
2693 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2694 !mImpl->IsPlaceholderAvailable() )
2696 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2700 ShowPlaceholderText();
2702 mImpl->mEventData->mUpdateCursorPosition = true;
2703 mImpl->mEventData->mScrollAfterDelete = true;
2705 requestRelayout = true;
2709 case ImfManager::GETSURROUNDING:
2711 retrieveText = true;
2712 retrieveCursor = true;
2715 case ImfManager::PRIVATECOMMAND:
2717 // PRIVATECOMMAND event is just for getting the private command message
2718 retrieveText = true;
2719 retrieveCursor = true;
2722 case ImfManager::VOID:
2729 if( requestRelayout )
2731 mImpl->mOperationsPending = ALL_OPERATIONS;
2732 mImpl->RequestRelayout();
2736 CharacterIndex cursorPosition = 0u;
2737 Length numberOfWhiteSpaces = 0u;
2739 if( retrieveCursor )
2741 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2743 cursorPosition = mImpl->GetLogicalCursorPosition();
2745 if( cursorPosition < numberOfWhiteSpaces )
2747 cursorPosition = 0u;
2751 cursorPosition -= numberOfWhiteSpaces;
2757 if( !mImpl->IsShowingPlaceholderText() )
2759 // Retrieves the normal text string.
2760 mImpl->GetText( numberOfWhiteSpaces, text );
2764 // When the current text is Placeholder Text, the surrounding text should be empty string.
2765 // It means DALi should send empty string ("") to IME.
2770 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2772 if( requestRelayout &&
2773 ( NULL != mImpl->mEditableControlInterface ) )
2775 // Do this last since it provides callbacks into application code
2776 mImpl->mEditableControlInterface->TextChanged();
2779 return callbackData;
2782 void Controller::PasteClipboardItemEvent()
2784 // Retrieve the clipboard contents first
2785 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2786 std::string stringToPaste( notifier.GetContent() );
2788 // Commit the current pre-edit text; the contents of the clipboard should be appended
2789 mImpl->ResetImfManager();
2791 // Temporary disable hiding clipboard
2792 mImpl->SetClipboardHideEnable( false );
2795 PasteText( stringToPaste );
2797 mImpl->SetClipboardHideEnable( true );
2800 // protected : Inherit from Text::Decorator::ControllerInterface.
2802 void Controller::GetTargetSize( Vector2& targetSize )
2804 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2807 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2809 if( NULL != mImpl->mEditableControlInterface )
2811 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2815 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2817 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2819 if( NULL != mImpl->mEventData )
2821 switch( handleType )
2825 Event event( Event::GRAB_HANDLE_EVENT );
2826 event.p1.mUint = state;
2827 event.p2.mFloat = x;
2828 event.p3.mFloat = y;
2830 mImpl->mEventData->mEventQueue.push_back( event );
2833 case LEFT_SELECTION_HANDLE:
2835 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2836 event.p1.mUint = state;
2837 event.p2.mFloat = x;
2838 event.p3.mFloat = y;
2840 mImpl->mEventData->mEventQueue.push_back( event );
2843 case RIGHT_SELECTION_HANDLE:
2845 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2846 event.p1.mUint = state;
2847 event.p2.mFloat = x;
2848 event.p3.mFloat = y;
2850 mImpl->mEventData->mEventQueue.push_back( event );
2853 case LEFT_SELECTION_HANDLE_MARKER:
2854 case RIGHT_SELECTION_HANDLE_MARKER:
2856 // Markers do not move the handles.
2859 case HANDLE_TYPE_COUNT:
2861 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2865 mImpl->RequestRelayout();
2869 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2871 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2873 if( NULL == mImpl->mEventData )
2880 case Toolkit::TextSelectionPopup::CUT:
2882 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2883 mImpl->mOperationsPending = ALL_OPERATIONS;
2885 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2886 !mImpl->IsPlaceholderAvailable() )
2888 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2892 ShowPlaceholderText();
2895 mImpl->mEventData->mUpdateCursorPosition = true;
2896 mImpl->mEventData->mScrollAfterDelete = true;
2898 mImpl->RequestRelayout();
2900 if( NULL != mImpl->mEditableControlInterface )
2902 mImpl->mEditableControlInterface->TextChanged();
2906 case Toolkit::TextSelectionPopup::COPY:
2908 mImpl->SendSelectionToClipboard( false ); // Text not modified
2910 mImpl->mEventData->mUpdateCursorPosition = true;
2912 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2915 case Toolkit::TextSelectionPopup::PASTE:
2917 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2920 case Toolkit::TextSelectionPopup::SELECT:
2922 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2924 if( mImpl->mEventData->mSelectionEnabled )
2926 // Creates a SELECT event.
2927 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2931 case Toolkit::TextSelectionPopup::SELECT_ALL:
2933 // Creates a SELECT_ALL event
2934 SelectEvent( 0.f, 0.f, true );
2937 case Toolkit::TextSelectionPopup::CLIPBOARD:
2939 mImpl->ShowClipboard();
2942 case Toolkit::TextSelectionPopup::NONE:
2950 void Controller::DisplayTimeExpired()
2952 mImpl->mEventData->mUpdateCursorPosition = true;
2953 // Apply modifications to the model
2954 mImpl->mOperationsPending = ALL_OPERATIONS;
2956 mImpl->RequestRelayout();
2959 // private : Update.
2961 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2963 bool removedPrevious = false;
2964 bool removedSelected = false;
2965 bool maxLengthReached = false;
2967 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2969 if( NULL == mImpl->mEventData )
2974 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2975 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2976 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2978 // TODO: At the moment the underline runs are only for pre-edit.
2979 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2981 // Remove the previous IMF pre-edit.
2982 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2984 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2985 mImpl->mEventData->mPreEditLength,
2986 DONT_UPDATE_INPUT_STYLE );
2988 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2989 mImpl->mEventData->mPreEditLength = 0u;
2993 // Remove the previous Selection.
2994 removedSelected = RemoveSelectedText();
2998 Vector<Character> utf32Characters;
2999 Length characterCount = 0u;
3003 // Convert text into UTF-32
3004 utf32Characters.Resize( text.size() );
3006 // This is a bit horrible but std::string returns a (signed) char*
3007 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3009 // Transform a text array encoded in utf8 into an array encoded in utf32.
3010 // It returns the actual number of characters.
3011 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3012 utf32Characters.Resize( characterCount );
3014 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3015 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3018 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3020 // The placeholder text is no longer needed
3021 if( mImpl->IsShowingPlaceholderText() )
3026 mImpl->ChangeState( EventData::EDITING );
3028 // Handle the IMF (predicitive text) state changes
3029 if( COMMIT == type )
3031 // IMF manager is no longer handling key-events
3032 mImpl->ClearPreEditFlag();
3036 if( !mImpl->mEventData->mPreEditFlag )
3038 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3040 // Record the start of the pre-edit text
3041 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3044 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3045 mImpl->mEventData->mPreEditFlag = true;
3047 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3050 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3052 // Restrict new text to fit within Maximum characters setting.
3053 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3054 maxLengthReached = ( characterCount > maxSizeOfNewText );
3056 // The cursor position.
3057 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3059 // Update the text's style.
3061 // Updates the text style runs by adding characters.
3062 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3064 // Get the character index from the cursor index.
3065 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3067 // Retrieve the text's style for the given index.
3069 mImpl->RetrieveDefaultInputStyle( style );
3070 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3072 // Whether to add a new text color run.
3073 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3075 // Whether to add a new font run.
3076 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3077 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3078 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3079 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3080 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3085 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3086 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3088 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3089 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3090 colorRun.characterRun.characterIndex = cursorIndex;
3091 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3094 if( addFontNameRun ||
3100 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3101 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3103 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3105 if( addFontNameRun )
3107 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3108 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3109 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3110 fontDescriptionRun.familyDefined = true;
3112 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3115 if( addFontWeightRun )
3117 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3118 fontDescriptionRun.weightDefined = true;
3121 if( addFontWidthRun )
3123 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3124 fontDescriptionRun.widthDefined = true;
3127 if( addFontSlantRun )
3129 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3130 fontDescriptionRun.slantDefined = true;
3133 if( addFontSizeRun )
3135 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3136 fontDescriptionRun.sizeDefined = true;
3139 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3140 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3143 // Insert at current cursor position.
3144 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3146 if( cursorIndex < numberOfCharactersInModel )
3148 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3152 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3155 // Mark the first paragraph to be updated.
3156 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3158 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3159 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3160 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3161 mImpl->mTextUpdateInfo.mClearAll = true;
3165 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3166 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3169 // Update the cursor index.
3170 cursorIndex += maxSizeOfNewText;
3172 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 );
3175 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3176 mImpl->IsPlaceholderAvailable() )
3178 // Show place-holder if empty after removing the pre-edit text
3179 ShowPlaceholderText();
3180 mImpl->mEventData->mUpdateCursorPosition = true;
3181 mImpl->ClearPreEditFlag();
3183 else if( removedPrevious ||
3185 ( 0 != utf32Characters.Count() ) )
3187 // Queue an inserted event
3188 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3190 mImpl->mEventData->mUpdateCursorPosition = true;
3191 if( removedSelected )
3193 mImpl->mEventData->mScrollAfterDelete = true;
3197 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3201 if( maxLengthReached )
3203 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3205 mImpl->ResetImfManager();
3207 if( NULL != mImpl->mEditableControlInterface )
3209 // Do this last since it provides callbacks into application code
3210 mImpl->mEditableControlInterface->MaxLengthReached();
3215 void Controller::PasteText( const std::string& stringToPaste )
3217 InsertText( stringToPaste, Text::Controller::COMMIT );
3218 mImpl->ChangeState( EventData::EDITING );
3219 mImpl->RequestRelayout();
3221 if( NULL != mImpl->mEditableControlInterface )
3223 // Do this last since it provides callbacks into application code
3224 mImpl->mEditableControlInterface->TextChanged();
3228 bool Controller::RemoveText( int cursorOffset,
3229 int numberOfCharacters,
3230 UpdateInputStyleType type )
3232 bool removed = false;
3234 if( NULL == mImpl->mEventData )
3239 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3240 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3242 if( !mImpl->IsShowingPlaceholderText() )
3244 // Delete at current cursor position
3245 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3246 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3248 CharacterIndex cursorIndex = 0;
3250 // Validate the cursor position & number of characters
3251 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3253 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3256 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3258 numberOfCharacters = currentText.Count() - cursorIndex;
3261 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.
3262 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3264 // Mark the paragraphs to be updated.
3265 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3267 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3268 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3269 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3270 mImpl->mTextUpdateInfo.mClearAll = true;
3274 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3275 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3278 // Update the input style and remove the text's style before removing the text.
3280 if( UPDATE_INPUT_STYLE == type )
3282 // Keep a copy of the current input style.
3283 InputStyle currentInputStyle;
3284 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3286 // Set first the default input style.
3287 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3289 // Update the input style.
3290 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3292 // Compare if the input style has changed.
3293 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3295 if( hasInputStyleChanged )
3297 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3298 // Queue the input style changed signal.
3299 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3303 // Updates the text style runs by removing characters. Runs with no characters are removed.
3304 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3306 // Remove the characters.
3307 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3308 Vector<Character>::Iterator last = first + numberOfCharacters;
3310 currentText.Erase( first, last );
3312 // Cursor position retreat
3313 oldCursorIndex = cursorIndex;
3315 mImpl->mEventData->mScrollAfterDelete = true;
3317 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3325 bool Controller::RemoveSelectedText()
3327 bool textRemoved( false );
3329 if( EventData::SELECTING == mImpl->mEventData->mState )
3331 std::string removedString;
3332 mImpl->RetrieveSelection( removedString, true );
3334 if( !removedString.empty() )
3337 mImpl->ChangeState( EventData::EDITING );
3344 // private : Relayout.
3346 bool Controller::DoRelayout( const Size& size,
3347 OperationsMask operationsRequired,
3350 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3351 bool viewUpdated( false );
3353 // Calculate the operations to be done.
3354 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3356 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3357 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3359 // Get the current layout size.
3360 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3362 if( NO_OPERATION != ( LAYOUT & operations ) )
3364 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3366 // Some vectors with data needed to layout and reorder may be void
3367 // after the first time the text has been laid out.
3368 // Fill the vectors again.
3370 // Calculate the number of glyphs to layout.
3371 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3372 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3373 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3374 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3376 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3377 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3378 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3379 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3381 if( 0u == totalNumberOfGlyphs )
3383 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3385 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3388 // Nothing else to do if there is no glyphs.
3389 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3393 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3394 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3395 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3396 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3397 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3398 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3399 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3400 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3402 // Set the layout parameters.
3403 Layout::Parameters layoutParameters( size,
3405 lineBreakInfo.Begin(),
3406 wordBreakInfo.Begin(),
3407 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3409 glyphsToCharactersMap.Begin(),
3410 charactersPerGlyph.Begin(),
3411 charactersToGlyphBuffer,
3412 glyphsPerCharacterBuffer,
3413 totalNumberOfGlyphs,
3414 mImpl->mModel->mHorizontalAlignment,
3415 mImpl->mModel->mLineWrapMode,
3418 // Resize the vector of positions to have the same size than the vector of glyphs.
3419 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3420 glyphPositions.Resize( totalNumberOfGlyphs );
3422 // Whether the last character is a new paragraph character.
3423 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3424 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3426 // The initial glyph and the number of glyphs to layout.
3427 layoutParameters.startGlyphIndex = startGlyphIndex;
3428 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3429 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3430 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3432 // Update the ellipsis
3433 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3435 if( NULL != mImpl->mEventData )
3437 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3439 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3441 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3443 // Disable ellipsis when editing
3444 elideTextEnabled = false;
3447 // Reset the scroll position in inactive state
3448 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3450 ResetScrollPosition();
3454 // Update the visual model.
3456 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3458 mImpl->mModel->mVisualModel->mLines,
3462 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3466 layoutSize = newLayoutSize;
3468 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3470 mImpl->mAutoScrollDirectionRTL = false;
3473 // Reorder the lines
3474 if( NO_OPERATION != ( REORDER & operations ) )
3476 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3477 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3479 // Check first if there are paragraphs with bidirectional info.
3480 if( 0u != bidirectionalInfo.Count() )
3483 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3485 // Reorder the lines.
3486 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3487 ReorderLines( bidirectionalInfo,
3489 requestedNumberOfCharacters,
3490 mImpl->mModel->mVisualModel->mLines,
3491 bidirectionalLineInfo );
3493 // Set the bidirectional info per line into the layout parameters.
3494 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3495 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3497 // Re-layout the text. Reorder those lines with right to left characters.
3498 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3500 requestedNumberOfCharacters,
3503 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3505 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3508 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3514 // Sets the layout size.
3515 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3517 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3522 if( NO_OPERATION != ( ALIGN & operations ) )
3524 // The laid-out lines.
3525 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3527 // Need to align with the control's size as the text may contain lines
3528 // starting either with left to right text or right to left.
3529 mImpl->mLayoutEngine.Align( size,
3531 requestedNumberOfCharacters,
3532 mImpl->mModel->mHorizontalAlignment,
3534 mImpl->mModel->mAlignmentOffset );
3538 #if defined(DEBUG_ENABLED)
3539 std::string currentText;
3540 GetText( currentText );
3541 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3543 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3547 void Controller::CalculateVerticalOffset( const Size& controlSize )
3549 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3551 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3553 // Get the line height of the default font.
3554 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3557 switch( mImpl->mModel->mVerticalAlignment )
3559 case VerticalAlignment::TOP:
3561 mImpl->mModel->mScrollPosition.y = 0.f;
3564 case VerticalAlignment::CENTER:
3566 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3569 case VerticalAlignment::BOTTOM:
3571 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3577 // private : Events.
3579 void Controller::ProcessModifyEvents()
3581 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3583 if( 0u == events.Count() )
3589 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3590 endIt = events.End();
3594 const ModifyEvent& event = *it;
3596 if( ModifyEvent::TEXT_REPLACED == event.type )
3598 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3599 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3601 TextReplacedEvent();
3603 else if( ModifyEvent::TEXT_INSERTED == event.type )
3605 TextInsertedEvent();
3607 else if( ModifyEvent::TEXT_DELETED == event.type )
3609 // Placeholder-text cannot be deleted
3610 if( !mImpl->IsShowingPlaceholderText() )
3617 if( NULL != mImpl->mEventData )
3619 // When the text is being modified, delay cursor blinking
3620 mImpl->mEventData->mDecorator->DelayCursorBlink();
3622 // Update selection position after modifying the text
3623 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3624 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3627 // Discard temporary text
3631 void Controller::TextReplacedEvent()
3633 // The natural size needs to be re-calculated.
3634 mImpl->mRecalculateNaturalSize = true;
3636 // Apply modifications to the model
3637 mImpl->mOperationsPending = ALL_OPERATIONS;
3640 void Controller::TextInsertedEvent()
3642 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3644 if( NULL == mImpl->mEventData )
3649 mImpl->mEventData->mCheckScrollAmount = true;
3651 // The natural size needs to be re-calculated.
3652 mImpl->mRecalculateNaturalSize = true;
3654 // Apply modifications to the model; TODO - Optimize this
3655 mImpl->mOperationsPending = ALL_OPERATIONS;
3658 void Controller::TextDeletedEvent()
3660 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3662 if( NULL == mImpl->mEventData )
3667 mImpl->mEventData->mCheckScrollAmount = true;
3669 // The natural size needs to be re-calculated.
3670 mImpl->mRecalculateNaturalSize = true;
3672 // Apply modifications to the model; TODO - Optimize this
3673 mImpl->mOperationsPending = ALL_OPERATIONS;
3676 void Controller::SelectEvent( float x, float y, bool selectAll )
3678 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3680 if( NULL != mImpl->mEventData )
3684 Event event( Event::SELECT_ALL );
3685 mImpl->mEventData->mEventQueue.push_back( event );
3689 Event event( Event::SELECT );
3690 event.p2.mFloat = x;
3691 event.p3.mFloat = y;
3692 mImpl->mEventData->mEventQueue.push_back( event );
3695 mImpl->mEventData->mCheckScrollAmount = true;
3696 mImpl->mEventData->mIsLeftHandleSelected = true;
3697 mImpl->mEventData->mIsRightHandleSelected = true;
3698 mImpl->RequestRelayout();
3702 bool Controller::DeleteEvent( int keyCode )
3704 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3706 bool removed = false;
3708 if( NULL == mImpl->mEventData )
3713 // IMF manager is no longer handling key-events
3714 mImpl->ClearPreEditFlag();
3716 if( EventData::SELECTING == mImpl->mEventData->mState )
3718 removed = RemoveSelectedText();
3720 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3722 // Remove the character before the current cursor position
3723 removed = RemoveText( -1,
3725 UPDATE_INPUT_STYLE );
3727 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
3729 // Remove the character after the current cursor position
3730 removed = RemoveText( 0,
3732 UPDATE_INPUT_STYLE );
3737 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3738 !mImpl->IsPlaceholderAvailable() )
3740 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3744 ShowPlaceholderText();
3746 mImpl->mEventData->mUpdateCursorPosition = true;
3747 mImpl->mEventData->mScrollAfterDelete = true;
3753 // private : Helpers.
3755 void Controller::ResetText()
3758 mImpl->mModel->mLogicalModel->mText.Clear();
3760 // We have cleared everything including the placeholder-text
3761 mImpl->PlaceholderCleared();
3763 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3764 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3765 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3767 // Clear any previous text.
3768 mImpl->mTextUpdateInfo.mClearAll = true;
3770 // The natural size needs to be re-calculated.
3771 mImpl->mRecalculateNaturalSize = true;
3773 // Apply modifications to the model
3774 mImpl->mOperationsPending = ALL_OPERATIONS;
3777 void Controller::ShowPlaceholderText()
3779 if( mImpl->IsPlaceholderAvailable() )
3781 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3783 if( NULL == mImpl->mEventData )
3788 mImpl->mEventData->mIsShowingPlaceholderText = true;
3790 // Disable handles when showing place-holder text
3791 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3792 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3793 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3795 const char* text( NULL );
3798 // TODO - Switch Placeholder text when changing state
3799 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3800 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3802 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3803 size = mImpl->mEventData->mPlaceholderTextActive.size();
3807 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3808 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3811 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3812 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3814 // Reset model for showing placeholder.
3815 mImpl->mModel->mLogicalModel->mText.Clear();
3816 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3818 // Convert text into UTF-32
3819 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3820 utf32Characters.Resize( size );
3822 // This is a bit horrible but std::string returns a (signed) char*
3823 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3825 // Transform a text array encoded in utf8 into an array encoded in utf32.
3826 // It returns the actual number of characters.
3827 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3828 utf32Characters.Resize( characterCount );
3830 // The characters to be added.
3831 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3833 // Reset the cursor position
3834 mImpl->mEventData->mPrimaryCursorPosition = 0;
3836 // The natural size needs to be re-calculated.
3837 mImpl->mRecalculateNaturalSize = true;
3839 // Apply modifications to the model
3840 mImpl->mOperationsPending = ALL_OPERATIONS;
3842 // Update the rest of the model during size negotiation
3843 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3847 void Controller::ClearFontData()
3849 if( mImpl->mFontDefaults )
3851 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3854 // Set flags to update the model.
3855 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3856 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3857 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3859 mImpl->mTextUpdateInfo.mClearAll = true;
3860 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3861 mImpl->mRecalculateNaturalSize = true;
3863 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3869 UPDATE_LAYOUT_SIZE |
3874 void Controller::ClearStyleData()
3876 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3877 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3880 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3882 // Reset the cursor position
3883 if( NULL != mImpl->mEventData )
3885 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3887 // Update the cursor if it's in editing mode.
3888 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3890 mImpl->mEventData->mUpdateCursorPosition = true;
3895 void Controller::ResetScrollPosition()
3897 if( NULL != mImpl->mEventData )
3899 // Reset the scroll position.
3900 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3901 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3905 void Controller::SetControlInterface( ControlInterface* controlInterface )
3907 mImpl->mControlInterface = controlInterface;
3910 bool Controller::ShouldClearFocusOnEscape() const
3912 return mImpl->mShouldClearFocusOnEscape;
3915 // private : Private contructors & copy operator.
3917 Controller::Controller()
3920 mImpl = new Controller::Impl( NULL, NULL );
3923 Controller::Controller( ControlInterface* controlInterface )
3925 mImpl = new Controller::Impl( controlInterface, NULL );
3928 Controller::Controller( ControlInterface* controlInterface,
3929 EditableControlInterface* editableControlInterface )
3931 mImpl = new Controller::Impl( controlInterface,
3932 editableControlInterface );
3935 // The copy constructor and operator are left unimplemented.
3937 // protected : Destructor.
3939 Controller::~Controller()
3946 } // namespace Toolkit