2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
28 #include <dali/devel-api/adaptor-framework/key-devel.h>
31 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
32 #include <dali-toolkit/internal/text/bidirectional-support.h>
33 #include <dali-toolkit/internal/text/character-set-conversion.h>
34 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
35 #include <dali-toolkit/internal/text/markup-processor.h>
36 #include <dali-toolkit/internal/text/multi-language-support.h>
37 #include <dali-toolkit/internal/text/text-controller-impl.h>
38 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
39 #include <dali-toolkit/internal/text/text-font-style.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
48 const float MAX_FLOAT = std::numeric_limits<float>::max();
50 const std::string EMPTY_STRING("");
52 const std::string KEY_C_NAME = "c";
53 const std::string KEY_V_NAME = "v";
54 const std::string KEY_X_NAME = "x";
56 const char * const PLACEHOLDER_TEXT = "text";
57 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
58 const char * const PLACEHOLDER_COLOR = "color";
59 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
60 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
61 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
62 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
63 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 float ConvertToEven( float value )
67 int intValue(static_cast<int>( value ));
68 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
83 * @brief Adds a new font description run for the selected text.
85 * The new font parameters are added after the call to this method.
87 * @param[in] eventData The event data pointer.
88 * @param[in] logicalModel The logical model where to add the new font description run.
89 * @param[out] startOfSelectedText Index to the first selected character.
90 * @param[out] lengthOfSelectedText Number of selected characters.
92 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
93 LogicalModelPtr logicalModel,
94 CharacterIndex& startOfSelectedText,
95 Length& lengthOfSelectedText )
97 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
99 // Get start and end position of selection
100 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
101 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
104 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
105 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
107 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
109 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
110 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
112 // Recalculate the selection highlight as the metrics may have changed.
113 eventData->mUpdateLeftSelectionPosition = true;
114 eventData->mUpdateRightSelectionPosition = true;
115 eventData->mUpdateHighlightBox = true;
117 return fontDescriptionRun;
120 // public : Constructor.
122 ControllerPtr Controller::New()
124 return ControllerPtr( new Controller() );
127 ControllerPtr Controller::New( ControlInterface* controlInterface )
129 return ControllerPtr( new Controller( controlInterface ) );
132 ControllerPtr Controller::New( ControlInterface* controlInterface,
133 EditableControlInterface* editableControlInterface )
135 return ControllerPtr( new Controller( controlInterface,
136 editableControlInterface ) );
139 // public : Configure the text controller.
141 void Controller::EnableTextInput( DecoratorPtr decorator )
145 delete mImpl->mEventData;
146 mImpl->mEventData = NULL;
148 // Nothing else to do.
152 if( NULL == mImpl->mEventData )
154 mImpl->mEventData = new EventData( decorator );
158 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
160 // Metrics for bitmap & vector based glyphs are different
161 mImpl->mMetrics->SetGlyphType( glyphType );
163 // Clear the font-specific data
166 mImpl->RequestRelayout();
169 void Controller::SetMarkupProcessorEnabled( bool enable )
171 mImpl->mMarkupProcessorEnabled = enable;
174 bool Controller::IsMarkupProcessorEnabled() const
176 return mImpl->mMarkupProcessorEnabled;
179 void Controller::SetAutoScrollEnabled( bool enable )
181 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
183 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
187 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
188 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
198 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
199 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
206 mImpl->mIsAutoScrollEnabled = enable;
207 mImpl->RequestRelayout();
211 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
212 mImpl->mIsAutoScrollEnabled = false;
216 bool Controller::IsAutoScrollEnabled() const
218 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
220 return mImpl->mIsAutoScrollEnabled;
223 CharacterDirection Controller::GetAutoScrollDirection() const
225 return mImpl->mIsTextDirectionRTL;
228 float Controller::GetAutoScrollLineAlignment() const
232 if( mImpl->mModel->mVisualModel &&
233 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
235 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
241 void Controller::SetHorizontalScrollEnabled( bool enable )
243 if( ( NULL != mImpl->mEventData ) &&
244 mImpl->mEventData->mDecorator )
246 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
249 bool Controller::IsHorizontalScrollEnabled() const
251 if( ( NULL != mImpl->mEventData ) &&
252 mImpl->mEventData->mDecorator )
254 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
260 void Controller::SetVerticalScrollEnabled( bool enable )
262 if( ( NULL != mImpl->mEventData ) &&
263 mImpl->mEventData->mDecorator )
265 if( mImpl->mEventData->mDecorator )
267 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
272 bool Controller::IsVerticalScrollEnabled() const
274 if( ( NULL != mImpl->mEventData ) &&
275 mImpl->mEventData->mDecorator )
277 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
283 void Controller::SetSmoothHandlePanEnabled( bool enable )
285 if( ( NULL != mImpl->mEventData ) &&
286 mImpl->mEventData->mDecorator )
288 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
292 bool Controller::IsSmoothHandlePanEnabled() const
294 if( ( NULL != mImpl->mEventData ) &&
295 mImpl->mEventData->mDecorator )
297 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
303 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
305 mImpl->mMaximumNumberOfCharacters = maxCharacters;
308 int Controller::GetMaximumNumberOfCharacters()
310 return mImpl->mMaximumNumberOfCharacters;
313 void Controller::SetEnableCursorBlink( bool enable )
315 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
317 if( NULL != mImpl->mEventData )
319 mImpl->mEventData->mCursorBlinkEnabled = enable;
322 mImpl->mEventData->mDecorator )
324 mImpl->mEventData->mDecorator->StopCursorBlink();
329 bool Controller::GetEnableCursorBlink() const
331 if( NULL != mImpl->mEventData )
333 return mImpl->mEventData->mCursorBlinkEnabled;
339 void Controller::SetMultiLineEnabled( bool enable )
341 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
343 if( layout != mImpl->mLayoutEngine.GetLayout() )
345 // Set the layout type.
346 mImpl->mLayoutEngine.SetLayout( layout );
348 // Set the flags to redo the layout operations
349 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
354 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
355 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
357 mImpl->RequestRelayout();
361 bool Controller::IsMultiLineEnabled() const
363 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
366 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
368 if( alignment != mImpl->mModel->mHorizontalAlignment )
370 // Set the alignment.
371 mImpl->mModel->mHorizontalAlignment = alignment;
373 // Set the flag to redo the alignment operation.
374 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
376 mImpl->RequestRelayout();
380 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
382 return mImpl->mModel->mHorizontalAlignment;
385 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
387 if( alignment != mImpl->mModel->mVerticalAlignment )
389 // Set the alignment.
390 mImpl->mModel->mVerticalAlignment = alignment;
392 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
394 mImpl->RequestRelayout();
398 VerticalAlignment::Type Controller::GetVerticalAlignment() const
400 return mImpl->mModel->mVerticalAlignment;
403 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
405 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
407 // Set the text wrap mode.
408 mImpl->mModel->mLineWrapMode = lineWrapMode;
411 // Update Text layout for applying wrap mode
412 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
417 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
418 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
419 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
422 mImpl->RequestRelayout();
426 Text::LineWrap::Mode Controller::GetLineWrapMode() const
428 return mImpl->mModel->mLineWrapMode;
431 void Controller::SetTextElideEnabled( bool enabled )
433 mImpl->mModel->mElideEnabled = enabled;
436 bool Controller::IsTextElideEnabled() const
438 return mImpl->mModel->mElideEnabled;
441 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
443 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
444 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
446 // Update placeholder if there is no text
447 if( mImpl->IsShowingPlaceholderText() ||
448 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
450 ShowPlaceholderText();
454 bool Controller::IsPlaceholderTextElideEnabled() const
456 return mImpl->mEventData->mIsPlaceholderElideEnabled;
459 void Controller::SetSelectionEnabled( bool enabled )
461 mImpl->mEventData->mSelectionEnabled = enabled;
464 bool Controller::IsSelectionEnabled() const
466 return mImpl->mEventData->mSelectionEnabled;
469 void Controller::SetShiftSelectionEnabled( bool enabled )
471 mImpl->mEventData->mShiftSelectionFlag = enabled;
474 bool Controller::IsShiftSelectionEnabled() const
476 return mImpl->mEventData->mShiftSelectionFlag;
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 // The text direction needs to be updated.
558 mImpl->mUpdateTextDirection = true;
560 // Apply modifications to the model
561 mImpl->mOperationsPending = ALL_OPERATIONS;
565 ShowPlaceholderText();
568 // Resets the cursor position.
569 ResetCursorPosition( lastCursorIndex );
571 // Scrolls the text to make the cursor visible.
572 ResetScrollPosition();
574 mImpl->RequestRelayout();
576 if( NULL != mImpl->mEventData )
578 // Cancel previously queued events
579 mImpl->mEventData->mEventQueue.clear();
582 // Do this last since it provides callbacks into application code.
583 if( NULL != mImpl->mEditableControlInterface )
585 mImpl->mEditableControlInterface->TextChanged();
589 void Controller::GetText( std::string& text ) const
591 if( !mImpl->IsShowingPlaceholderText() )
593 // Retrieves the text string.
594 mImpl->GetText( 0u, text );
598 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
602 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
604 if( NULL != mImpl->mEventData )
606 if( PLACEHOLDER_TYPE_INACTIVE == type )
608 mImpl->mEventData->mPlaceholderTextInactive = text;
612 mImpl->mEventData->mPlaceholderTextActive = text;
615 // Update placeholder if there is no text
616 if( mImpl->IsShowingPlaceholderText() ||
617 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
619 ShowPlaceholderText();
624 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
626 if( NULL != mImpl->mEventData )
628 if( PLACEHOLDER_TYPE_INACTIVE == type )
630 text = mImpl->mEventData->mPlaceholderTextInactive;
634 text = mImpl->mEventData->mPlaceholderTextActive;
639 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
641 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
643 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
645 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
646 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
650 mImpl->RequestRelayout();
654 // public : Default style & Input style
656 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
658 if( NULL == mImpl->mFontDefaults )
660 mImpl->mFontDefaults = new FontDefaults();
663 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
664 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
665 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
667 // Clear the font-specific data
670 mImpl->RequestRelayout();
673 const std::string& Controller::GetDefaultFontFamily() const
675 if( NULL != mImpl->mFontDefaults )
677 return mImpl->mFontDefaults->mFontDescription.family;
683 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
685 if( NULL != mImpl->mEventData )
687 if( NULL == mImpl->mEventData->mPlaceholderFont )
689 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
692 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
693 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
694 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
696 mImpl->RequestRelayout();
700 const std::string& Controller::GetPlaceholderFontFamily() const
702 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
704 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
710 void Controller::SetDefaultFontWeight( FontWeight weight )
712 if( NULL == mImpl->mFontDefaults )
714 mImpl->mFontDefaults = new FontDefaults();
717 mImpl->mFontDefaults->mFontDescription.weight = weight;
718 mImpl->mFontDefaults->weightDefined = true;
720 // Clear the font-specific data
723 mImpl->RequestRelayout();
726 bool Controller::IsDefaultFontWeightDefined() const
728 if( NULL != mImpl->mFontDefaults )
730 return mImpl->mFontDefaults->weightDefined;
736 FontWeight Controller::GetDefaultFontWeight() const
738 if( NULL != mImpl->mFontDefaults )
740 return mImpl->mFontDefaults->mFontDescription.weight;
743 return TextAbstraction::FontWeight::NORMAL;
746 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
748 if( NULL != mImpl->mEventData )
750 if( NULL == mImpl->mEventData->mPlaceholderFont )
752 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
755 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
756 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
758 mImpl->RequestRelayout();
762 bool Controller::IsPlaceholderTextFontWeightDefined() const
764 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
766 return mImpl->mEventData->mPlaceholderFont->weightDefined;
771 FontWeight Controller::GetPlaceholderTextFontWeight() const
773 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
775 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
778 return TextAbstraction::FontWeight::NORMAL;
781 void Controller::SetDefaultFontWidth( FontWidth width )
783 if( NULL == mImpl->mFontDefaults )
785 mImpl->mFontDefaults = new FontDefaults();
788 mImpl->mFontDefaults->mFontDescription.width = width;
789 mImpl->mFontDefaults->widthDefined = true;
791 // Clear the font-specific data
794 mImpl->RequestRelayout();
797 bool Controller::IsDefaultFontWidthDefined() const
799 if( NULL != mImpl->mFontDefaults )
801 return mImpl->mFontDefaults->widthDefined;
807 FontWidth Controller::GetDefaultFontWidth() const
809 if( NULL != mImpl->mFontDefaults )
811 return mImpl->mFontDefaults->mFontDescription.width;
814 return TextAbstraction::FontWidth::NORMAL;
817 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
819 if( NULL != mImpl->mEventData )
821 if( NULL == mImpl->mEventData->mPlaceholderFont )
823 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
826 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
827 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
829 mImpl->RequestRelayout();
833 bool Controller::IsPlaceholderTextFontWidthDefined() const
835 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
837 return mImpl->mEventData->mPlaceholderFont->widthDefined;
842 FontWidth Controller::GetPlaceholderTextFontWidth() const
844 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
846 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
849 return TextAbstraction::FontWidth::NORMAL;
852 void Controller::SetDefaultFontSlant( FontSlant slant )
854 if( NULL == mImpl->mFontDefaults )
856 mImpl->mFontDefaults = new FontDefaults();
859 mImpl->mFontDefaults->mFontDescription.slant = slant;
860 mImpl->mFontDefaults->slantDefined = true;
862 // Clear the font-specific data
865 mImpl->RequestRelayout();
868 bool Controller::IsDefaultFontSlantDefined() const
870 if( NULL != mImpl->mFontDefaults )
872 return mImpl->mFontDefaults->slantDefined;
877 FontSlant Controller::GetDefaultFontSlant() const
879 if( NULL != mImpl->mFontDefaults )
881 return mImpl->mFontDefaults->mFontDescription.slant;
884 return TextAbstraction::FontSlant::NORMAL;
887 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
889 if( NULL != mImpl->mEventData )
891 if( NULL == mImpl->mEventData->mPlaceholderFont )
893 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
896 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
897 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
899 mImpl->RequestRelayout();
903 bool Controller::IsPlaceholderTextFontSlantDefined() const
905 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
907 return mImpl->mEventData->mPlaceholderFont->slantDefined;
912 FontSlant Controller::GetPlaceholderTextFontSlant() const
914 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
916 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
919 return TextAbstraction::FontSlant::NORMAL;
922 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
924 if( NULL == mImpl->mFontDefaults )
926 mImpl->mFontDefaults = new FontDefaults();
933 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
934 mImpl->mFontDefaults->sizeDefined = true;
939 // Point size = Pixel size * 72.f / DPI
940 unsigned int horizontalDpi = 0u;
941 unsigned int verticalDpi = 0u;
942 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
943 fontClient.GetDpi( horizontalDpi, verticalDpi );
945 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
946 mImpl->mFontDefaults->sizeDefined = true;
951 // Clear the font-specific data
954 mImpl->RequestRelayout();
957 float Controller::GetDefaultFontSize( FontSizeType type ) const
960 if( NULL != mImpl->mFontDefaults )
966 value = mImpl->mFontDefaults->mDefaultPointSize;
971 // Pixel size = Point size * DPI / 72.f
972 unsigned int horizontalDpi = 0u;
973 unsigned int verticalDpi = 0u;
974 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
975 fontClient.GetDpi( horizontalDpi, verticalDpi );
977 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
987 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
989 if( NULL != mImpl->mEventData )
991 if( NULL == mImpl->mEventData->mPlaceholderFont )
993 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1000 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1001 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1002 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1007 // Point size = Pixel size * 72.f / DPI
1008 unsigned int horizontalDpi = 0u;
1009 unsigned int verticalDpi = 0u;
1010 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1011 fontClient.GetDpi( horizontalDpi, verticalDpi );
1013 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1014 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1015 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1020 mImpl->RequestRelayout();
1024 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1027 if( NULL != mImpl->mEventData )
1033 if( NULL != mImpl->mEventData->mPlaceholderFont )
1035 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1039 // If the placeholder text font size is not set, then return the default font size.
1040 value = GetDefaultFontSize( POINT_SIZE );
1046 if( NULL != mImpl->mEventData->mPlaceholderFont )
1048 // Pixel size = Point size * DPI / 72.f
1049 unsigned int horizontalDpi = 0u;
1050 unsigned int verticalDpi = 0u;
1051 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1052 fontClient.GetDpi( horizontalDpi, verticalDpi );
1054 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1058 // If the placeholder text font size is not set, then return the default font size.
1059 value = GetDefaultFontSize( PIXEL_SIZE );
1070 void Controller::SetDefaultColor( const Vector4& color )
1072 mImpl->mTextColor = color;
1074 if( !mImpl->IsShowingPlaceholderText() )
1076 mImpl->mModel->mVisualModel->SetTextColor( color );
1078 mImpl->RequestRelayout();
1082 const Vector4& Controller::GetDefaultColor() const
1084 return mImpl->mTextColor;
1087 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1089 if( NULL != mImpl->mEventData )
1091 mImpl->mEventData->mPlaceholderTextColor = textColor;
1094 if( mImpl->IsShowingPlaceholderText() )
1096 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1097 mImpl->RequestRelayout();
1101 const Vector4& Controller::GetPlaceholderTextColor() const
1103 if( NULL != mImpl->mEventData )
1105 return mImpl->mEventData->mPlaceholderTextColor;
1108 return Color::BLACK;
1111 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1113 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1115 mImpl->RequestRelayout();
1118 const Vector2& Controller::GetShadowOffset() const
1120 return mImpl->mModel->mVisualModel->GetShadowOffset();
1123 void Controller::SetShadowColor( const Vector4& shadowColor )
1125 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1127 mImpl->RequestRelayout();
1130 const Vector4& Controller::GetShadowColor() const
1132 return mImpl->mModel->mVisualModel->GetShadowColor();
1135 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1137 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1139 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1141 mImpl->RequestRelayout();
1145 const float& Controller::GetShadowBlurRadius() const
1147 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1150 void Controller::SetUnderlineColor( const Vector4& color )
1152 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1154 mImpl->RequestRelayout();
1157 const Vector4& Controller::GetUnderlineColor() const
1159 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1162 void Controller::SetUnderlineEnabled( bool enabled )
1164 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1166 mImpl->RequestRelayout();
1169 bool Controller::IsUnderlineEnabled() const
1171 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1174 void Controller::SetUnderlineHeight( float height )
1176 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1178 mImpl->RequestRelayout();
1181 float Controller::GetUnderlineHeight() const
1183 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1186 void Controller::SetOutlineColor( const Vector4& color )
1188 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1190 mImpl->RequestRelayout();
1193 const Vector4& Controller::GetOutlineColor() const
1195 return mImpl->mModel->mVisualModel->GetOutlineColor();
1198 void Controller::SetOutlineWidth( unsigned int width )
1200 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1202 mImpl->RequestRelayout();
1205 unsigned int Controller::GetOutlineWidth() const
1207 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1210 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1212 if( NULL == mImpl->mEmbossDefaults )
1214 mImpl->mEmbossDefaults = new EmbossDefaults();
1217 mImpl->mEmbossDefaults->properties = embossProperties;
1220 const std::string& Controller::GetDefaultEmbossProperties() const
1222 if( NULL != mImpl->mEmbossDefaults )
1224 return mImpl->mEmbossDefaults->properties;
1227 return EMPTY_STRING;
1230 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1232 if( NULL == mImpl->mOutlineDefaults )
1234 mImpl->mOutlineDefaults = new OutlineDefaults();
1237 mImpl->mOutlineDefaults->properties = outlineProperties;
1240 const std::string& Controller::GetDefaultOutlineProperties() const
1242 if( NULL != mImpl->mOutlineDefaults )
1244 return mImpl->mOutlineDefaults->properties;
1247 return EMPTY_STRING;
1250 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1252 if( std::abs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000 )
1254 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1255 mImpl->mRecalculateNaturalSize = true;
1261 float Controller::GetDefaultLineSpacing() const
1263 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1266 void Controller::SetInputColor( const Vector4& color )
1268 if( NULL != mImpl->mEventData )
1270 mImpl->mEventData->mInputStyle.textColor = color;
1271 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1273 if( EventData::SELECTING == mImpl->mEventData->mState )
1275 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1277 // Get start and end position of selection
1278 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1279 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1281 // Add the color run.
1282 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1283 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1285 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1286 colorRun.color = color;
1287 colorRun.characterRun.characterIndex = startOfSelectedText;
1288 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1290 // Request to relayout.
1291 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1292 mImpl->RequestRelayout();
1294 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1295 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1296 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1301 const Vector4& Controller::GetInputColor() const
1303 if( NULL != mImpl->mEventData )
1305 return mImpl->mEventData->mInputStyle.textColor;
1308 // Return the default text's color if there is no EventData.
1309 return mImpl->mTextColor;
1313 void Controller::SetInputFontFamily( const std::string& fontFamily )
1315 if( NULL != mImpl->mEventData )
1317 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1318 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1320 if( EventData::SELECTING == mImpl->mEventData->mState )
1322 CharacterIndex startOfSelectedText = 0u;
1323 Length lengthOfSelectedText = 0u;
1324 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1325 mImpl->mModel->mLogicalModel,
1326 startOfSelectedText,
1327 lengthOfSelectedText );
1329 fontDescriptionRun.familyLength = fontFamily.size();
1330 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1331 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1332 fontDescriptionRun.familyDefined = true;
1334 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1336 // Request to relayout.
1337 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1342 UPDATE_LAYOUT_SIZE |
1345 mImpl->mRecalculateNaturalSize = true;
1346 mImpl->RequestRelayout();
1348 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1349 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1350 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1352 // As the font changes, recalculate the handle positions is needed.
1353 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1354 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1355 mImpl->mEventData->mUpdateHighlightBox = true;
1356 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1361 const std::string& Controller::GetInputFontFamily() const
1363 if( NULL != mImpl->mEventData )
1365 return mImpl->mEventData->mInputStyle.familyName;
1368 // Return the default font's family if there is no EventData.
1369 return GetDefaultFontFamily();
1372 void Controller::SetInputFontWeight( FontWeight weight )
1374 if( NULL != mImpl->mEventData )
1376 mImpl->mEventData->mInputStyle.weight = weight;
1377 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1379 if( EventData::SELECTING == mImpl->mEventData->mState )
1381 CharacterIndex startOfSelectedText = 0u;
1382 Length lengthOfSelectedText = 0u;
1383 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1384 mImpl->mModel->mLogicalModel,
1385 startOfSelectedText,
1386 lengthOfSelectedText );
1388 fontDescriptionRun.weight = weight;
1389 fontDescriptionRun.weightDefined = true;
1391 // Request to relayout.
1392 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1397 UPDATE_LAYOUT_SIZE |
1400 mImpl->mRecalculateNaturalSize = true;
1401 mImpl->RequestRelayout();
1403 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1404 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1405 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1407 // As the font might change, recalculate the handle positions is needed.
1408 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1409 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1410 mImpl->mEventData->mUpdateHighlightBox = true;
1411 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1416 bool Controller::IsInputFontWeightDefined() const
1418 bool defined = false;
1420 if( NULL != mImpl->mEventData )
1422 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1428 FontWeight Controller::GetInputFontWeight() const
1430 if( NULL != mImpl->mEventData )
1432 return mImpl->mEventData->mInputStyle.weight;
1435 return GetDefaultFontWeight();
1438 void Controller::SetInputFontWidth( FontWidth width )
1440 if( NULL != mImpl->mEventData )
1442 mImpl->mEventData->mInputStyle.width = width;
1443 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1445 if( EventData::SELECTING == mImpl->mEventData->mState )
1447 CharacterIndex startOfSelectedText = 0u;
1448 Length lengthOfSelectedText = 0u;
1449 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1450 mImpl->mModel->mLogicalModel,
1451 startOfSelectedText,
1452 lengthOfSelectedText );
1454 fontDescriptionRun.width = width;
1455 fontDescriptionRun.widthDefined = true;
1457 // Request to relayout.
1458 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1463 UPDATE_LAYOUT_SIZE |
1466 mImpl->mRecalculateNaturalSize = true;
1467 mImpl->RequestRelayout();
1469 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1470 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1471 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1473 // As the font might change, recalculate the handle positions is needed.
1474 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1475 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1476 mImpl->mEventData->mUpdateHighlightBox = true;
1477 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1482 bool Controller::IsInputFontWidthDefined() const
1484 bool defined = false;
1486 if( NULL != mImpl->mEventData )
1488 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1494 FontWidth Controller::GetInputFontWidth() const
1496 if( NULL != mImpl->mEventData )
1498 return mImpl->mEventData->mInputStyle.width;
1501 return GetDefaultFontWidth();
1504 void Controller::SetInputFontSlant( FontSlant slant )
1506 if( NULL != mImpl->mEventData )
1508 mImpl->mEventData->mInputStyle.slant = slant;
1509 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1511 if( EventData::SELECTING == mImpl->mEventData->mState )
1513 CharacterIndex startOfSelectedText = 0u;
1514 Length lengthOfSelectedText = 0u;
1515 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1516 mImpl->mModel->mLogicalModel,
1517 startOfSelectedText,
1518 lengthOfSelectedText );
1520 fontDescriptionRun.slant = slant;
1521 fontDescriptionRun.slantDefined = true;
1523 // Request to relayout.
1524 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1529 UPDATE_LAYOUT_SIZE |
1532 mImpl->mRecalculateNaturalSize = true;
1533 mImpl->RequestRelayout();
1535 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1536 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1537 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1539 // As the font might change, recalculate the handle positions is needed.
1540 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1541 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1542 mImpl->mEventData->mUpdateHighlightBox = true;
1543 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1548 bool Controller::IsInputFontSlantDefined() const
1550 bool defined = false;
1552 if( NULL != mImpl->mEventData )
1554 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1560 FontSlant Controller::GetInputFontSlant() const
1562 if( NULL != mImpl->mEventData )
1564 return mImpl->mEventData->mInputStyle.slant;
1567 return GetDefaultFontSlant();
1570 void Controller::SetInputFontPointSize( float size )
1572 if( NULL != mImpl->mEventData )
1574 mImpl->mEventData->mInputStyle.size = size;
1575 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1577 if( EventData::SELECTING == mImpl->mEventData->mState )
1579 CharacterIndex startOfSelectedText = 0u;
1580 Length lengthOfSelectedText = 0u;
1581 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1582 mImpl->mModel->mLogicalModel,
1583 startOfSelectedText,
1584 lengthOfSelectedText );
1586 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1587 fontDescriptionRun.sizeDefined = true;
1589 // Request to relayout.
1590 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1595 UPDATE_LAYOUT_SIZE |
1598 mImpl->mRecalculateNaturalSize = true;
1599 mImpl->RequestRelayout();
1601 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1602 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1603 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1605 // As the font might change, recalculate the handle positions is needed.
1606 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1607 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1608 mImpl->mEventData->mUpdateHighlightBox = true;
1609 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1614 float Controller::GetInputFontPointSize() const
1616 if( NULL != mImpl->mEventData )
1618 return mImpl->mEventData->mInputStyle.size;
1621 // Return the default font's point size if there is no EventData.
1622 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1625 void Controller::SetInputLineSpacing( float lineSpacing )
1627 if( NULL != mImpl->mEventData )
1629 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1630 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1634 float Controller::GetInputLineSpacing() const
1636 if( NULL != mImpl->mEventData )
1638 return mImpl->mEventData->mInputStyle.lineSpacing;
1644 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1646 if( NULL != mImpl->mEventData )
1648 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1652 const std::string& Controller::GetInputShadowProperties() const
1654 if( NULL != mImpl->mEventData )
1656 return mImpl->mEventData->mInputStyle.shadowProperties;
1659 return EMPTY_STRING;
1662 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1664 if( NULL != mImpl->mEventData )
1666 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1670 const std::string& Controller::GetInputUnderlineProperties() const
1672 if( NULL != mImpl->mEventData )
1674 return mImpl->mEventData->mInputStyle.underlineProperties;
1677 return EMPTY_STRING;
1680 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1682 if( NULL != mImpl->mEventData )
1684 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1688 const std::string& Controller::GetInputEmbossProperties() const
1690 if( NULL != mImpl->mEventData )
1692 return mImpl->mEventData->mInputStyle.embossProperties;
1695 return GetDefaultEmbossProperties();
1698 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1700 if( NULL != mImpl->mEventData )
1702 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1706 const std::string& Controller::GetInputOutlineProperties() const
1708 if( NULL != mImpl->mEventData )
1710 return mImpl->mEventData->mInputStyle.outlineProperties;
1713 return GetDefaultOutlineProperties();
1716 void Controller::SetInputModePassword( bool passwordInput )
1718 if( NULL != mImpl->mEventData )
1720 mImpl->mEventData->mPasswordInput = passwordInput;
1724 bool Controller::IsInputModePassword()
1726 if( NULL != mImpl->mEventData )
1728 return mImpl->mEventData->mPasswordInput;
1733 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1735 if( NULL != mImpl->mEventData )
1737 mImpl->mEventData->mDoubleTapAction = action;
1741 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1743 NoTextTap::Action action = NoTextTap::NO_ACTION;
1745 if( NULL != mImpl->mEventData )
1747 action = mImpl->mEventData->mDoubleTapAction;
1753 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1755 if( NULL != mImpl->mEventData )
1757 mImpl->mEventData->mLongPressAction = action;
1761 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1763 NoTextTap::Action action = NoTextTap::NO_ACTION;
1765 if( NULL != mImpl->mEventData )
1767 action = mImpl->mEventData->mLongPressAction;
1773 bool Controller::IsUnderlineSetByString()
1775 return mImpl->mUnderlineSetByString;
1778 void Controller::UnderlineSetByString( bool setByString )
1780 mImpl->mUnderlineSetByString = setByString;
1783 bool Controller::IsShadowSetByString()
1785 return mImpl->mShadowSetByString;
1788 void Controller::ShadowSetByString( bool setByString )
1790 mImpl->mShadowSetByString = setByString;
1793 bool Controller::IsOutlineSetByString()
1795 return mImpl->mOutlineSetByString;
1798 void Controller::OutlineSetByString( bool setByString )
1800 mImpl->mOutlineSetByString = setByString;
1803 bool Controller::IsFontStyleSetByString()
1805 return mImpl->mFontStyleSetByString;
1808 void Controller::FontStyleSetByString( bool setByString )
1810 mImpl->mFontStyleSetByString = setByString;
1813 // public : Queries & retrieves.
1815 Layout::Engine& Controller::GetLayoutEngine()
1817 return mImpl->mLayoutEngine;
1820 View& Controller::GetView()
1822 return mImpl->mView;
1825 Vector3 Controller::GetNaturalSize()
1827 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1828 Vector3 naturalSize;
1830 // Make sure the model is up-to-date before layouting
1831 ProcessModifyEvents();
1833 if( mImpl->mRecalculateNaturalSize )
1835 // Operations that can be done only once until the text changes.
1836 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1843 GET_GLYPH_METRICS );
1845 // Set the update info to relayout the whole text.
1846 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1847 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1849 // Make sure the model is up-to-date before layouting
1850 mImpl->UpdateModel( onlyOnceOperations );
1852 // Layout the text for the new width.
1853 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1855 // Store the actual control's size to restore later.
1856 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1858 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1859 static_cast<OperationsMask>( onlyOnceOperations |
1861 naturalSize.GetVectorXY() );
1863 // Do not do again the only once operations.
1864 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1866 // Do the size related operations again.
1867 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1870 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1872 // Stores the natural size to avoid recalculate it again
1873 // unless the text/style changes.
1874 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1876 mImpl->mRecalculateNaturalSize = false;
1878 // Clear the update info. This info will be set the next time the text is updated.
1879 mImpl->mTextUpdateInfo.Clear();
1880 mImpl->mTextUpdateInfo.mClearAll = true;
1882 // Restore the actual control's size.
1883 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1885 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1889 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1891 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1894 naturalSize.x = ConvertToEven( naturalSize.x );
1895 naturalSize.y = ConvertToEven( naturalSize.y );
1900 float Controller::GetHeightForWidth( float width )
1902 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1903 // Make sure the model is up-to-date before layouting
1904 ProcessModifyEvents();
1907 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1908 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1909 mImpl->mTextUpdateInfo.mClearAll )
1911 // Operations that can be done only once until the text changes.
1912 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1919 GET_GLYPH_METRICS );
1921 // Set the update info to relayout the whole text.
1922 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1923 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1925 // Make sure the model is up-to-date before layouting
1926 mImpl->UpdateModel( onlyOnceOperations );
1929 // Layout the text for the new width.
1930 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1932 // Store the actual control's width.
1933 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1935 DoRelayout( Size( width, MAX_FLOAT ),
1936 static_cast<OperationsMask>( onlyOnceOperations |
1940 // Do not do again the only once operations.
1941 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1943 // Do the size related operations again.
1944 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1948 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1950 // Clear the update info. This info will be set the next time the text is updated.
1951 mImpl->mTextUpdateInfo.Clear();
1953 // Restore the actual control's width.
1954 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1956 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1960 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1961 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1964 return layoutSize.height;
1967 int Controller::GetLineCount( float width )
1969 GetHeightForWidth( width );
1970 int numberofLines = mImpl->mModel->GetNumberOfLines();
1971 return numberofLines;
1974 const ModelInterface* const Controller::GetTextModel() const
1976 return mImpl->mModel.Get();
1979 float Controller::GetScrollAmountByUserInput()
1981 float scrollAmount = 0.0f;
1983 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1985 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1986 mImpl->mEventData->mCheckScrollAmount = false;
1988 return scrollAmount;
1991 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1993 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1996 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1997 layoutHeight = layout.height;
1998 scrollPosition = mImpl->mModel->mScrollPosition.y;
1999 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2003 void Controller::SetHiddenInputOption(const Property::Map& options )
2005 if( NULL == mImpl->mHiddenInput )
2007 mImpl->mHiddenInput = new HiddenText( this );
2009 mImpl->mHiddenInput->SetProperties(options);
2012 void Controller::GetHiddenInputOption(Property::Map& options )
2014 if( NULL != mImpl->mHiddenInput )
2016 mImpl->mHiddenInput->GetProperties(options);
2020 void Controller::SetPlaceholderProperty( const Property::Map& map )
2022 const Property::Map::SizeType count = map.Count();
2024 for( Property::Map::SizeType position = 0; position < count; ++position )
2026 KeyValuePair keyValue = map.GetKeyValue( position );
2027 Property::Key& key = keyValue.first;
2028 Property::Value& value = keyValue.second;
2030 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2032 std::string text = "";
2034 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2036 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2038 std::string text = "";
2040 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2042 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2045 value.Get( textColor );
2046 if( GetPlaceholderTextColor() != textColor )
2048 SetPlaceholderTextColor( textColor );
2051 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2053 std::string fontFamily = "";
2054 value.Get( fontFamily );
2055 SetPlaceholderFontFamily( fontFamily );
2057 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2059 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2061 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2064 value.Get( pointSize );
2065 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2067 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2070 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2073 value.Get( pixelSize );
2074 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2076 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2079 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2082 value.Get( ellipsis );
2083 SetPlaceholderTextElideEnabled( ellipsis );
2088 void Controller::GetPlaceholderProperty( Property::Map& map )
2090 if( NULL != mImpl->mEventData )
2092 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2094 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2096 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2098 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2101 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2102 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2104 Property::Value fontStyleMapGet;
2105 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2106 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2108 // Choose font size : POINT_SIZE or PIXEL_SIZE
2109 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2111 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2115 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2118 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2120 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2125 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2127 // Make sure the model is up-to-date before layouting
2128 ProcessModifyEvents();
2130 if ( mImpl->mUpdateTextDirection )
2132 // Operations that can be done only once until the text changes.
2133 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( GET_SCRIPTS |
2140 // Set the update info to relayout the whole text.
2141 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2142 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2144 // Make sure the model is up-to-date before layouting
2145 mImpl->UpdateModel( onlyOnceOperations );
2147 Vector3 naturalSize;
2148 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2149 static_cast<OperationsMask>( onlyOnceOperations |
2150 LAYOUT | REORDER | UPDATE_DIRECTION ),
2151 naturalSize.GetVectorXY() );
2153 // Clear the update info. This info will be set the next time the text is updated.
2154 mImpl->mTextUpdateInfo.Clear();
2156 mImpl->mUpdateTextDirection = false;
2159 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2162 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2164 return mImpl->mModel->GetVerticalLineAlignment();
2167 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2169 mImpl->mModel->mVerticalLineAlignment = alignment;
2172 // public : Relayout.
2174 Controller::UpdateTextType Controller::Relayout( const Size& size )
2176 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2178 UpdateTextType updateTextType = NONE_UPDATED;
2180 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2182 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2184 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2185 updateTextType = MODEL_UPDATED;
2188 // Clear the update info. This info will be set the next time the text is updated.
2189 mImpl->mTextUpdateInfo.Clear();
2191 // Not worth to relayout if width or height is equal to zero.
2192 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2194 return updateTextType;
2197 // Whether a new size has been set.
2198 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2202 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2204 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2205 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2206 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2208 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2211 // Layout operations that need to be done if the size changes.
2212 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2215 UPDATE_LAYOUT_SIZE |
2217 // Set the update info to relayout the whole text.
2218 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2219 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2221 // Store the size used to layout the text.
2222 mImpl->mModel->mVisualModel->mControlSize = size;
2225 // Whether there are modify events.
2226 if( 0u != mImpl->mModifyEvents.Count() )
2228 // Style operations that need to be done if the text is modified.
2229 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2233 // Set the update info to elide the text.
2234 if( mImpl->mModel->mElideEnabled ||
2235 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2237 // Update Text layout for applying elided
2238 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2241 UPDATE_LAYOUT_SIZE |
2243 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2244 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2247 // Make sure the model is up-to-date before layouting.
2248 ProcessModifyEvents();
2249 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2253 updated = DoRelayout( size,
2254 mImpl->mOperationsPending,
2255 layoutSize ) || updated;
2259 updateTextType = MODEL_UPDATED;
2262 // Do not re-do any operation until something changes.
2263 mImpl->mOperationsPending = NO_OPERATION;
2264 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2266 // Whether the text control is editable
2267 const bool isEditable = NULL != mImpl->mEventData;
2269 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2271 if( newSize && isEditable )
2273 offset = mImpl->mModel->mScrollPosition;
2276 if( !isEditable || !IsMultiLineEnabled() )
2278 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2279 CalculateVerticalOffset( size );
2286 // If there is a new size, the scroll position needs to be clamped.
2287 mImpl->ClampHorizontalScroll( layoutSize );
2289 // Update the decorator's positions is needed if there is a new size.
2290 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2293 // Move the cursor, grab handle etc.
2294 if( mImpl->ProcessInputEvents() )
2296 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2300 // Clear the update info. This info will be set the next time the text is updated.
2301 mImpl->mTextUpdateInfo.Clear();
2302 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2304 return updateTextType;
2307 void Controller::RequestRelayout()
2309 mImpl->RequestRelayout();
2312 // public : Input style change signals.
2314 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2316 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2319 void Controller::ProcessInputStyleChangedSignals()
2321 if( NULL == mImpl->mEventData )
2327 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2328 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2332 const InputStyle::Mask mask = *it;
2334 if( NULL != mImpl->mEditableControlInterface )
2336 // Emit the input style changed signal.
2337 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2341 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2344 // public : Text-input Event Queuing.
2346 void Controller::KeyboardFocusGainEvent()
2348 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2350 if( NULL != mImpl->mEventData )
2352 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2353 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2355 mImpl->ChangeState( EventData::EDITING );
2356 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2357 mImpl->mEventData->mUpdateInputStyle = true;
2359 mImpl->NotifyImfMultiLineStatus();
2360 if( mImpl->IsShowingPlaceholderText() )
2362 // Show alternative placeholder-text when editing
2363 ShowPlaceholderText();
2366 mImpl->RequestRelayout();
2370 void Controller::KeyboardFocusLostEvent()
2372 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2374 if( NULL != mImpl->mEventData )
2376 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2378 mImpl->ChangeState( EventData::INACTIVE );
2380 if( !mImpl->IsShowingRealText() )
2382 // Revert to regular placeholder-text when not editing
2383 ShowPlaceholderText();
2387 mImpl->RequestRelayout();
2390 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2392 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2394 bool textChanged = false;
2395 bool relayoutNeeded = false;
2397 if( ( NULL != mImpl->mEventData ) &&
2398 ( keyEvent.state == KeyEvent::Down ) )
2400 int keyCode = keyEvent.keyCode;
2401 const std::string& keyString = keyEvent.keyPressed;
2402 const std::string keyName = keyEvent.keyPressedName;
2404 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2406 // Pre-process to separate modifying events from non-modifying input events.
2409 // In some platforms arrive key events with no key code.
2413 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2418 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2419 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2420 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2421 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2423 // If don't have any text, do nothing.
2424 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2429 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2430 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2431 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2432 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2434 // Logic to determine whether this text control will lose focus or not.
2435 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2436 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2437 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2438 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2439 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2440 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2445 mImpl->mEventData->mCheckScrollAmount = true;
2446 Event event( Event::CURSOR_KEY_EVENT );
2447 event.p1.mInt = keyCode;
2448 event.p2.mBool = keyEvent.IsShiftModifier();
2449 mImpl->mEventData->mEventQueue.push_back( event );
2451 // Will request for relayout.
2452 relayoutNeeded = true;
2454 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2456 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2457 // If not handle it here, any selected text will be deleted
2462 else if ( keyEvent.IsCtrlModifier() )
2464 bool consumed = false;
2465 if (keyName == KEY_C_NAME)
2467 // Ctrl-C to copy the selected text
2468 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2471 else if (keyName == KEY_V_NAME)
2473 // Ctrl-V to paste the copied text
2474 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2477 else if (keyName == KEY_X_NAME)
2479 // Ctrl-X to cut the selected text
2480 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2485 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2486 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2488 textChanged = DeleteEvent( keyCode );
2490 // Will request for relayout.
2491 relayoutNeeded = true;
2493 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2494 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2495 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2497 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2498 mImpl->ChangeState( EventData::INACTIVE );
2500 // Will request for relayout.
2501 relayoutNeeded = true;
2503 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2505 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2507 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2508 // and a character is typed after the type of a upper case latin character.
2513 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2515 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2521 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2523 // IMF manager is no longer handling key-events
2524 mImpl->ClearPreEditFlag();
2526 InsertText( keyString, COMMIT );
2529 // Will request for relayout.
2530 relayoutNeeded = true;
2533 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2534 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2536 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2537 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2538 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2540 // Should not change the state if the key is the shift send by the imf manager.
2541 // Otherwise, when the state is SELECTING the text controller can't send the right
2542 // surrounding info to the imf.
2543 mImpl->ChangeState( EventData::EDITING );
2545 // Will request for relayout.
2546 relayoutNeeded = true;
2549 if( relayoutNeeded )
2551 mImpl->RequestRelayout();
2556 ( NULL != mImpl->mEditableControlInterface ) )
2558 // Do this last since it provides callbacks into application code
2559 mImpl->mEditableControlInterface->TextChanged();
2565 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2567 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2569 if( NULL != mImpl->mEventData )
2571 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2572 EventData::State state( mImpl->mEventData->mState );
2573 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2575 if( mImpl->IsClipboardVisible() )
2577 if( EventData::INACTIVE == state || EventData::EDITING == state)
2579 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2581 relayoutNeeded = true;
2583 else if( 1u == tapCount )
2585 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2587 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2590 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2592 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2593 relayoutNeeded = true;
2597 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2599 // Hide placeholder text
2603 if( EventData::INACTIVE == state )
2605 mImpl->ChangeState( EventData::EDITING );
2607 else if( !mImpl->IsClipboardEmpty() )
2609 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2611 relayoutNeeded = true;
2614 else if( 2u == tapCount )
2616 if( mImpl->mEventData->mSelectionEnabled &&
2617 mImpl->IsShowingRealText() )
2619 relayoutNeeded = true;
2620 mImpl->mEventData->mIsLeftHandleSelected = true;
2621 mImpl->mEventData->mIsRightHandleSelected = true;
2625 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2626 if( relayoutNeeded )
2628 Event event( Event::TAP_EVENT );
2629 event.p1.mUint = tapCount;
2630 event.p2.mFloat = x;
2631 event.p3.mFloat = y;
2632 mImpl->mEventData->mEventQueue.push_back( event );
2634 mImpl->RequestRelayout();
2638 // Reset keyboard as tap event has occurred.
2639 mImpl->ResetImfManager();
2642 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2644 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2646 if( NULL != mImpl->mEventData )
2648 Event event( Event::PAN_EVENT );
2649 event.p1.mInt = state;
2650 event.p2.mFloat = displacement.x;
2651 event.p3.mFloat = displacement.y;
2652 mImpl->mEventData->mEventQueue.push_back( event );
2654 mImpl->RequestRelayout();
2658 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2660 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2662 if( ( state == Gesture::Started ) &&
2663 ( NULL != mImpl->mEventData ) )
2665 // The 1st long-press on inactive text-field is treated as tap
2666 if( EventData::INACTIVE == mImpl->mEventData->mState )
2668 mImpl->ChangeState( EventData::EDITING );
2670 Event event( Event::TAP_EVENT );
2672 event.p2.mFloat = x;
2673 event.p3.mFloat = y;
2674 mImpl->mEventData->mEventQueue.push_back( event );
2676 mImpl->RequestRelayout();
2678 else if( !mImpl->IsShowingRealText() )
2680 Event event( Event::LONG_PRESS_EVENT );
2681 event.p1.mInt = state;
2682 event.p2.mFloat = x;
2683 event.p3.mFloat = y;
2684 mImpl->mEventData->mEventQueue.push_back( event );
2685 mImpl->RequestRelayout();
2687 else if( !mImpl->IsClipboardVisible() )
2689 // Reset the imf manager to commit the pre-edit before selecting the text.
2690 mImpl->ResetImfManager();
2692 Event event( Event::LONG_PRESS_EVENT );
2693 event.p1.mInt = state;
2694 event.p2.mFloat = x;
2695 event.p3.mFloat = y;
2696 mImpl->mEventData->mEventQueue.push_back( event );
2697 mImpl->RequestRelayout();
2699 mImpl->mEventData->mIsLeftHandleSelected = true;
2700 mImpl->mEventData->mIsRightHandleSelected = true;
2705 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2707 // Whether the text needs to be relaid-out.
2708 bool requestRelayout = false;
2710 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2711 bool retrieveText = false;
2712 bool retrieveCursor = false;
2714 switch( imfEvent.eventName )
2716 case ImfManager::COMMIT:
2718 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2719 requestRelayout = true;
2720 retrieveCursor = true;
2723 case ImfManager::PREEDIT:
2725 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2726 requestRelayout = true;
2727 retrieveCursor = true;
2730 case ImfManager::DELETESURROUNDING:
2732 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2733 imfEvent.numberOfChars,
2734 DONT_UPDATE_INPUT_STYLE );
2738 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2739 !mImpl->IsPlaceholderAvailable() )
2741 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2745 ShowPlaceholderText();
2747 mImpl->mEventData->mUpdateCursorPosition = true;
2748 mImpl->mEventData->mScrollAfterDelete = true;
2750 requestRelayout = true;
2754 case ImfManager::GETSURROUNDING:
2756 retrieveText = true;
2757 retrieveCursor = true;
2760 case ImfManager::PRIVATECOMMAND:
2762 // PRIVATECOMMAND event is just for getting the private command message
2763 retrieveText = true;
2764 retrieveCursor = true;
2767 case ImfManager::VOID:
2774 if( requestRelayout )
2776 mImpl->mOperationsPending = ALL_OPERATIONS;
2777 mImpl->RequestRelayout();
2781 CharacterIndex cursorPosition = 0u;
2782 Length numberOfWhiteSpaces = 0u;
2784 if( retrieveCursor )
2786 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2788 cursorPosition = mImpl->GetLogicalCursorPosition();
2790 if( cursorPosition < numberOfWhiteSpaces )
2792 cursorPosition = 0u;
2796 cursorPosition -= numberOfWhiteSpaces;
2802 if( !mImpl->IsShowingPlaceholderText() )
2804 // Retrieves the normal text string.
2805 mImpl->GetText( numberOfWhiteSpaces, text );
2809 // When the current text is Placeholder Text, the surrounding text should be empty string.
2810 // It means DALi should send empty string ("") to IME.
2815 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2817 if( requestRelayout &&
2818 ( NULL != mImpl->mEditableControlInterface ) )
2820 // Do this last since it provides callbacks into application code
2821 mImpl->mEditableControlInterface->TextChanged();
2824 return callbackData;
2827 void Controller::PasteClipboardItemEvent()
2829 // Retrieve the clipboard contents first
2830 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2831 std::string stringToPaste( notifier.GetContent() );
2833 // Commit the current pre-edit text; the contents of the clipboard should be appended
2834 mImpl->ResetImfManager();
2836 // Temporary disable hiding clipboard
2837 mImpl->SetClipboardHideEnable( false );
2840 PasteText( stringToPaste );
2842 mImpl->SetClipboardHideEnable( true );
2845 // protected : Inherit from Text::Decorator::ControllerInterface.
2847 void Controller::GetTargetSize( Vector2& targetSize )
2849 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2852 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2854 if( NULL != mImpl->mEditableControlInterface )
2856 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2860 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2862 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2864 if( NULL != mImpl->mEventData )
2866 switch( handleType )
2870 Event event( Event::GRAB_HANDLE_EVENT );
2871 event.p1.mUint = state;
2872 event.p2.mFloat = x;
2873 event.p3.mFloat = y;
2875 mImpl->mEventData->mEventQueue.push_back( event );
2878 case LEFT_SELECTION_HANDLE:
2880 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2881 event.p1.mUint = state;
2882 event.p2.mFloat = x;
2883 event.p3.mFloat = y;
2885 mImpl->mEventData->mEventQueue.push_back( event );
2888 case RIGHT_SELECTION_HANDLE:
2890 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2891 event.p1.mUint = state;
2892 event.p2.mFloat = x;
2893 event.p3.mFloat = y;
2895 mImpl->mEventData->mEventQueue.push_back( event );
2898 case LEFT_SELECTION_HANDLE_MARKER:
2899 case RIGHT_SELECTION_HANDLE_MARKER:
2901 // Markers do not move the handles.
2904 case HANDLE_TYPE_COUNT:
2906 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2910 mImpl->RequestRelayout();
2914 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2916 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2918 if( NULL == mImpl->mEventData )
2925 case Toolkit::TextSelectionPopup::CUT:
2927 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2928 mImpl->mOperationsPending = ALL_OPERATIONS;
2930 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2931 !mImpl->IsPlaceholderAvailable() )
2933 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2937 ShowPlaceholderText();
2940 mImpl->mEventData->mUpdateCursorPosition = true;
2941 mImpl->mEventData->mScrollAfterDelete = true;
2943 mImpl->RequestRelayout();
2945 if( NULL != mImpl->mEditableControlInterface )
2947 mImpl->mEditableControlInterface->TextChanged();
2951 case Toolkit::TextSelectionPopup::COPY:
2953 mImpl->SendSelectionToClipboard( false ); // Text not modified
2955 mImpl->mEventData->mUpdateCursorPosition = true;
2957 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2960 case Toolkit::TextSelectionPopup::PASTE:
2962 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2965 case Toolkit::TextSelectionPopup::SELECT:
2967 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2969 if( mImpl->mEventData->mSelectionEnabled )
2971 // Creates a SELECT event.
2972 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2976 case Toolkit::TextSelectionPopup::SELECT_ALL:
2978 // Creates a SELECT_ALL event
2979 SelectEvent( 0.f, 0.f, true );
2982 case Toolkit::TextSelectionPopup::CLIPBOARD:
2984 mImpl->ShowClipboard();
2987 case Toolkit::TextSelectionPopup::NONE:
2995 void Controller::DisplayTimeExpired()
2997 mImpl->mEventData->mUpdateCursorPosition = true;
2998 // Apply modifications to the model
2999 mImpl->mOperationsPending = ALL_OPERATIONS;
3001 mImpl->RequestRelayout();
3004 // private : Update.
3006 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3008 bool removedPrevious = false;
3009 bool removedSelected = false;
3010 bool maxLengthReached = false;
3012 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3014 if( NULL == mImpl->mEventData )
3019 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3020 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3021 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3023 // TODO: At the moment the underline runs are only for pre-edit.
3024 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3026 // Remove the previous IMF pre-edit.
3027 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3029 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3030 mImpl->mEventData->mPreEditLength,
3031 DONT_UPDATE_INPUT_STYLE );
3033 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3034 mImpl->mEventData->mPreEditLength = 0u;
3038 // Remove the previous Selection.
3039 removedSelected = RemoveSelectedText();
3043 Vector<Character> utf32Characters;
3044 Length characterCount = 0u;
3048 // Convert text into UTF-32
3049 utf32Characters.Resize( text.size() );
3051 // This is a bit horrible but std::string returns a (signed) char*
3052 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3054 // Transform a text array encoded in utf8 into an array encoded in utf32.
3055 // It returns the actual number of characters.
3056 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3057 utf32Characters.Resize( characterCount );
3059 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3060 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3063 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3065 // The placeholder text is no longer needed
3066 if( mImpl->IsShowingPlaceholderText() )
3071 mImpl->ChangeState( EventData::EDITING );
3073 // Handle the IMF (predicitive text) state changes
3074 if( COMMIT == type )
3076 // IMF manager is no longer handling key-events
3077 mImpl->ClearPreEditFlag();
3081 if( !mImpl->mEventData->mPreEditFlag )
3083 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3085 // Record the start of the pre-edit text
3086 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3089 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3090 mImpl->mEventData->mPreEditFlag = true;
3092 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3095 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3097 // Restrict new text to fit within Maximum characters setting.
3098 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3099 maxLengthReached = ( characterCount > maxSizeOfNewText );
3101 // The cursor position.
3102 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3104 // Update the text's style.
3106 // Updates the text style runs by adding characters.
3107 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3109 // Get the character index from the cursor index.
3110 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3112 // Retrieve the text's style for the given index.
3114 mImpl->RetrieveDefaultInputStyle( style );
3115 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3117 // Whether to add a new text color run.
3118 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3120 // Whether to add a new font run.
3121 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3122 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3123 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3124 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3125 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3130 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3131 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3133 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3134 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3135 colorRun.characterRun.characterIndex = cursorIndex;
3136 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3139 if( addFontNameRun ||
3145 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3146 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3148 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3150 if( addFontNameRun )
3152 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3153 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3154 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3155 fontDescriptionRun.familyDefined = true;
3157 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3160 if( addFontWeightRun )
3162 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3163 fontDescriptionRun.weightDefined = true;
3166 if( addFontWidthRun )
3168 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3169 fontDescriptionRun.widthDefined = true;
3172 if( addFontSlantRun )
3174 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3175 fontDescriptionRun.slantDefined = true;
3178 if( addFontSizeRun )
3180 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3181 fontDescriptionRun.sizeDefined = true;
3184 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3185 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3188 // Insert at current cursor position.
3189 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3191 if( cursorIndex < numberOfCharactersInModel )
3193 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3197 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3200 // Mark the first paragraph to be updated.
3201 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3203 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3204 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3205 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3206 mImpl->mTextUpdateInfo.mClearAll = true;
3210 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3211 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3214 // Update the cursor index.
3215 cursorIndex += maxSizeOfNewText;
3217 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 );
3220 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3221 mImpl->IsPlaceholderAvailable() )
3223 // Show place-holder if empty after removing the pre-edit text
3224 ShowPlaceholderText();
3225 mImpl->mEventData->mUpdateCursorPosition = true;
3226 mImpl->ClearPreEditFlag();
3228 else if( removedPrevious ||
3230 ( 0 != utf32Characters.Count() ) )
3232 // Queue an inserted event
3233 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3235 mImpl->mEventData->mUpdateCursorPosition = true;
3236 if( removedSelected )
3238 mImpl->mEventData->mScrollAfterDelete = true;
3242 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3246 if( maxLengthReached )
3248 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3250 mImpl->ResetImfManager();
3252 if( NULL != mImpl->mEditableControlInterface )
3254 // Do this last since it provides callbacks into application code
3255 mImpl->mEditableControlInterface->MaxLengthReached();
3260 void Controller::PasteText( const std::string& stringToPaste )
3262 InsertText( stringToPaste, Text::Controller::COMMIT );
3263 mImpl->ChangeState( EventData::EDITING );
3264 mImpl->RequestRelayout();
3266 if( NULL != mImpl->mEditableControlInterface )
3268 // Do this last since it provides callbacks into application code
3269 mImpl->mEditableControlInterface->TextChanged();
3273 bool Controller::RemoveText( int cursorOffset,
3274 int numberOfCharacters,
3275 UpdateInputStyleType type )
3277 bool removed = false;
3279 if( NULL == mImpl->mEventData )
3284 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3285 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3287 if( !mImpl->IsShowingPlaceholderText() )
3289 // Delete at current cursor position
3290 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3291 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3293 CharacterIndex cursorIndex = 0;
3295 // Validate the cursor position & number of characters
3296 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3298 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3301 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3303 numberOfCharacters = currentText.Count() - cursorIndex;
3306 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.
3307 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3309 // Mark the paragraphs to be updated.
3310 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3312 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3313 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3314 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3315 mImpl->mTextUpdateInfo.mClearAll = true;
3319 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3320 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3323 // Update the input style and remove the text's style before removing the text.
3325 if( UPDATE_INPUT_STYLE == type )
3327 // Keep a copy of the current input style.
3328 InputStyle currentInputStyle;
3329 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3331 // Set first the default input style.
3332 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3334 // Update the input style.
3335 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3337 // Compare if the input style has changed.
3338 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3340 if( hasInputStyleChanged )
3342 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3343 // Queue the input style changed signal.
3344 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3348 // Updates the text style runs by removing characters. Runs with no characters are removed.
3349 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3351 // Remove the characters.
3352 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3353 Vector<Character>::Iterator last = first + numberOfCharacters;
3355 currentText.Erase( first, last );
3357 // Cursor position retreat
3358 oldCursorIndex = cursorIndex;
3360 mImpl->mEventData->mScrollAfterDelete = true;
3362 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3370 bool Controller::RemoveSelectedText()
3372 bool textRemoved( false );
3374 if( EventData::SELECTING == mImpl->mEventData->mState )
3376 std::string removedString;
3377 mImpl->RetrieveSelection( removedString, true );
3379 if( !removedString.empty() )
3382 mImpl->ChangeState( EventData::EDITING );
3389 // private : Relayout.
3391 bool Controller::DoRelayout( const Size& size,
3392 OperationsMask operationsRequired,
3395 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3396 bool viewUpdated( false );
3398 // Calculate the operations to be done.
3399 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3401 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3402 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3404 // Get the current layout size.
3405 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3407 if( NO_OPERATION != ( LAYOUT & operations ) )
3409 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3411 // Some vectors with data needed to layout and reorder may be void
3412 // after the first time the text has been laid out.
3413 // Fill the vectors again.
3415 // Calculate the number of glyphs to layout.
3416 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3417 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3418 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3419 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3421 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3422 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3423 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3424 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3426 if( 0u == totalNumberOfGlyphs )
3428 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3430 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3433 // Nothing else to do if there is no glyphs.
3434 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3438 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3439 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3440 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3441 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3442 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3443 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3444 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3445 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3447 // Set the layout parameters.
3448 const Vector2 sizeOffset = Vector2(outlineWidth * 2.0f, outlineWidth * 2.0f); // The outline should be fit into the bounding box
3449 Layout::Parameters layoutParameters( size - sizeOffset,
3451 lineBreakInfo.Begin(),
3452 wordBreakInfo.Begin(),
3453 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3455 glyphsToCharactersMap.Begin(),
3456 charactersPerGlyph.Begin(),
3457 charactersToGlyphBuffer,
3458 glyphsPerCharacterBuffer,
3459 totalNumberOfGlyphs,
3460 mImpl->mModel->mHorizontalAlignment,
3461 mImpl->mModel->mLineWrapMode,
3464 // Resize the vector of positions to have the same size than the vector of glyphs.
3465 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3466 glyphPositions.Resize( totalNumberOfGlyphs );
3468 // Whether the last character is a new paragraph character.
3469 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3470 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3472 // The initial glyph and the number of glyphs to layout.
3473 layoutParameters.startGlyphIndex = startGlyphIndex;
3474 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3475 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3476 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3478 // Update the ellipsis
3479 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3481 if( NULL != mImpl->mEventData )
3483 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3485 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3487 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3489 // Disable ellipsis when editing
3490 elideTextEnabled = false;
3493 // Reset the scroll position in inactive state
3494 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3496 ResetScrollPosition();
3500 // Update the visual model.
3502 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3504 mImpl->mModel->mVisualModel->mLines,
3508 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3512 layoutSize = newLayoutSize;
3514 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3516 mImpl->mIsTextDirectionRTL = false;
3519 // Reorder the lines
3520 if( NO_OPERATION != ( REORDER & operations ) )
3522 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3523 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3525 // Check first if there are paragraphs with bidirectional info.
3526 if( 0u != bidirectionalInfo.Count() )
3529 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3531 // Reorder the lines.
3532 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3533 ReorderLines( bidirectionalInfo,
3535 requestedNumberOfCharacters,
3536 mImpl->mModel->mVisualModel->mLines,
3537 bidirectionalLineInfo );
3539 // Set the bidirectional info per line into the layout parameters.
3540 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3541 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3543 // Re-layout the text. Reorder those lines with right to left characters.
3544 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3546 requestedNumberOfCharacters,
3549 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3551 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3554 mImpl->mIsTextDirectionRTL = firstline->direction;
3560 // Sets the layout size.
3561 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3563 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3568 if( NO_OPERATION != ( ALIGN & operations ) )
3570 // The laid-out lines.
3571 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3573 // Need to align with the control's size as the text may contain lines
3574 // starting either with left to right text or right to left.
3575 mImpl->mLayoutEngine.Align( size,
3577 requestedNumberOfCharacters,
3578 mImpl->mModel->mHorizontalAlignment,
3580 mImpl->mModel->mAlignmentOffset );
3584 #if defined(DEBUG_ENABLED)
3585 std::string currentText;
3586 GetText( currentText );
3587 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3589 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3593 void Controller::CalculateVerticalOffset( const Size& controlSize )
3595 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3597 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3599 // Get the line height of the default font.
3600 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3603 switch( mImpl->mModel->mVerticalAlignment )
3605 case VerticalAlignment::TOP:
3607 mImpl->mModel->mScrollPosition.y = 0.f;
3610 case VerticalAlignment::CENTER:
3612 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3615 case VerticalAlignment::BOTTOM:
3617 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3623 // private : Events.
3625 void Controller::ProcessModifyEvents()
3627 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3629 if( 0u == events.Count() )
3635 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3636 endIt = events.End();
3640 const ModifyEvent& event = *it;
3642 if( ModifyEvent::TEXT_REPLACED == event.type )
3644 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3645 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3647 TextReplacedEvent();
3649 else if( ModifyEvent::TEXT_INSERTED == event.type )
3651 TextInsertedEvent();
3653 else if( ModifyEvent::TEXT_DELETED == event.type )
3655 // Placeholder-text cannot be deleted
3656 if( !mImpl->IsShowingPlaceholderText() )
3663 if( NULL != mImpl->mEventData )
3665 // When the text is being modified, delay cursor blinking
3666 mImpl->mEventData->mDecorator->DelayCursorBlink();
3668 // Update selection position after modifying the text
3669 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3670 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3673 // Discard temporary text
3677 void Controller::TextReplacedEvent()
3679 // The natural size needs to be re-calculated.
3680 mImpl->mRecalculateNaturalSize = true;
3682 // The text direction needs to be updated.
3683 mImpl->mUpdateTextDirection = true;
3685 // Apply modifications to the model
3686 mImpl->mOperationsPending = ALL_OPERATIONS;
3689 void Controller::TextInsertedEvent()
3691 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3693 if( NULL == mImpl->mEventData )
3698 mImpl->mEventData->mCheckScrollAmount = true;
3700 // The natural size needs to be re-calculated.
3701 mImpl->mRecalculateNaturalSize = true;
3703 // The text direction needs to be updated.
3704 mImpl->mUpdateTextDirection = true;
3706 // Apply modifications to the model; TODO - Optimize this
3707 mImpl->mOperationsPending = ALL_OPERATIONS;
3710 void Controller::TextDeletedEvent()
3712 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3714 if( NULL == mImpl->mEventData )
3719 mImpl->mEventData->mCheckScrollAmount = true;
3721 // The natural size needs to be re-calculated.
3722 mImpl->mRecalculateNaturalSize = true;
3724 // The text direction needs to be updated.
3725 mImpl->mUpdateTextDirection = true;
3727 // Apply modifications to the model; TODO - Optimize this
3728 mImpl->mOperationsPending = ALL_OPERATIONS;
3731 void Controller::SelectEvent( float x, float y, bool selectAll )
3733 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3735 if( NULL != mImpl->mEventData )
3739 Event event( Event::SELECT_ALL );
3740 mImpl->mEventData->mEventQueue.push_back( event );
3744 Event event( Event::SELECT );
3745 event.p2.mFloat = x;
3746 event.p3.mFloat = y;
3747 mImpl->mEventData->mEventQueue.push_back( event );
3750 mImpl->mEventData->mCheckScrollAmount = true;
3751 mImpl->mEventData->mIsLeftHandleSelected = true;
3752 mImpl->mEventData->mIsRightHandleSelected = true;
3753 mImpl->RequestRelayout();
3757 bool Controller::DeleteEvent( int keyCode )
3759 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3761 bool removed = false;
3763 if( NULL == mImpl->mEventData )
3768 // IMF manager is no longer handling key-events
3769 mImpl->ClearPreEditFlag();
3771 if( EventData::SELECTING == mImpl->mEventData->mState )
3773 removed = RemoveSelectedText();
3775 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3777 // Remove the character before the current cursor position
3778 removed = RemoveText( -1,
3780 UPDATE_INPUT_STYLE );
3782 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
3784 // Remove the character after the current cursor position
3785 removed = RemoveText( 0,
3787 UPDATE_INPUT_STYLE );
3792 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3793 !mImpl->IsPlaceholderAvailable() )
3795 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3799 ShowPlaceholderText();
3801 mImpl->mEventData->mUpdateCursorPosition = true;
3802 mImpl->mEventData->mScrollAfterDelete = true;
3808 // private : Helpers.
3810 void Controller::ResetText()
3813 mImpl->mModel->mLogicalModel->mText.Clear();
3815 // We have cleared everything including the placeholder-text
3816 mImpl->PlaceholderCleared();
3818 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3819 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3820 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3822 // Clear any previous text.
3823 mImpl->mTextUpdateInfo.mClearAll = true;
3825 // The natural size needs to be re-calculated.
3826 mImpl->mRecalculateNaturalSize = true;
3828 // The text direction needs to be updated.
3829 mImpl->mUpdateTextDirection = true;
3831 // Apply modifications to the model
3832 mImpl->mOperationsPending = ALL_OPERATIONS;
3835 void Controller::ShowPlaceholderText()
3837 if( mImpl->IsPlaceholderAvailable() )
3839 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3841 if( NULL == mImpl->mEventData )
3846 mImpl->mEventData->mIsShowingPlaceholderText = true;
3848 // Disable handles when showing place-holder text
3849 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3850 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3851 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3853 const char* text( NULL );
3856 // TODO - Switch Placeholder text when changing state
3857 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3858 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3860 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3861 size = mImpl->mEventData->mPlaceholderTextActive.size();
3865 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3866 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3869 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3870 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3872 // Reset model for showing placeholder.
3873 mImpl->mModel->mLogicalModel->mText.Clear();
3874 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3876 // Convert text into UTF-32
3877 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3878 utf32Characters.Resize( size );
3880 // This is a bit horrible but std::string returns a (signed) char*
3881 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3883 // Transform a text array encoded in utf8 into an array encoded in utf32.
3884 // It returns the actual number of characters.
3885 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3886 utf32Characters.Resize( characterCount );
3888 // The characters to be added.
3889 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3891 // Reset the cursor position
3892 mImpl->mEventData->mPrimaryCursorPosition = 0;
3894 // The natural size needs to be re-calculated.
3895 mImpl->mRecalculateNaturalSize = true;
3897 // The text direction needs to be updated.
3898 mImpl->mUpdateTextDirection = true;
3900 // Apply modifications to the model
3901 mImpl->mOperationsPending = ALL_OPERATIONS;
3903 // Update the rest of the model during size negotiation
3904 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3908 void Controller::ClearFontData()
3910 if( mImpl->mFontDefaults )
3912 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3915 // Set flags to update the model.
3916 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3917 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3918 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3920 mImpl->mTextUpdateInfo.mClearAll = true;
3921 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3922 mImpl->mRecalculateNaturalSize = true;
3924 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3930 UPDATE_LAYOUT_SIZE |
3935 void Controller::ClearStyleData()
3937 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3938 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3941 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3943 // Reset the cursor position
3944 if( NULL != mImpl->mEventData )
3946 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3948 // Update the cursor if it's in editing mode.
3949 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3951 mImpl->mEventData->mUpdateCursorPosition = true;
3956 void Controller::ResetScrollPosition()
3958 if( NULL != mImpl->mEventData )
3960 // Reset the scroll position.
3961 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3962 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3966 void Controller::SetControlInterface( ControlInterface* controlInterface )
3968 mImpl->mControlInterface = controlInterface;
3971 bool Controller::ShouldClearFocusOnEscape() const
3973 return mImpl->mShouldClearFocusOnEscape;
3976 // private : Private contructors & copy operator.
3978 Controller::Controller()
3981 mImpl = new Controller::Impl( NULL, NULL );
3984 Controller::Controller( ControlInterface* controlInterface )
3986 mImpl = new Controller::Impl( controlInterface, NULL );
3989 Controller::Controller( ControlInterface* controlInterface,
3990 EditableControlInterface* editableControlInterface )
3992 mImpl = new Controller::Impl( controlInterface,
3993 editableControlInterface );
3996 // The copy constructor and operator are left unimplemented.
3998 // protected : Destructor.
4000 Controller::~Controller()
4007 } // namespace Toolkit