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>
30 #include <dali-toolkit/internal/text/bidirectional-support.h>
31 #include <dali-toolkit/internal/text/character-set-conversion.h>
32 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
33 #include <dali-toolkit/internal/text/markup-processor.h>
34 #include <dali-toolkit/internal/text/multi-language-support.h>
35 #include <dali-toolkit/internal/text/text-controller-impl.h>
36 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
37 #include <dali-toolkit/internal/text/text-font-style.h>
42 #if defined(DEBUG_ENABLED)
43 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
46 const float MAX_FLOAT = std::numeric_limits<float>::max();
48 const std::string EMPTY_STRING("");
50 const char * const PLACEHOLDER_TEXT = "placeholderText";
51 const char * const PLACEHOLDER_TEXT_FOCUSED = "placeholderTextFocused";
52 const char * const PLACEHOLDER_COLOR = "placeholderColor";
53 const char * const PLACEHOLDER_FONT_FAMILY = "placeholderFontFamily";
54 const char * const PLACEHOLDER_FONT_STYLE = "placeholderFontStyle";
55 const char * const PLACEHOLDER_POINT_SIZE = "placeholderPointSize";
56 const char * const PLACEHOLDER_PIXEL_SIZE = "placeholderPixelSize";
57 const char * const PLACEHOLDER_ELLIPSIS = "placeholderEllipsis";
59 float ConvertToEven( float value )
61 int intValue(static_cast<int>( value ));
62 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
77 * @brief Adds a new font description run for the selected text.
79 * The new font parameters are added after the call to this method.
81 * @param[in] eventData The event data pointer.
82 * @param[in] logicalModel The logical model where to add the new font description run.
83 * @param[out] startOfSelectedText Index to the first selected character.
84 * @param[out] lengthOfSelectedText Number of selected characters.
86 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
87 LogicalModelPtr logicalModel,
88 CharacterIndex& startOfSelectedText,
89 Length& lengthOfSelectedText )
91 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
93 // Get start and end position of selection
94 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
95 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
98 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
99 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
101 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
103 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
104 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
106 // Recalculate the selection highlight as the metrics may have changed.
107 eventData->mUpdateLeftSelectionPosition = true;
108 eventData->mUpdateRightSelectionPosition = true;
109 eventData->mUpdateHighlightBox = true;
111 return fontDescriptionRun;
114 // public : Constructor.
116 ControllerPtr Controller::New()
118 return ControllerPtr( new Controller() );
121 ControllerPtr Controller::New( ControlInterface* controlInterface )
123 return ControllerPtr( new Controller( controlInterface ) );
126 ControllerPtr Controller::New( ControlInterface* controlInterface,
127 EditableControlInterface* editableControlInterface )
129 return ControllerPtr( new Controller( controlInterface,
130 editableControlInterface ) );
133 // public : Configure the text controller.
135 void Controller::EnableTextInput( DecoratorPtr decorator )
139 delete mImpl->mEventData;
140 mImpl->mEventData = NULL;
142 // Nothing else to do.
146 if( NULL == mImpl->mEventData )
148 mImpl->mEventData = new EventData( decorator );
152 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
154 // Metrics for bitmap & vector based glyphs are different
155 mImpl->mMetrics->SetGlyphType( glyphType );
157 // Clear the font-specific data
160 mImpl->RequestRelayout();
163 void Controller::SetMarkupProcessorEnabled( bool enable )
165 mImpl->mMarkupProcessorEnabled = enable;
168 bool Controller::IsMarkupProcessorEnabled() const
170 return mImpl->mMarkupProcessorEnabled;
173 void Controller::SetAutoScrollEnabled( bool enable )
175 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 );
177 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
181 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
182 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
192 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
193 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
200 mImpl->mIsAutoScrollEnabled = enable;
201 mImpl->RequestRelayout();
205 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
206 mImpl->mIsAutoScrollEnabled = false;
210 bool Controller::IsAutoScrollEnabled() const
212 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
214 return mImpl->mIsAutoScrollEnabled;
217 CharacterDirection Controller::GetAutoScrollDirection() const
219 return mImpl->mAutoScrollDirectionRTL;
222 float Controller::GetAutoScrollLineAlignment() const
226 if( mImpl->mModel->mVisualModel &&
227 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
229 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
235 void Controller::SetHorizontalScrollEnabled( bool enable )
237 if( ( NULL != mImpl->mEventData ) &&
238 mImpl->mEventData->mDecorator )
240 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
243 bool Controller::IsHorizontalScrollEnabled() const
245 if( ( NULL != mImpl->mEventData ) &&
246 mImpl->mEventData->mDecorator )
248 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
254 void Controller::SetVerticalScrollEnabled( bool enable )
256 if( ( NULL != mImpl->mEventData ) &&
257 mImpl->mEventData->mDecorator )
259 if( mImpl->mEventData->mDecorator )
261 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
266 bool Controller::IsVerticalScrollEnabled() const
268 if( ( NULL != mImpl->mEventData ) &&
269 mImpl->mEventData->mDecorator )
271 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
277 void Controller::SetSmoothHandlePanEnabled( bool enable )
279 if( ( NULL != mImpl->mEventData ) &&
280 mImpl->mEventData->mDecorator )
282 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
286 bool Controller::IsSmoothHandlePanEnabled() const
288 if( ( NULL != mImpl->mEventData ) &&
289 mImpl->mEventData->mDecorator )
291 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
297 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
299 mImpl->mMaximumNumberOfCharacters = maxCharacters;
302 int Controller::GetMaximumNumberOfCharacters()
304 return mImpl->mMaximumNumberOfCharacters;
307 void Controller::SetEnableCursorBlink( bool enable )
309 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
311 if( NULL != mImpl->mEventData )
313 mImpl->mEventData->mCursorBlinkEnabled = enable;
316 mImpl->mEventData->mDecorator )
318 mImpl->mEventData->mDecorator->StopCursorBlink();
323 bool Controller::GetEnableCursorBlink() const
325 if( NULL != mImpl->mEventData )
327 return mImpl->mEventData->mCursorBlinkEnabled;
333 void Controller::SetMultiLineEnabled( bool enable )
335 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
337 if( layout != mImpl->mLayoutEngine.GetLayout() )
339 // Set the layout type.
340 mImpl->mLayoutEngine.SetLayout( layout );
342 // Set the flags to redo the layout operations
343 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
348 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
350 mImpl->RequestRelayout();
354 bool Controller::IsMultiLineEnabled() const
356 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
359 void Controller::SetHorizontalAlignment( Layout::HorizontalAlignment alignment )
361 if( alignment != mImpl->mModel->mHorizontalAlignment )
363 // Set the alignment.
364 mImpl->mModel->mHorizontalAlignment = alignment;
366 // Set the flag to redo the alignment operation.
367 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
369 mImpl->RequestRelayout();
373 Layout::HorizontalAlignment Controller::GetHorizontalAlignment() const
375 return mImpl->mModel->mHorizontalAlignment;
378 void Controller::SetVerticalAlignment( Layout::VerticalAlignment alignment )
380 if( alignment != mImpl->mModel->mVerticalAlignment )
382 // Set the alignment.
383 mImpl->mModel->mVerticalAlignment = alignment;
385 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
387 mImpl->RequestRelayout();
391 Layout::VerticalAlignment Controller::GetVerticalAlignment() const
393 return mImpl->mModel->mVerticalAlignment;
396 void Controller::SetLineWrapMode( Layout::LineWrap::Mode lineWrapMode )
398 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
400 // Set the text wrap mode.
401 mImpl->mModel->mLineWrapMode = lineWrapMode;
404 // Update Text layout for applying wrap mode
405 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
410 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
411 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
412 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
415 mImpl->RequestRelayout();
419 Layout::LineWrap::Mode Controller::GetLineWrapMode() const
421 return mImpl->mModel->mLineWrapMode;
424 void Controller::SetTextElideEnabled( bool enabled )
426 mImpl->mModel->mElideEnabled = enabled;
429 bool Controller::IsTextElideEnabled() const
431 return mImpl->mModel->mElideEnabled;
434 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
436 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
437 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
439 // Update placeholder if there is no text
440 if( mImpl->IsShowingPlaceholderText() ||
441 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
443 ShowPlaceholderText();
447 bool Controller::IsPlaceholderTextElideEnabled() const
449 return mImpl->mEventData->mIsPlaceholderElideEnabled;
452 void Controller::SetSelectionEnabled( bool enabled )
454 mImpl->mEventData->mSelectionEnabled = enabled;
457 bool Controller::IsSelectionEnabled() const
459 return mImpl->mEventData->mSelectionEnabled;
464 void Controller::SetText( const std::string& text )
466 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
468 // Reset keyboard as text changed
469 mImpl->ResetImfManager();
471 // Remove the previously set text and style.
477 CharacterIndex lastCursorIndex = 0u;
479 if( NULL != mImpl->mEventData )
481 // If popup shown then hide it by switching to Editing state
482 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
483 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
484 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
485 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
487 mImpl->ChangeState( EventData::EDITING );
493 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
495 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
496 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
498 Length textSize = 0u;
499 const uint8_t* utf8 = NULL;
500 if( mImpl->mMarkupProcessorEnabled )
502 ProcessMarkupString( text, markupProcessData );
503 textSize = markupProcessData.markupProcessedText.size();
505 // This is a bit horrible but std::string returns a (signed) char*
506 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
510 textSize = text.size();
512 // This is a bit horrible but std::string returns a (signed) char*
513 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
516 // Convert text into UTF-32
517 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
518 utf32Characters.Resize( textSize );
520 // Transform a text array encoded in utf8 into an array encoded in utf32.
521 // It returns the actual number of characters.
522 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
523 utf32Characters.Resize( characterCount );
525 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
526 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
528 // The characters to be added.
529 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
531 // To reset the cursor position
532 lastCursorIndex = characterCount;
534 // Update the rest of the model during size negotiation
535 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
537 // The natural size needs to be re-calculated.
538 mImpl->mRecalculateNaturalSize = true;
540 // Apply modifications to the model
541 mImpl->mOperationsPending = ALL_OPERATIONS;
545 ShowPlaceholderText();
548 // Resets the cursor position.
549 ResetCursorPosition( lastCursorIndex );
551 // Scrolls the text to make the cursor visible.
552 ResetScrollPosition();
554 mImpl->RequestRelayout();
556 if( NULL != mImpl->mEventData )
558 // Cancel previously queued events
559 mImpl->mEventData->mEventQueue.clear();
562 // Do this last since it provides callbacks into application code.
563 if( NULL != mImpl->mEditableControlInterface )
565 mImpl->mEditableControlInterface->TextChanged();
569 void Controller::GetText( std::string& text ) const
571 if( !mImpl->IsShowingPlaceholderText() )
573 // Retrieves the text string.
574 mImpl->GetText( 0u, text );
578 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
582 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
584 if( NULL != mImpl->mEventData )
586 if( PLACEHOLDER_TYPE_INACTIVE == type )
588 mImpl->mEventData->mPlaceholderTextInactive = text;
592 mImpl->mEventData->mPlaceholderTextActive = text;
595 // Update placeholder if there is no text
596 if( mImpl->IsShowingPlaceholderText() ||
597 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
599 ShowPlaceholderText();
604 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
606 if( NULL != mImpl->mEventData )
608 if( PLACEHOLDER_TYPE_INACTIVE == type )
610 text = mImpl->mEventData->mPlaceholderTextInactive;
614 text = mImpl->mEventData->mPlaceholderTextActive;
619 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
621 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
623 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
625 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
626 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
630 mImpl->RequestRelayout();
634 // public : Default style & Input style
636 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
638 if( NULL == mImpl->mFontDefaults )
640 mImpl->mFontDefaults = new FontDefaults();
643 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
644 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
645 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
647 // Clear the font-specific data
650 mImpl->RequestRelayout();
653 const std::string& Controller::GetDefaultFontFamily() const
655 if( NULL != mImpl->mFontDefaults )
657 return mImpl->mFontDefaults->mFontDescription.family;
663 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
665 if( NULL != mImpl->mEventData )
667 if( NULL == mImpl->mEventData->mPlaceholderFont )
669 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
672 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
673 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
674 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
676 mImpl->RequestRelayout();
680 const std::string& Controller::GetPlaceholderFontFamily() const
682 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
684 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
690 void Controller::SetDefaultFontWeight( FontWeight weight )
692 if( NULL == mImpl->mFontDefaults )
694 mImpl->mFontDefaults = new FontDefaults();
697 mImpl->mFontDefaults->mFontDescription.weight = weight;
698 mImpl->mFontDefaults->weightDefined = true;
700 // Clear the font-specific data
703 mImpl->RequestRelayout();
706 bool Controller::IsDefaultFontWeightDefined() const
708 if( NULL != mImpl->mFontDefaults )
710 return mImpl->mFontDefaults->weightDefined;
716 FontWeight Controller::GetDefaultFontWeight() const
718 if( NULL != mImpl->mFontDefaults )
720 return mImpl->mFontDefaults->mFontDescription.weight;
723 return TextAbstraction::FontWeight::NORMAL;
726 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
728 if( NULL != mImpl->mEventData )
730 if( NULL == mImpl->mEventData->mPlaceholderFont )
732 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
735 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
736 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
738 mImpl->RequestRelayout();
742 bool Controller::IsPlaceholderTextFontWeightDefined() const
744 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
746 return mImpl->mEventData->mPlaceholderFont->weightDefined;
751 FontWeight Controller::GetPlaceholderTextFontWeight() const
753 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
755 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
758 return TextAbstraction::FontWeight::NORMAL;
761 void Controller::SetDefaultFontWidth( FontWidth width )
763 if( NULL == mImpl->mFontDefaults )
765 mImpl->mFontDefaults = new FontDefaults();
768 mImpl->mFontDefaults->mFontDescription.width = width;
769 mImpl->mFontDefaults->widthDefined = true;
771 // Clear the font-specific data
774 mImpl->RequestRelayout();
777 bool Controller::IsDefaultFontWidthDefined() const
779 if( NULL != mImpl->mFontDefaults )
781 return mImpl->mFontDefaults->widthDefined;
787 FontWidth Controller::GetDefaultFontWidth() const
789 if( NULL != mImpl->mFontDefaults )
791 return mImpl->mFontDefaults->mFontDescription.width;
794 return TextAbstraction::FontWidth::NORMAL;
797 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
799 if( NULL != mImpl->mEventData )
801 if( NULL == mImpl->mEventData->mPlaceholderFont )
803 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
806 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
807 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
809 mImpl->RequestRelayout();
813 bool Controller::IsPlaceholderTextFontWidthDefined() const
815 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
817 return mImpl->mEventData->mPlaceholderFont->widthDefined;
822 FontWidth Controller::GetPlaceholderTextFontWidth() const
824 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
826 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
829 return TextAbstraction::FontWidth::NORMAL;
832 void Controller::SetDefaultFontSlant( FontSlant slant )
834 if( NULL == mImpl->mFontDefaults )
836 mImpl->mFontDefaults = new FontDefaults();
839 mImpl->mFontDefaults->mFontDescription.slant = slant;
840 mImpl->mFontDefaults->slantDefined = true;
842 // Clear the font-specific data
845 mImpl->RequestRelayout();
848 bool Controller::IsDefaultFontSlantDefined() const
850 if( NULL != mImpl->mFontDefaults )
852 return mImpl->mFontDefaults->slantDefined;
857 FontSlant Controller::GetDefaultFontSlant() const
859 if( NULL != mImpl->mFontDefaults )
861 return mImpl->mFontDefaults->mFontDescription.slant;
864 return TextAbstraction::FontSlant::NORMAL;
867 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
869 if( NULL != mImpl->mEventData )
871 if( NULL == mImpl->mEventData->mPlaceholderFont )
873 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
876 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
877 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
879 mImpl->RequestRelayout();
883 bool Controller::IsPlaceholderTextFontSlantDefined() const
885 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
887 return mImpl->mEventData->mPlaceholderFont->slantDefined;
892 FontSlant Controller::GetPlaceholderTextFontSlant() const
894 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
896 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
899 return TextAbstraction::FontSlant::NORMAL;
902 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
904 if( NULL == mImpl->mFontDefaults )
906 mImpl->mFontDefaults = new FontDefaults();
913 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
914 mImpl->mFontDefaults->sizeDefined = true;
919 // Point size = Pixel size * 72.f / DPI
920 unsigned int horizontalDpi = 0u;
921 unsigned int verticalDpi = 0u;
922 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
923 fontClient.GetDpi( horizontalDpi, verticalDpi );
925 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
926 mImpl->mFontDefaults->sizeDefined = true;
931 // Clear the font-specific data
934 mImpl->RequestRelayout();
937 float Controller::GetDefaultFontSize( FontSizeType type ) const
940 if( NULL != mImpl->mFontDefaults )
946 value = mImpl->mFontDefaults->mDefaultPointSize;
951 // Pixel size = Point size * DPI / 72.f
952 unsigned int horizontalDpi = 0u;
953 unsigned int verticalDpi = 0u;
954 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
955 fontClient.GetDpi( horizontalDpi, verticalDpi );
957 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
967 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
969 if( NULL != mImpl->mEventData )
971 if( NULL == mImpl->mEventData->mPlaceholderFont )
973 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
980 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
981 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
982 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
987 // Point size = Pixel size * 72.f / DPI
988 unsigned int horizontalDpi = 0u;
989 unsigned int verticalDpi = 0u;
990 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
991 fontClient.GetDpi( horizontalDpi, verticalDpi );
993 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
994 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
995 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1000 mImpl->RequestRelayout();
1004 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1007 if( NULL != mImpl->mEventData )
1013 if( NULL != mImpl->mEventData->mPlaceholderFont )
1015 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1019 // If the placeholder text font size is not set, then return the default font size.
1020 value = GetDefaultFontSize( POINT_SIZE );
1026 if( NULL != mImpl->mEventData->mPlaceholderFont )
1028 // Pixel size = Point size * DPI / 72.f
1029 unsigned int horizontalDpi = 0u;
1030 unsigned int verticalDpi = 0u;
1031 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1032 fontClient.GetDpi( horizontalDpi, verticalDpi );
1034 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1038 // If the placeholder text font size is not set, then return the default font size.
1039 value = GetDefaultFontSize( PIXEL_SIZE );
1050 void Controller::SetDefaultColor( const Vector4& color )
1052 mImpl->mTextColor = color;
1054 if( !mImpl->IsShowingPlaceholderText() )
1056 mImpl->mModel->mVisualModel->SetTextColor( color );
1058 mImpl->RequestRelayout();
1062 const Vector4& Controller::GetDefaultColor() const
1064 return mImpl->mTextColor;
1067 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1069 if( NULL != mImpl->mEventData )
1071 mImpl->mEventData->mPlaceholderTextColor = textColor;
1074 if( mImpl->IsShowingPlaceholderText() )
1076 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1077 mImpl->RequestRelayout();
1081 const Vector4& Controller::GetPlaceholderTextColor() const
1083 if( NULL != mImpl->mEventData )
1085 return mImpl->mEventData->mPlaceholderTextColor;
1088 return Color::BLACK;
1091 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1093 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1095 mImpl->RequestRelayout();
1098 const Vector2& Controller::GetShadowOffset() const
1100 return mImpl->mModel->mVisualModel->GetShadowOffset();
1103 void Controller::SetShadowColor( const Vector4& shadowColor )
1105 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1107 mImpl->RequestRelayout();
1110 const Vector4& Controller::GetShadowColor() const
1112 return mImpl->mModel->mVisualModel->GetShadowColor();
1115 void Controller::SetUnderlineColor( const Vector4& color )
1117 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1119 mImpl->RequestRelayout();
1122 const Vector4& Controller::GetUnderlineColor() const
1124 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1127 void Controller::SetUnderlineEnabled( bool enabled )
1129 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1131 mImpl->RequestRelayout();
1134 bool Controller::IsUnderlineEnabled() const
1136 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1139 void Controller::SetUnderlineHeight( float height )
1141 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1143 mImpl->RequestRelayout();
1146 float Controller::GetUnderlineHeight() const
1148 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1151 void Controller::SetOutlineColor( const Vector4& color )
1153 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1155 mImpl->RequestRelayout();
1158 const Vector4& Controller::GetOutlineColor() const
1160 return mImpl->mModel->mVisualModel->GetOutlineColor();
1163 void Controller::SetOutlineWidth( float width )
1165 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1167 mImpl->RequestRelayout();
1170 float Controller::GetOutlineWidth() const
1172 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1175 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1177 if( NULL == mImpl->mEmbossDefaults )
1179 mImpl->mEmbossDefaults = new EmbossDefaults();
1182 mImpl->mEmbossDefaults->properties = embossProperties;
1185 const std::string& Controller::GetDefaultEmbossProperties() const
1187 if( NULL != mImpl->mEmbossDefaults )
1189 return mImpl->mEmbossDefaults->properties;
1192 return EMPTY_STRING;
1195 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1197 if( NULL == mImpl->mOutlineDefaults )
1199 mImpl->mOutlineDefaults = new OutlineDefaults();
1202 mImpl->mOutlineDefaults->properties = outlineProperties;
1205 const std::string& Controller::GetDefaultOutlineProperties() const
1207 if( NULL != mImpl->mOutlineDefaults )
1209 return mImpl->mOutlineDefaults->properties;
1212 return EMPTY_STRING;
1215 void Controller::SetDefaultLineSpacing( float lineSpacing )
1217 //TODO finish implementation
1218 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1221 float Controller::GetDefaultLineSpacing() const
1223 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1226 void Controller::SetInputColor( const Vector4& color )
1228 if( NULL != mImpl->mEventData )
1230 mImpl->mEventData->mInputStyle.textColor = color;
1231 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1233 if( EventData::SELECTING == mImpl->mEventData->mState )
1235 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1237 // Get start and end position of selection
1238 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1239 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1241 // Add the color run.
1242 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1243 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1245 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1246 colorRun.color = color;
1247 colorRun.characterRun.characterIndex = startOfSelectedText;
1248 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1250 // Request to relayout.
1251 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1252 mImpl->RequestRelayout();
1254 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1255 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1256 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1261 const Vector4& Controller::GetInputColor() const
1263 if( NULL != mImpl->mEventData )
1265 return mImpl->mEventData->mInputStyle.textColor;
1268 // Return the default text's color if there is no EventData.
1269 return mImpl->mTextColor;
1273 void Controller::SetInputFontFamily( const std::string& fontFamily )
1275 if( NULL != mImpl->mEventData )
1277 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1278 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1280 if( EventData::SELECTING == mImpl->mEventData->mState )
1282 CharacterIndex startOfSelectedText = 0u;
1283 Length lengthOfSelectedText = 0u;
1284 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1285 mImpl->mModel->mLogicalModel,
1286 startOfSelectedText,
1287 lengthOfSelectedText );
1289 fontDescriptionRun.familyLength = fontFamily.size();
1290 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1291 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1292 fontDescriptionRun.familyDefined = true;
1294 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1296 // Request to relayout.
1297 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1302 UPDATE_LAYOUT_SIZE |
1305 mImpl->mRecalculateNaturalSize = true;
1306 mImpl->RequestRelayout();
1308 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1309 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1310 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1312 // As the font changes, recalculate the handle positions is needed.
1313 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1314 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1315 mImpl->mEventData->mUpdateHighlightBox = true;
1316 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1321 const std::string& Controller::GetInputFontFamily() const
1323 if( NULL != mImpl->mEventData )
1325 return mImpl->mEventData->mInputStyle.familyName;
1328 // Return the default font's family if there is no EventData.
1329 return GetDefaultFontFamily();
1332 void Controller::SetInputFontWeight( FontWeight weight )
1334 if( NULL != mImpl->mEventData )
1336 mImpl->mEventData->mInputStyle.weight = weight;
1337 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1339 if( EventData::SELECTING == mImpl->mEventData->mState )
1341 CharacterIndex startOfSelectedText = 0u;
1342 Length lengthOfSelectedText = 0u;
1343 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1344 mImpl->mModel->mLogicalModel,
1345 startOfSelectedText,
1346 lengthOfSelectedText );
1348 fontDescriptionRun.weight = weight;
1349 fontDescriptionRun.weightDefined = true;
1351 // Request to relayout.
1352 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1357 UPDATE_LAYOUT_SIZE |
1360 mImpl->mRecalculateNaturalSize = true;
1361 mImpl->RequestRelayout();
1363 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1364 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1365 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1367 // As the font might change, recalculate the handle positions is needed.
1368 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1369 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1370 mImpl->mEventData->mUpdateHighlightBox = true;
1371 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1376 bool Controller::IsInputFontWeightDefined() const
1378 bool defined = false;
1380 if( NULL != mImpl->mEventData )
1382 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1388 FontWeight Controller::GetInputFontWeight() const
1390 if( NULL != mImpl->mEventData )
1392 return mImpl->mEventData->mInputStyle.weight;
1395 return GetDefaultFontWeight();
1398 void Controller::SetInputFontWidth( FontWidth width )
1400 if( NULL != mImpl->mEventData )
1402 mImpl->mEventData->mInputStyle.width = width;
1403 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1405 if( EventData::SELECTING == mImpl->mEventData->mState )
1407 CharacterIndex startOfSelectedText = 0u;
1408 Length lengthOfSelectedText = 0u;
1409 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1410 mImpl->mModel->mLogicalModel,
1411 startOfSelectedText,
1412 lengthOfSelectedText );
1414 fontDescriptionRun.width = width;
1415 fontDescriptionRun.widthDefined = true;
1417 // Request to relayout.
1418 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1423 UPDATE_LAYOUT_SIZE |
1426 mImpl->mRecalculateNaturalSize = true;
1427 mImpl->RequestRelayout();
1429 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1430 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1431 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1433 // As the font might change, recalculate the handle positions is needed.
1434 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1435 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1436 mImpl->mEventData->mUpdateHighlightBox = true;
1437 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1442 bool Controller::IsInputFontWidthDefined() const
1444 bool defined = false;
1446 if( NULL != mImpl->mEventData )
1448 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1454 FontWidth Controller::GetInputFontWidth() const
1456 if( NULL != mImpl->mEventData )
1458 return mImpl->mEventData->mInputStyle.width;
1461 return GetDefaultFontWidth();
1464 void Controller::SetInputFontSlant( FontSlant slant )
1466 if( NULL != mImpl->mEventData )
1468 mImpl->mEventData->mInputStyle.slant = slant;
1469 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1471 if( EventData::SELECTING == mImpl->mEventData->mState )
1473 CharacterIndex startOfSelectedText = 0u;
1474 Length lengthOfSelectedText = 0u;
1475 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1476 mImpl->mModel->mLogicalModel,
1477 startOfSelectedText,
1478 lengthOfSelectedText );
1480 fontDescriptionRun.slant = slant;
1481 fontDescriptionRun.slantDefined = true;
1483 // Request to relayout.
1484 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1489 UPDATE_LAYOUT_SIZE |
1492 mImpl->mRecalculateNaturalSize = true;
1493 mImpl->RequestRelayout();
1495 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1496 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1497 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1499 // As the font might change, recalculate the handle positions is needed.
1500 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1501 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1502 mImpl->mEventData->mUpdateHighlightBox = true;
1503 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1508 bool Controller::IsInputFontSlantDefined() const
1510 bool defined = false;
1512 if( NULL != mImpl->mEventData )
1514 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1520 FontSlant Controller::GetInputFontSlant() const
1522 if( NULL != mImpl->mEventData )
1524 return mImpl->mEventData->mInputStyle.slant;
1527 return GetDefaultFontSlant();
1530 void Controller::SetInputFontPointSize( float size )
1532 if( NULL != mImpl->mEventData )
1534 mImpl->mEventData->mInputStyle.size = size;
1535 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1537 if( EventData::SELECTING == mImpl->mEventData->mState )
1539 CharacterIndex startOfSelectedText = 0u;
1540 Length lengthOfSelectedText = 0u;
1541 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1542 mImpl->mModel->mLogicalModel,
1543 startOfSelectedText,
1544 lengthOfSelectedText );
1546 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1547 fontDescriptionRun.sizeDefined = true;
1549 // Request to relayout.
1550 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1555 UPDATE_LAYOUT_SIZE |
1558 mImpl->mRecalculateNaturalSize = true;
1559 mImpl->RequestRelayout();
1561 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1562 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1563 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1565 // As the font might change, recalculate the handle positions is needed.
1566 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1567 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1568 mImpl->mEventData->mUpdateHighlightBox = true;
1569 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1574 float Controller::GetInputFontPointSize() const
1576 if( NULL != mImpl->mEventData )
1578 return mImpl->mEventData->mInputStyle.size;
1581 // Return the default font's point size if there is no EventData.
1582 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1585 void Controller::SetInputLineSpacing( float lineSpacing )
1587 if( NULL != mImpl->mEventData )
1589 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1590 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1594 float Controller::GetInputLineSpacing() const
1596 if( NULL != mImpl->mEventData )
1598 return mImpl->mEventData->mInputStyle.lineSpacing;
1604 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1606 if( NULL != mImpl->mEventData )
1608 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1612 const std::string& Controller::GetInputShadowProperties() const
1614 if( NULL != mImpl->mEventData )
1616 return mImpl->mEventData->mInputStyle.shadowProperties;
1619 return EMPTY_STRING;
1622 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1624 if( NULL != mImpl->mEventData )
1626 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1630 const std::string& Controller::GetInputUnderlineProperties() const
1632 if( NULL != mImpl->mEventData )
1634 return mImpl->mEventData->mInputStyle.underlineProperties;
1637 return EMPTY_STRING;
1640 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1642 if( NULL != mImpl->mEventData )
1644 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1648 const std::string& Controller::GetInputEmbossProperties() const
1650 if( NULL != mImpl->mEventData )
1652 return mImpl->mEventData->mInputStyle.embossProperties;
1655 return GetDefaultEmbossProperties();
1658 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1660 if( NULL != mImpl->mEventData )
1662 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1666 const std::string& Controller::GetInputOutlineProperties() const
1668 if( NULL != mImpl->mEventData )
1670 return mImpl->mEventData->mInputStyle.outlineProperties;
1673 return GetDefaultOutlineProperties();
1676 void Controller::SetInputModePassword( bool passwordInput )
1678 if( NULL != mImpl->mEventData )
1680 mImpl->mEventData->mPasswordInput = passwordInput;
1684 bool Controller::IsInputModePassword()
1686 if( NULL != mImpl->mEventData )
1688 return mImpl->mEventData->mPasswordInput;
1693 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1695 if( NULL != mImpl->mEventData )
1697 mImpl->mEventData->mDoubleTapAction = action;
1701 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1703 NoTextTap::Action action = NoTextTap::NO_ACTION;
1705 if( NULL != mImpl->mEventData )
1707 action = mImpl->mEventData->mDoubleTapAction;
1713 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1715 if( NULL != mImpl->mEventData )
1717 mImpl->mEventData->mLongPressAction = action;
1721 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1723 NoTextTap::Action action = NoTextTap::NO_ACTION;
1725 if( NULL != mImpl->mEventData )
1727 action = mImpl->mEventData->mLongPressAction;
1733 bool Controller::IsUnderlineSetByString()
1735 return mImpl->mUnderlineSetByString;
1738 void Controller::UnderlineSetByString( bool setByString )
1740 mImpl->mUnderlineSetByString = setByString;
1743 bool Controller::IsShadowSetByString()
1745 return mImpl->mShadowSetByString;
1748 void Controller::ShadowSetByString( bool setByString )
1750 mImpl->mShadowSetByString = setByString;
1753 bool Controller::IsFontStyleSetByString()
1755 return mImpl->mFontStyleSetByString;
1758 void Controller::FontStyleSetByString( bool setByString )
1760 mImpl->mFontStyleSetByString = setByString;
1763 // public : Queries & retrieves.
1765 Layout::Engine& Controller::GetLayoutEngine()
1767 return mImpl->mLayoutEngine;
1770 View& Controller::GetView()
1772 return mImpl->mView;
1775 Vector3 Controller::GetNaturalSize()
1777 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1778 Vector3 naturalSize;
1780 // Make sure the model is up-to-date before layouting
1781 ProcessModifyEvents();
1783 if( mImpl->mRecalculateNaturalSize )
1785 // Operations that can be done only once until the text changes.
1786 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1793 GET_GLYPH_METRICS );
1795 // Set the update info to relayout the whole text.
1796 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1797 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1799 // Make sure the model is up-to-date before layouting
1800 mImpl->UpdateModel( onlyOnceOperations );
1802 // Layout the text for the new width.
1803 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1805 // Store the actual control's size to restore later.
1806 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1808 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1809 static_cast<OperationsMask>( onlyOnceOperations |
1811 naturalSize.GetVectorXY() );
1813 // Do not do again the only once operations.
1814 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1816 // Do the size related operations again.
1817 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1820 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1822 // Stores the natural size to avoid recalculate it again
1823 // unless the text/style changes.
1824 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1826 mImpl->mRecalculateNaturalSize = false;
1828 // Clear the update info. This info will be set the next time the text is updated.
1829 mImpl->mTextUpdateInfo.Clear();
1831 // Restore the actual control's size.
1832 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1834 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1838 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1840 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1843 naturalSize.x = ConvertToEven( naturalSize.x );
1844 naturalSize.y = ConvertToEven( naturalSize.y );
1849 float Controller::GetHeightForWidth( float width )
1851 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1852 // Make sure the model is up-to-date before layouting
1853 ProcessModifyEvents();
1856 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1857 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1858 mImpl->mTextUpdateInfo.mClearAll )
1860 // Operations that can be done only once until the text changes.
1861 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1868 GET_GLYPH_METRICS );
1870 // Set the update info to relayout the whole text.
1871 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1872 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1874 // Make sure the model is up-to-date before layouting
1875 mImpl->UpdateModel( onlyOnceOperations );
1878 // Layout the text for the new width.
1879 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1881 // Store the actual control's width.
1882 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1884 DoRelayout( Size( width, MAX_FLOAT ),
1885 static_cast<OperationsMask>( onlyOnceOperations |
1889 // Do not do again the only once operations.
1890 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1892 // Do the size related operations again.
1893 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1897 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1899 // Clear the update info. This info will be set the next time the text is updated.
1900 mImpl->mTextUpdateInfo.Clear();
1902 // Restore the actual control's width.
1903 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1905 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1909 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1910 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1913 return layoutSize.height;
1916 int Controller::GetLineCount( float width )
1918 GetHeightForWidth( width );
1919 int numberofLines = mImpl->mModel->GetNumberOfLines();
1920 return numberofLines;
1923 const ModelInterface* const Controller::GetTextModel() const
1925 return mImpl->mModel.Get();
1928 float Controller::GetScrollAmountByUserInput()
1930 float scrollAmount = 0.0f;
1932 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1934 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1935 mImpl->mEventData->mCheckScrollAmount = false;
1937 return scrollAmount;
1940 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1942 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1945 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1946 layoutHeight = layout.height;
1947 scrollPosition = mImpl->mModel->mScrollPosition.y;
1948 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1952 void Controller::SetHiddenInputOption(const Property::Map& options )
1954 if( NULL == mImpl->mHiddenInput )
1956 mImpl->mHiddenInput = new HiddenText( this );
1958 mImpl->mHiddenInput->SetProperties(options);
1961 void Controller::GetHiddenInputOption(Property::Map& options )
1963 if( NULL != mImpl->mHiddenInput )
1965 mImpl->mHiddenInput->GetProperties(options);
1969 void Controller::SetPlaceholderProperty( const Property::Map& map )
1971 const Property::Map::SizeType count = map.Count();
1973 for( Property::Map::SizeType position = 0; position < count; ++position )
1975 KeyValuePair keyValue = map.GetKeyValue( position );
1976 Property::Key& key = keyValue.first;
1977 Property::Value& value = keyValue.second;
1979 if( key == PLACEHOLDER_TEXT )
1981 std::string text = "";
1983 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
1985 else if( key == PLACEHOLDER_TEXT_FOCUSED )
1987 std::string text = "";
1989 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
1991 else if( key == PLACEHOLDER_COLOR )
1994 value.Get( textColor );
1995 if( GetPlaceholderTextColor() != textColor )
1997 SetPlaceholderTextColor( textColor );
2000 else if( key == PLACEHOLDER_FONT_FAMILY )
2002 std::string fontFamily = "";
2003 value.Get( fontFamily );
2004 SetPlaceholderFontFamily( fontFamily );
2006 else if( key == PLACEHOLDER_FONT_STYLE )
2008 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2010 else if( key == PLACEHOLDER_POINT_SIZE )
2013 value.Get( pointSize );
2014 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2016 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2019 else if( key == PLACEHOLDER_PIXEL_SIZE )
2022 value.Get( pixelSize );
2023 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2025 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2028 else if( key == PLACEHOLDER_ELLIPSIS )
2031 value.Get( ellipsis );
2032 SetPlaceholderTextElideEnabled( ellipsis );
2037 void Controller::GetPlaceholderProperty( Property::Map& map )
2039 if( NULL != mImpl->mEventData )
2041 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2043 map[ PLACEHOLDER_TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2045 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2047 map[ PLACEHOLDER_TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2050 map[ PLACEHOLDER_COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2051 map[ PLACEHOLDER_FONT_FAMILY ] = GetPlaceholderFontFamily();
2053 Property::Value fontStyleMapGet;
2054 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2055 map[ PLACEHOLDER_FONT_STYLE ] = fontStyleMapGet;
2057 // Choose font size : POINT_SIZE or PIXEL_SIZE
2058 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2060 map[ PLACEHOLDER_POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2064 map[ PLACEHOLDER_PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2067 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2069 map[ PLACEHOLDER_ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2074 // public : Relayout.
2076 Controller::UpdateTextType Controller::Relayout( const Size& size )
2078 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2080 UpdateTextType updateTextType = NONE_UPDATED;
2082 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2084 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2086 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2087 updateTextType = MODEL_UPDATED;
2090 // Clear the update info. This info will be set the next time the text is updated.
2091 mImpl->mTextUpdateInfo.Clear();
2093 // Not worth to relayout if width or height is equal to zero.
2094 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2096 return updateTextType;
2099 // Whether a new size has been set.
2100 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2104 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2106 // Layout operations that need to be done if the size changes.
2107 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2110 UPDATE_LAYOUT_SIZE |
2112 // Set the update info to relayout the whole text.
2113 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2114 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2116 // Store the size used to layout the text.
2117 mImpl->mModel->mVisualModel->mControlSize = size;
2120 // Whether there are modify events.
2121 if( 0u != mImpl->mModifyEvents.Count() )
2123 // Style operations that need to be done if the text is modified.
2124 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2128 // Set the update info to elide the text.
2129 if( mImpl->mModel->mElideEnabled ||
2130 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2132 // Update Text layout for applying elided
2133 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2136 UPDATE_LAYOUT_SIZE |
2138 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2139 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2142 // Make sure the model is up-to-date before layouting.
2143 ProcessModifyEvents();
2144 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2148 updated = DoRelayout( size,
2149 mImpl->mOperationsPending,
2150 layoutSize ) || updated;
2154 updateTextType = MODEL_UPDATED;
2157 // Do not re-do any operation until something changes.
2158 mImpl->mOperationsPending = NO_OPERATION;
2159 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2161 // Whether the text control is editable
2162 const bool isEditable = NULL != mImpl->mEventData;
2164 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2166 if( newSize && isEditable )
2168 offset = mImpl->mModel->mScrollPosition;
2171 if( !isEditable || !IsMultiLineEnabled() )
2173 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2174 CalculateVerticalOffset( size );
2181 // If there is a new size, the scroll position needs to be clamped.
2182 mImpl->ClampHorizontalScroll( layoutSize );
2184 // Update the decorator's positions is needed if there is a new size.
2185 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2188 // Move the cursor, grab handle etc.
2189 if( mImpl->ProcessInputEvents() )
2191 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2195 // Clear the update info. This info will be set the next time the text is updated.
2196 mImpl->mTextUpdateInfo.Clear();
2197 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2199 return updateTextType;
2202 void Controller::RequestRelayout()
2204 mImpl->RequestRelayout();
2207 // public : Input style change signals.
2209 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2211 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2214 void Controller::ProcessInputStyleChangedSignals()
2216 if( NULL == mImpl->mEventData )
2222 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2223 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2227 const InputStyle::Mask mask = *it;
2229 if( NULL != mImpl->mEditableControlInterface )
2231 // Emit the input style changed signal.
2232 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2236 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2239 // public : Text-input Event Queuing.
2241 void Controller::KeyboardFocusGainEvent()
2243 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2245 if( NULL != mImpl->mEventData )
2247 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2248 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2250 mImpl->ChangeState( EventData::EDITING );
2251 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2252 mImpl->mEventData->mUpdateInputStyle = true;
2254 mImpl->NotifyImfMultiLineStatus();
2255 if( mImpl->IsShowingPlaceholderText() )
2257 // Show alternative placeholder-text when editing
2258 ShowPlaceholderText();
2261 mImpl->RequestRelayout();
2265 void Controller::KeyboardFocusLostEvent()
2267 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2269 if( NULL != mImpl->mEventData )
2271 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2273 mImpl->ChangeState( EventData::INACTIVE );
2275 if( !mImpl->IsShowingRealText() )
2277 // Revert to regular placeholder-text when not editing
2278 ShowPlaceholderText();
2282 mImpl->RequestRelayout();
2285 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2287 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2289 bool textChanged = false;
2290 bool relayoutNeeded = false;
2292 if( ( NULL != mImpl->mEventData ) &&
2293 ( keyEvent.state == KeyEvent::Down ) )
2295 int keyCode = keyEvent.keyCode;
2296 const std::string& keyString = keyEvent.keyPressed;
2298 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2300 // Pre-process to separate modifying events from non-modifying input events.
2303 // In some platforms arrive key events with no key code.
2307 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode )
2312 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2313 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2314 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2315 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2317 // If don't have any text, do nothing.
2318 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2323 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2324 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2325 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2326 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2328 // Logic to determine whether this text control will lose focus or not.
2329 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2330 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2331 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2332 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2333 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2334 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2339 mImpl->mEventData->mCheckScrollAmount = true;
2340 Event event( Event::CURSOR_KEY_EVENT );
2341 event.p1.mInt = keyCode;
2342 mImpl->mEventData->mEventQueue.push_back( event );
2344 // Will request for relayout.
2345 relayoutNeeded = true;
2347 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
2349 textChanged = BackspaceKeyEvent();
2351 // Will request for relayout.
2352 relayoutNeeded = true;
2354 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2355 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2356 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2358 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2359 mImpl->ChangeState( EventData::INACTIVE );
2361 // Will request for relayout.
2362 relayoutNeeded = true;
2364 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2366 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2368 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2369 // and a character is typed after the type of a upper case latin character.
2374 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2376 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2382 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2384 // IMF manager is no longer handling key-events
2385 mImpl->ClearPreEditFlag();
2387 InsertText( keyString, COMMIT );
2390 // Will request for relayout.
2391 relayoutNeeded = true;
2394 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2395 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2397 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2398 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2399 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2401 // Should not change the state if the key is the shift send by the imf manager.
2402 // Otherwise, when the state is SELECTING the text controller can't send the right
2403 // surrounding info to the imf.
2404 mImpl->ChangeState( EventData::EDITING );
2406 // Will request for relayout.
2407 relayoutNeeded = true;
2410 if( relayoutNeeded )
2412 mImpl->RequestRelayout();
2417 ( NULL != mImpl->mEditableControlInterface ) )
2419 // Do this last since it provides callbacks into application code
2420 mImpl->mEditableControlInterface->TextChanged();
2426 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2428 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2430 if( NULL != mImpl->mEventData )
2432 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2433 EventData::State state( mImpl->mEventData->mState );
2434 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2436 if( mImpl->IsClipboardVisible() )
2438 if( EventData::INACTIVE == state || EventData::EDITING == state)
2440 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2442 relayoutNeeded = true;
2444 else if( 1u == tapCount )
2446 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2448 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2451 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2453 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2454 relayoutNeeded = true;
2458 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2460 // Hide placeholder text
2464 if( EventData::INACTIVE == state )
2466 mImpl->ChangeState( EventData::EDITING );
2468 else if( !mImpl->IsClipboardEmpty() )
2470 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2472 relayoutNeeded = true;
2475 else if( 2u == tapCount )
2477 if( mImpl->mEventData->mSelectionEnabled &&
2478 mImpl->IsShowingRealText() )
2480 relayoutNeeded = true;
2481 mImpl->mEventData->mIsLeftHandleSelected = true;
2482 mImpl->mEventData->mIsRightHandleSelected = true;
2486 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2487 if( relayoutNeeded )
2489 Event event( Event::TAP_EVENT );
2490 event.p1.mUint = tapCount;
2491 event.p2.mFloat = x;
2492 event.p3.mFloat = y;
2493 mImpl->mEventData->mEventQueue.push_back( event );
2495 mImpl->RequestRelayout();
2499 // Reset keyboard as tap event has occurred.
2500 mImpl->ResetImfManager();
2503 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2505 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2507 if( NULL != mImpl->mEventData )
2509 Event event( Event::PAN_EVENT );
2510 event.p1.mInt = state;
2511 event.p2.mFloat = displacement.x;
2512 event.p3.mFloat = displacement.y;
2513 mImpl->mEventData->mEventQueue.push_back( event );
2515 mImpl->RequestRelayout();
2519 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2521 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2523 if( ( state == Gesture::Started ) &&
2524 ( NULL != mImpl->mEventData ) )
2526 // The 1st long-press on inactive text-field is treated as tap
2527 if( EventData::INACTIVE == mImpl->mEventData->mState )
2529 mImpl->ChangeState( EventData::EDITING );
2531 Event event( Event::TAP_EVENT );
2533 event.p2.mFloat = x;
2534 event.p3.mFloat = y;
2535 mImpl->mEventData->mEventQueue.push_back( event );
2537 mImpl->RequestRelayout();
2539 else if( !mImpl->IsShowingRealText() )
2541 Event event( Event::LONG_PRESS_EVENT );
2542 event.p1.mInt = state;
2543 event.p2.mFloat = x;
2544 event.p3.mFloat = y;
2545 mImpl->mEventData->mEventQueue.push_back( event );
2546 mImpl->RequestRelayout();
2548 else if( !mImpl->IsClipboardVisible() )
2550 // Reset the imf manager to commit the pre-edit before selecting the text.
2551 mImpl->ResetImfManager();
2553 Event event( Event::LONG_PRESS_EVENT );
2554 event.p1.mInt = state;
2555 event.p2.mFloat = x;
2556 event.p3.mFloat = y;
2557 mImpl->mEventData->mEventQueue.push_back( event );
2558 mImpl->RequestRelayout();
2560 mImpl->mEventData->mIsLeftHandleSelected = true;
2561 mImpl->mEventData->mIsRightHandleSelected = true;
2566 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2568 // Whether the text needs to be relaid-out.
2569 bool requestRelayout = false;
2571 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2572 bool retrieveText = false;
2573 bool retrieveCursor = false;
2575 switch( imfEvent.eventName )
2577 case ImfManager::COMMIT:
2579 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2580 requestRelayout = true;
2581 retrieveCursor = true;
2584 case ImfManager::PREEDIT:
2586 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2587 requestRelayout = true;
2588 retrieveCursor = true;
2591 case ImfManager::DELETESURROUNDING:
2593 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2594 imfEvent.numberOfChars,
2595 DONT_UPDATE_INPUT_STYLE );
2599 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2600 !mImpl->IsPlaceholderAvailable() )
2602 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2606 ShowPlaceholderText();
2608 mImpl->mEventData->mUpdateCursorPosition = true;
2609 mImpl->mEventData->mScrollAfterDelete = true;
2611 requestRelayout = true;
2615 case ImfManager::GETSURROUNDING:
2617 retrieveText = true;
2618 retrieveCursor = true;
2621 case ImfManager::PRIVATECOMMAND:
2623 // PRIVATECOMMAND event is just for getting the private command message
2624 retrieveText = true;
2625 retrieveCursor = true;
2628 case ImfManager::VOID:
2635 if( requestRelayout )
2637 mImpl->mOperationsPending = ALL_OPERATIONS;
2638 mImpl->RequestRelayout();
2642 CharacterIndex cursorPosition = 0u;
2643 Length numberOfWhiteSpaces = 0u;
2645 if( retrieveCursor )
2647 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2649 cursorPosition = mImpl->GetLogicalCursorPosition();
2651 if( cursorPosition < numberOfWhiteSpaces )
2653 cursorPosition = 0u;
2657 cursorPosition -= numberOfWhiteSpaces;
2663 mImpl->GetText( numberOfWhiteSpaces, text );
2666 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2668 if( requestRelayout &&
2669 ( NULL != mImpl->mEditableControlInterface ) )
2671 // Do this last since it provides callbacks into application code
2672 mImpl->mEditableControlInterface->TextChanged();
2675 return callbackData;
2678 void Controller::PasteClipboardItemEvent()
2680 // Retrieve the clipboard contents first
2681 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2682 std::string stringToPaste( notifier.GetContent() );
2684 // Commit the current pre-edit text; the contents of the clipboard should be appended
2685 mImpl->ResetImfManager();
2687 // Temporary disable hiding clipboard
2688 mImpl->SetClipboardHideEnable( false );
2691 PasteText( stringToPaste );
2693 mImpl->SetClipboardHideEnable( true );
2696 // protected : Inherit from Text::Decorator::ControllerInterface.
2698 void Controller::GetTargetSize( Vector2& targetSize )
2700 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2703 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2705 if( NULL != mImpl->mEditableControlInterface )
2707 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2711 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2713 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2715 if( NULL != mImpl->mEventData )
2717 switch( handleType )
2721 Event event( Event::GRAB_HANDLE_EVENT );
2722 event.p1.mUint = state;
2723 event.p2.mFloat = x;
2724 event.p3.mFloat = y;
2726 mImpl->mEventData->mEventQueue.push_back( event );
2729 case LEFT_SELECTION_HANDLE:
2731 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2732 event.p1.mUint = state;
2733 event.p2.mFloat = x;
2734 event.p3.mFloat = y;
2736 mImpl->mEventData->mEventQueue.push_back( event );
2739 case RIGHT_SELECTION_HANDLE:
2741 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2742 event.p1.mUint = state;
2743 event.p2.mFloat = x;
2744 event.p3.mFloat = y;
2746 mImpl->mEventData->mEventQueue.push_back( event );
2749 case LEFT_SELECTION_HANDLE_MARKER:
2750 case RIGHT_SELECTION_HANDLE_MARKER:
2752 // Markers do not move the handles.
2755 case HANDLE_TYPE_COUNT:
2757 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2761 mImpl->RequestRelayout();
2765 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2767 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2769 if( NULL == mImpl->mEventData )
2776 case Toolkit::TextSelectionPopup::CUT:
2778 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2779 mImpl->mOperationsPending = ALL_OPERATIONS;
2781 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2782 !mImpl->IsPlaceholderAvailable() )
2784 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2788 ShowPlaceholderText();
2791 mImpl->mEventData->mUpdateCursorPosition = true;
2792 mImpl->mEventData->mScrollAfterDelete = true;
2794 mImpl->RequestRelayout();
2796 if( NULL != mImpl->mEditableControlInterface )
2798 mImpl->mEditableControlInterface->TextChanged();
2802 case Toolkit::TextSelectionPopup::COPY:
2804 mImpl->SendSelectionToClipboard( false ); // Text not modified
2806 mImpl->mEventData->mUpdateCursorPosition = true;
2808 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2811 case Toolkit::TextSelectionPopup::PASTE:
2813 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2816 case Toolkit::TextSelectionPopup::SELECT:
2818 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2820 if( mImpl->mEventData->mSelectionEnabled )
2822 // Creates a SELECT event.
2823 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2827 case Toolkit::TextSelectionPopup::SELECT_ALL:
2829 // Creates a SELECT_ALL event
2830 SelectEvent( 0.f, 0.f, true );
2833 case Toolkit::TextSelectionPopup::CLIPBOARD:
2835 mImpl->ShowClipboard();
2838 case Toolkit::TextSelectionPopup::NONE:
2846 void Controller::DisplayTimeExpired()
2848 mImpl->mEventData->mUpdateCursorPosition = true;
2849 // Apply modifications to the model
2850 mImpl->mOperationsPending = ALL_OPERATIONS;
2852 mImpl->RequestRelayout();
2855 // private : Update.
2857 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2859 bool removedPrevious = false;
2860 bool removedSelected = false;
2861 bool maxLengthReached = false;
2863 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2865 if( NULL == mImpl->mEventData )
2870 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2871 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2872 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2874 // TODO: At the moment the underline runs are only for pre-edit.
2875 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2877 // Remove the previous IMF pre-edit.
2878 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2880 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2881 mImpl->mEventData->mPreEditLength,
2882 DONT_UPDATE_INPUT_STYLE );
2884 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2885 mImpl->mEventData->mPreEditLength = 0u;
2889 // Remove the previous Selection.
2890 removedSelected = RemoveSelectedText();
2894 Vector<Character> utf32Characters;
2895 Length characterCount = 0u;
2899 // Convert text into UTF-32
2900 utf32Characters.Resize( text.size() );
2902 // This is a bit horrible but std::string returns a (signed) char*
2903 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2905 // Transform a text array encoded in utf8 into an array encoded in utf32.
2906 // It returns the actual number of characters.
2907 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2908 utf32Characters.Resize( characterCount );
2910 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2911 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2914 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2916 // The placeholder text is no longer needed
2917 if( mImpl->IsShowingPlaceholderText() )
2922 mImpl->ChangeState( EventData::EDITING );
2924 // Handle the IMF (predicitive text) state changes
2925 if( COMMIT == type )
2927 // IMF manager is no longer handling key-events
2928 mImpl->ClearPreEditFlag();
2932 if( !mImpl->mEventData->mPreEditFlag )
2934 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2936 // Record the start of the pre-edit text
2937 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2940 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2941 mImpl->mEventData->mPreEditFlag = true;
2943 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2946 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2948 // Restrict new text to fit within Maximum characters setting.
2949 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2950 maxLengthReached = ( characterCount > maxSizeOfNewText );
2952 // The cursor position.
2953 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2955 // Update the text's style.
2957 // Updates the text style runs by adding characters.
2958 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2960 // Get the character index from the cursor index.
2961 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2963 // Retrieve the text's style for the given index.
2965 mImpl->RetrieveDefaultInputStyle( style );
2966 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2968 // Whether to add a new text color run.
2969 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2971 // Whether to add a new font run.
2972 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2973 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2974 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2975 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2976 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2981 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2982 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2984 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2985 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2986 colorRun.characterRun.characterIndex = cursorIndex;
2987 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2990 if( addFontNameRun ||
2996 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2997 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2999 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3001 if( addFontNameRun )
3003 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3004 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3005 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3006 fontDescriptionRun.familyDefined = true;
3008 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3011 if( addFontWeightRun )
3013 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3014 fontDescriptionRun.weightDefined = true;
3017 if( addFontWidthRun )
3019 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3020 fontDescriptionRun.widthDefined = true;
3023 if( addFontSlantRun )
3025 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3026 fontDescriptionRun.slantDefined = true;
3029 if( addFontSizeRun )
3031 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3032 fontDescriptionRun.sizeDefined = true;
3035 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3036 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3039 // Insert at current cursor position.
3040 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3042 if( cursorIndex < numberOfCharactersInModel )
3044 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3048 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3051 // Mark the first paragraph to be updated.
3052 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3054 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3055 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3056 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3057 mImpl->mTextUpdateInfo.mClearAll = true;
3061 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3062 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3065 // Update the cursor index.
3066 cursorIndex += maxSizeOfNewText;
3068 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 );
3071 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3072 mImpl->IsPlaceholderAvailable() )
3074 // Show place-holder if empty after removing the pre-edit text
3075 ShowPlaceholderText();
3076 mImpl->mEventData->mUpdateCursorPosition = true;
3077 mImpl->ClearPreEditFlag();
3079 else if( removedPrevious ||
3081 ( 0 != utf32Characters.Count() ) )
3083 // Queue an inserted event
3084 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3086 mImpl->mEventData->mUpdateCursorPosition = true;
3087 if( removedSelected )
3089 mImpl->mEventData->mScrollAfterDelete = true;
3093 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3097 if( maxLengthReached )
3099 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3101 mImpl->ResetImfManager();
3103 if( NULL != mImpl->mEditableControlInterface )
3105 // Do this last since it provides callbacks into application code
3106 mImpl->mEditableControlInterface->MaxLengthReached();
3111 void Controller::PasteText( const std::string& stringToPaste )
3113 InsertText( stringToPaste, Text::Controller::COMMIT );
3114 mImpl->ChangeState( EventData::EDITING );
3115 mImpl->RequestRelayout();
3117 if( NULL != mImpl->mEditableControlInterface )
3119 // Do this last since it provides callbacks into application code
3120 mImpl->mEditableControlInterface->TextChanged();
3124 bool Controller::RemoveText( int cursorOffset,
3125 int numberOfCharacters,
3126 UpdateInputStyleType type )
3128 bool removed = false;
3130 if( NULL == mImpl->mEventData )
3135 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3136 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3138 if( !mImpl->IsShowingPlaceholderText() )
3140 // Delete at current cursor position
3141 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3142 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3144 CharacterIndex cursorIndex = 0;
3146 // Validate the cursor position & number of characters
3147 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3149 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3152 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3154 numberOfCharacters = currentText.Count() - cursorIndex;
3157 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.
3158 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3160 // Mark the paragraphs to be updated.
3161 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3163 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3164 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3165 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3166 mImpl->mTextUpdateInfo.mClearAll = true;
3170 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3171 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3174 // Update the input style and remove the text's style before removing the text.
3176 if( UPDATE_INPUT_STYLE == type )
3178 // Keep a copy of the current input style.
3179 InputStyle currentInputStyle;
3180 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3182 // Set first the default input style.
3183 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3185 // Update the input style.
3186 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3188 // Compare if the input style has changed.
3189 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3191 if( hasInputStyleChanged )
3193 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3194 // Queue the input style changed signal.
3195 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3199 // Updates the text style runs by removing characters. Runs with no characters are removed.
3200 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3202 // Remove the characters.
3203 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3204 Vector<Character>::Iterator last = first + numberOfCharacters;
3206 currentText.Erase( first, last );
3208 // Cursor position retreat
3209 oldCursorIndex = cursorIndex;
3211 mImpl->mEventData->mScrollAfterDelete = true;
3213 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3221 bool Controller::RemoveSelectedText()
3223 bool textRemoved( false );
3225 if( EventData::SELECTING == mImpl->mEventData->mState )
3227 std::string removedString;
3228 mImpl->RetrieveSelection( removedString, true );
3230 if( !removedString.empty() )
3233 mImpl->ChangeState( EventData::EDITING );
3240 // private : Relayout.
3242 bool Controller::DoRelayout( const Size& size,
3243 OperationsMask operationsRequired,
3246 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3247 bool viewUpdated( false );
3249 // Calculate the operations to be done.
3250 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3252 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3253 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3255 // Get the current layout size.
3256 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3258 if( NO_OPERATION != ( LAYOUT & operations ) )
3260 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3262 // Some vectors with data needed to layout and reorder may be void
3263 // after the first time the text has been laid out.
3264 // Fill the vectors again.
3266 // Calculate the number of glyphs to layout.
3267 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3268 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3269 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3270 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3272 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3273 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3274 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3275 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3277 if( 0u == totalNumberOfGlyphs )
3279 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3281 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3284 // Nothing else to do if there is no glyphs.
3285 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3289 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3290 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3291 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3292 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3293 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3294 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3295 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3297 // Set the layout parameters.
3298 Layout::Parameters layoutParameters( size,
3300 lineBreakInfo.Begin(),
3301 wordBreakInfo.Begin(),
3302 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3304 glyphsToCharactersMap.Begin(),
3305 charactersPerGlyph.Begin(),
3306 charactersToGlyphBuffer,
3307 glyphsPerCharacterBuffer,
3308 totalNumberOfGlyphs,
3309 mImpl->mModel->mHorizontalAlignment,
3310 mImpl->mModel->mLineWrapMode );
3312 // Resize the vector of positions to have the same size than the vector of glyphs.
3313 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3314 glyphPositions.Resize( totalNumberOfGlyphs );
3316 // Whether the last character is a new paragraph character.
3317 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3318 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3320 // The initial glyph and the number of glyphs to layout.
3321 layoutParameters.startGlyphIndex = startGlyphIndex;
3322 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3323 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3324 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3326 // Update the ellipsis
3327 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3329 if( NULL != mImpl->mEventData )
3331 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3333 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3335 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3337 // Disable ellipsis when editing
3338 elideTextEnabled = false;
3341 // Reset the scroll position in inactive state
3342 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3344 ResetScrollPosition();
3348 // Update the visual model.
3350 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3352 mImpl->mModel->mVisualModel->mLines,
3356 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3360 layoutSize = newLayoutSize;
3362 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3364 mImpl->mAutoScrollDirectionRTL = false;
3367 // Reorder the lines
3368 if( NO_OPERATION != ( REORDER & operations ) )
3370 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3371 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3373 // Check first if there are paragraphs with bidirectional info.
3374 if( 0u != bidirectionalInfo.Count() )
3377 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3379 // Reorder the lines.
3380 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3381 ReorderLines( bidirectionalInfo,
3383 requestedNumberOfCharacters,
3384 mImpl->mModel->mVisualModel->mLines,
3385 bidirectionalLineInfo );
3387 // Set the bidirectional info per line into the layout parameters.
3388 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3389 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3391 // Re-layout the text. Reorder those lines with right to left characters.
3392 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3394 requestedNumberOfCharacters,
3397 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3399 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3402 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3408 // Sets the layout size.
3409 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3411 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3416 if( NO_OPERATION != ( ALIGN & operations ) )
3418 // The laid-out lines.
3419 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3421 // Need to align with the control's size as the text may contain lines
3422 // starting either with left to right text or right to left.
3423 mImpl->mLayoutEngine.Align( size,
3425 requestedNumberOfCharacters,
3426 mImpl->mModel->mHorizontalAlignment,
3428 mImpl->mModel->mAlignmentOffset );
3432 #if defined(DEBUG_ENABLED)
3433 std::string currentText;
3434 GetText( currentText );
3435 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3437 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3441 void Controller::CalculateVerticalOffset( const Size& controlSize )
3443 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3445 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3447 // Get the line height of the default font.
3448 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3451 switch( mImpl->mModel->mVerticalAlignment )
3453 case Layout::VERTICAL_ALIGN_TOP:
3455 mImpl->mModel->mScrollPosition.y = 0.f;
3458 case Layout::VERTICAL_ALIGN_CENTER:
3460 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3463 case Layout::VERTICAL_ALIGN_BOTTOM:
3465 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3471 // private : Events.
3473 void Controller::ProcessModifyEvents()
3475 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3477 if( 0u == events.Count() )
3483 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3484 endIt = events.End();
3488 const ModifyEvent& event = *it;
3490 if( ModifyEvent::TEXT_REPLACED == event.type )
3492 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3493 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3495 TextReplacedEvent();
3497 else if( ModifyEvent::TEXT_INSERTED == event.type )
3499 TextInsertedEvent();
3501 else if( ModifyEvent::TEXT_DELETED == event.type )
3503 // Placeholder-text cannot be deleted
3504 if( !mImpl->IsShowingPlaceholderText() )
3511 if( NULL != mImpl->mEventData )
3513 // When the text is being modified, delay cursor blinking
3514 mImpl->mEventData->mDecorator->DelayCursorBlink();
3517 // Discard temporary text
3521 void Controller::TextReplacedEvent()
3523 // The natural size needs to be re-calculated.
3524 mImpl->mRecalculateNaturalSize = true;
3526 // Apply modifications to the model
3527 mImpl->mOperationsPending = ALL_OPERATIONS;
3530 void Controller::TextInsertedEvent()
3532 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3534 if( NULL == mImpl->mEventData )
3539 mImpl->mEventData->mCheckScrollAmount = true;
3541 // The natural size needs to be re-calculated.
3542 mImpl->mRecalculateNaturalSize = true;
3544 // Apply modifications to the model; TODO - Optimize this
3545 mImpl->mOperationsPending = ALL_OPERATIONS;
3548 void Controller::TextDeletedEvent()
3550 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3552 if( NULL == mImpl->mEventData )
3557 mImpl->mEventData->mCheckScrollAmount = true;
3559 // The natural size needs to be re-calculated.
3560 mImpl->mRecalculateNaturalSize = true;
3562 // Apply modifications to the model; TODO - Optimize this
3563 mImpl->mOperationsPending = ALL_OPERATIONS;
3566 void Controller::SelectEvent( float x, float y, bool selectAll )
3568 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3570 if( NULL != mImpl->mEventData )
3574 Event event( Event::SELECT_ALL );
3575 mImpl->mEventData->mEventQueue.push_back( event );
3579 Event event( Event::SELECT );
3580 event.p2.mFloat = x;
3581 event.p3.mFloat = y;
3582 mImpl->mEventData->mEventQueue.push_back( event );
3585 mImpl->mEventData->mCheckScrollAmount = true;
3586 mImpl->mEventData->mIsLeftHandleSelected = true;
3587 mImpl->mEventData->mIsRightHandleSelected = true;
3588 mImpl->RequestRelayout();
3592 bool Controller::BackspaceKeyEvent()
3594 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3596 bool removed = false;
3598 if( NULL == mImpl->mEventData )
3603 // IMF manager is no longer handling key-events
3604 mImpl->ClearPreEditFlag();
3606 if( EventData::SELECTING == mImpl->mEventData->mState )
3608 removed = RemoveSelectedText();
3610 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3612 // Remove the character before the current cursor position
3613 removed = RemoveText( -1,
3615 UPDATE_INPUT_STYLE );
3620 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3621 !mImpl->IsPlaceholderAvailable() )
3623 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3627 ShowPlaceholderText();
3629 mImpl->mEventData->mUpdateCursorPosition = true;
3630 mImpl->mEventData->mScrollAfterDelete = true;
3636 // private : Helpers.
3638 void Controller::ResetText()
3641 mImpl->mModel->mLogicalModel->mText.Clear();
3643 // We have cleared everything including the placeholder-text
3644 mImpl->PlaceholderCleared();
3646 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3647 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3648 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3650 // Clear any previous text.
3651 mImpl->mTextUpdateInfo.mClearAll = true;
3653 // The natural size needs to be re-calculated.
3654 mImpl->mRecalculateNaturalSize = true;
3656 // Apply modifications to the model
3657 mImpl->mOperationsPending = ALL_OPERATIONS;
3660 void Controller::ShowPlaceholderText()