2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
28 #include <dali/devel-api/adaptor-framework/key-devel.h>
31 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
32 #include <dali-toolkit/internal/text/bidirectional-support.h>
33 #include <dali-toolkit/internal/text/character-set-conversion.h>
34 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
35 #include <dali-toolkit/internal/text/markup-processor.h>
36 #include <dali-toolkit/internal/text/multi-language-support.h>
37 #include <dali-toolkit/internal/text/text-controller-impl.h>
38 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
39 #include <dali-toolkit/internal/text/text-font-style.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
48 const float MAX_FLOAT = std::numeric_limits<float>::max();
50 const std::string EMPTY_STRING("");
52 const char * const PLACEHOLDER_TEXT = "text";
53 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
54 const char * const PLACEHOLDER_COLOR = "color";
55 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
56 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
57 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
58 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
59 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
61 float ConvertToEven( float value )
63 int intValue(static_cast<int>( value ));
64 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
79 * @brief Adds a new font description run for the selected text.
81 * The new font parameters are added after the call to this method.
83 * @param[in] eventData The event data pointer.
84 * @param[in] logicalModel The logical model where to add the new font description run.
85 * @param[out] startOfSelectedText Index to the first selected character.
86 * @param[out] lengthOfSelectedText Number of selected characters.
88 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
89 LogicalModelPtr logicalModel,
90 CharacterIndex& startOfSelectedText,
91 Length& lengthOfSelectedText )
93 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
95 // Get start and end position of selection
96 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
97 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
100 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
101 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
103 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
105 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
106 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
108 // Recalculate the selection highlight as the metrics may have changed.
109 eventData->mUpdateLeftSelectionPosition = true;
110 eventData->mUpdateRightSelectionPosition = true;
111 eventData->mUpdateHighlightBox = true;
113 return fontDescriptionRun;
116 // public : Constructor.
118 ControllerPtr Controller::New()
120 return ControllerPtr( new Controller() );
123 ControllerPtr Controller::New( ControlInterface* controlInterface )
125 return ControllerPtr( new Controller( controlInterface ) );
128 ControllerPtr Controller::New( ControlInterface* controlInterface,
129 EditableControlInterface* editableControlInterface )
131 return ControllerPtr( new Controller( controlInterface,
132 editableControlInterface ) );
135 // public : Configure the text controller.
137 void Controller::EnableTextInput( DecoratorPtr decorator )
141 delete mImpl->mEventData;
142 mImpl->mEventData = NULL;
144 // Nothing else to do.
148 if( NULL == mImpl->mEventData )
150 mImpl->mEventData = new EventData( decorator );
154 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
156 // Metrics for bitmap & vector based glyphs are different
157 mImpl->mMetrics->SetGlyphType( glyphType );
159 // Clear the font-specific data
162 mImpl->RequestRelayout();
165 void Controller::SetMarkupProcessorEnabled( bool enable )
167 mImpl->mMarkupProcessorEnabled = enable;
170 bool Controller::IsMarkupProcessorEnabled() const
172 return mImpl->mMarkupProcessorEnabled;
175 void Controller::SetAutoScrollEnabled( bool enable )
177 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 );
179 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
183 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
184 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
194 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
195 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
202 mImpl->mIsAutoScrollEnabled = enable;
203 mImpl->RequestRelayout();
207 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
208 mImpl->mIsAutoScrollEnabled = false;
212 bool Controller::IsAutoScrollEnabled() const
214 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
216 return mImpl->mIsAutoScrollEnabled;
219 CharacterDirection Controller::GetAutoScrollDirection() const
221 return mImpl->mAutoScrollDirectionRTL;
224 float Controller::GetAutoScrollLineAlignment() const
228 if( mImpl->mModel->mVisualModel &&
229 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
231 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
237 void Controller::SetHorizontalScrollEnabled( bool enable )
239 if( ( NULL != mImpl->mEventData ) &&
240 mImpl->mEventData->mDecorator )
242 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
245 bool Controller::IsHorizontalScrollEnabled() const
247 if( ( NULL != mImpl->mEventData ) &&
248 mImpl->mEventData->mDecorator )
250 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
256 void Controller::SetVerticalScrollEnabled( bool enable )
258 if( ( NULL != mImpl->mEventData ) &&
259 mImpl->mEventData->mDecorator )
261 if( mImpl->mEventData->mDecorator )
263 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
268 bool Controller::IsVerticalScrollEnabled() const
270 if( ( NULL != mImpl->mEventData ) &&
271 mImpl->mEventData->mDecorator )
273 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
279 void Controller::SetSmoothHandlePanEnabled( bool enable )
281 if( ( NULL != mImpl->mEventData ) &&
282 mImpl->mEventData->mDecorator )
284 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
288 bool Controller::IsSmoothHandlePanEnabled() const
290 if( ( NULL != mImpl->mEventData ) &&
291 mImpl->mEventData->mDecorator )
293 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
299 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
301 mImpl->mMaximumNumberOfCharacters = maxCharacters;
304 int Controller::GetMaximumNumberOfCharacters()
306 return mImpl->mMaximumNumberOfCharacters;
309 void Controller::SetEnableCursorBlink( bool enable )
311 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
313 if( NULL != mImpl->mEventData )
315 mImpl->mEventData->mCursorBlinkEnabled = enable;
318 mImpl->mEventData->mDecorator )
320 mImpl->mEventData->mDecorator->StopCursorBlink();
325 bool Controller::GetEnableCursorBlink() const
327 if( NULL != mImpl->mEventData )
329 return mImpl->mEventData->mCursorBlinkEnabled;
335 void Controller::SetMultiLineEnabled( bool enable )
337 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
339 if( layout != mImpl->mLayoutEngine.GetLayout() )
341 // Set the layout type.
342 mImpl->mLayoutEngine.SetLayout( layout );
344 // Set the flags to redo the layout operations
345 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
350 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
351 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
353 mImpl->RequestRelayout();
357 bool Controller::IsMultiLineEnabled() const
359 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
362 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
364 if( alignment != mImpl->mModel->mHorizontalAlignment )
366 // Set the alignment.
367 mImpl->mModel->mHorizontalAlignment = alignment;
369 // Set the flag to redo the alignment operation.
370 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
372 mImpl->RequestRelayout();
376 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
378 return mImpl->mModel->mHorizontalAlignment;
381 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
383 if( alignment != mImpl->mModel->mVerticalAlignment )
385 // Set the alignment.
386 mImpl->mModel->mVerticalAlignment = alignment;
388 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
390 mImpl->RequestRelayout();
394 VerticalAlignment::Type Controller::GetVerticalAlignment() const
396 return mImpl->mModel->mVerticalAlignment;
399 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
401 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
403 // Set the text wrap mode.
404 mImpl->mModel->mLineWrapMode = lineWrapMode;
407 // Update Text layout for applying wrap mode
408 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
413 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
414 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
415 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
418 mImpl->RequestRelayout();
422 Text::LineWrap::Mode Controller::GetLineWrapMode() const
424 return mImpl->mModel->mLineWrapMode;
427 void Controller::SetTextElideEnabled( bool enabled )
429 mImpl->mModel->mElideEnabled = enabled;
432 bool Controller::IsTextElideEnabled() const
434 return mImpl->mModel->mElideEnabled;
437 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
439 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
440 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
442 // Update placeholder if there is no text
443 if( mImpl->IsShowingPlaceholderText() ||
444 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
446 ShowPlaceholderText();
450 bool Controller::IsPlaceholderTextElideEnabled() const
452 return mImpl->mEventData->mIsPlaceholderElideEnabled;
455 void Controller::SetSelectionEnabled( bool enabled )
457 mImpl->mEventData->mSelectionEnabled = enabled;
460 bool Controller::IsSelectionEnabled() const
462 return mImpl->mEventData->mSelectionEnabled;
467 void Controller::SetText( const std::string& text )
469 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
471 // Reset keyboard as text changed
472 mImpl->ResetImfManager();
474 // Remove the previously set text and style.
480 CharacterIndex lastCursorIndex = 0u;
482 if( NULL != mImpl->mEventData )
484 // If popup shown then hide it by switching to Editing state
485 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
486 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
487 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
488 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
490 mImpl->ChangeState( EventData::EDITING );
496 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
498 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
499 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
501 Length textSize = 0u;
502 const uint8_t* utf8 = NULL;
503 if( mImpl->mMarkupProcessorEnabled )
505 ProcessMarkupString( text, markupProcessData );
506 textSize = markupProcessData.markupProcessedText.size();
508 // This is a bit horrible but std::string returns a (signed) char*
509 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
513 textSize = text.size();
515 // This is a bit horrible but std::string returns a (signed) char*
516 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
519 // Convert text into UTF-32
520 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
521 utf32Characters.Resize( textSize );
523 // Transform a text array encoded in utf8 into an array encoded in utf32.
524 // It returns the actual number of characters.
525 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
526 utf32Characters.Resize( characterCount );
528 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
529 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
531 // The characters to be added.
532 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
534 // To reset the cursor position
535 lastCursorIndex = characterCount;
537 // Update the rest of the model during size negotiation
538 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
540 // The natural size needs to be re-calculated.
541 mImpl->mRecalculateNaturalSize = true;
543 // Apply modifications to the model
544 mImpl->mOperationsPending = ALL_OPERATIONS;
548 ShowPlaceholderText();
551 // Resets the cursor position.
552 ResetCursorPosition( lastCursorIndex );
554 // Scrolls the text to make the cursor visible.
555 ResetScrollPosition();
557 mImpl->RequestRelayout();
559 if( NULL != mImpl->mEventData )
561 // Cancel previously queued events
562 mImpl->mEventData->mEventQueue.clear();
565 // Do this last since it provides callbacks into application code.
566 if( NULL != mImpl->mEditableControlInterface )
568 mImpl->mEditableControlInterface->TextChanged();
572 void Controller::GetText( std::string& text ) const
574 if( !mImpl->IsShowingPlaceholderText() )
576 // Retrieves the text string.
577 mImpl->GetText( 0u, text );
581 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
585 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
587 if( NULL != mImpl->mEventData )
589 if( PLACEHOLDER_TYPE_INACTIVE == type )
591 mImpl->mEventData->mPlaceholderTextInactive = text;
595 mImpl->mEventData->mPlaceholderTextActive = text;
598 // Update placeholder if there is no text
599 if( mImpl->IsShowingPlaceholderText() ||
600 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
602 ShowPlaceholderText();
607 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
609 if( NULL != mImpl->mEventData )
611 if( PLACEHOLDER_TYPE_INACTIVE == type )
613 text = mImpl->mEventData->mPlaceholderTextInactive;
617 text = mImpl->mEventData->mPlaceholderTextActive;
622 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
624 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
626 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
628 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
629 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
633 mImpl->RequestRelayout();
637 // public : Default style & Input style
639 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
641 if( NULL == mImpl->mFontDefaults )
643 mImpl->mFontDefaults = new FontDefaults();
646 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
647 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
648 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
650 // Clear the font-specific data
653 mImpl->RequestRelayout();
656 const std::string& Controller::GetDefaultFontFamily() const
658 if( NULL != mImpl->mFontDefaults )
660 return mImpl->mFontDefaults->mFontDescription.family;
666 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
668 if( NULL != mImpl->mEventData )
670 if( NULL == mImpl->mEventData->mPlaceholderFont )
672 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
675 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
676 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
677 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
679 mImpl->RequestRelayout();
683 const std::string& Controller::GetPlaceholderFontFamily() const
685 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
687 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
693 void Controller::SetDefaultFontWeight( FontWeight weight )
695 if( NULL == mImpl->mFontDefaults )
697 mImpl->mFontDefaults = new FontDefaults();
700 mImpl->mFontDefaults->mFontDescription.weight = weight;
701 mImpl->mFontDefaults->weightDefined = true;
703 // Clear the font-specific data
706 mImpl->RequestRelayout();
709 bool Controller::IsDefaultFontWeightDefined() const
711 if( NULL != mImpl->mFontDefaults )
713 return mImpl->mFontDefaults->weightDefined;
719 FontWeight Controller::GetDefaultFontWeight() const
721 if( NULL != mImpl->mFontDefaults )
723 return mImpl->mFontDefaults->mFontDescription.weight;
726 return TextAbstraction::FontWeight::NORMAL;
729 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
731 if( NULL != mImpl->mEventData )
733 if( NULL == mImpl->mEventData->mPlaceholderFont )
735 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
738 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
739 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
741 mImpl->RequestRelayout();
745 bool Controller::IsPlaceholderTextFontWeightDefined() const
747 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
749 return mImpl->mEventData->mPlaceholderFont->weightDefined;
754 FontWeight Controller::GetPlaceholderTextFontWeight() const
756 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
758 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
761 return TextAbstraction::FontWeight::NORMAL;
764 void Controller::SetDefaultFontWidth( FontWidth width )
766 if( NULL == mImpl->mFontDefaults )
768 mImpl->mFontDefaults = new FontDefaults();
771 mImpl->mFontDefaults->mFontDescription.width = width;
772 mImpl->mFontDefaults->widthDefined = true;
774 // Clear the font-specific data
777 mImpl->RequestRelayout();
780 bool Controller::IsDefaultFontWidthDefined() const
782 if( NULL != mImpl->mFontDefaults )
784 return mImpl->mFontDefaults->widthDefined;
790 FontWidth Controller::GetDefaultFontWidth() const
792 if( NULL != mImpl->mFontDefaults )
794 return mImpl->mFontDefaults->mFontDescription.width;
797 return TextAbstraction::FontWidth::NORMAL;
800 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
802 if( NULL != mImpl->mEventData )
804 if( NULL == mImpl->mEventData->mPlaceholderFont )
806 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
809 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
810 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
812 mImpl->RequestRelayout();
816 bool Controller::IsPlaceholderTextFontWidthDefined() const
818 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
820 return mImpl->mEventData->mPlaceholderFont->widthDefined;
825 FontWidth Controller::GetPlaceholderTextFontWidth() const
827 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
829 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
832 return TextAbstraction::FontWidth::NORMAL;
835 void Controller::SetDefaultFontSlant( FontSlant slant )
837 if( NULL == mImpl->mFontDefaults )
839 mImpl->mFontDefaults = new FontDefaults();
842 mImpl->mFontDefaults->mFontDescription.slant = slant;
843 mImpl->mFontDefaults->slantDefined = true;
845 // Clear the font-specific data
848 mImpl->RequestRelayout();
851 bool Controller::IsDefaultFontSlantDefined() const
853 if( NULL != mImpl->mFontDefaults )
855 return mImpl->mFontDefaults->slantDefined;
860 FontSlant Controller::GetDefaultFontSlant() const
862 if( NULL != mImpl->mFontDefaults )
864 return mImpl->mFontDefaults->mFontDescription.slant;
867 return TextAbstraction::FontSlant::NORMAL;
870 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
872 if( NULL != mImpl->mEventData )
874 if( NULL == mImpl->mEventData->mPlaceholderFont )
876 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
879 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
880 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
882 mImpl->RequestRelayout();
886 bool Controller::IsPlaceholderTextFontSlantDefined() const
888 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
890 return mImpl->mEventData->mPlaceholderFont->slantDefined;
895 FontSlant Controller::GetPlaceholderTextFontSlant() const
897 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
899 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
902 return TextAbstraction::FontSlant::NORMAL;
905 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
907 if( NULL == mImpl->mFontDefaults )
909 mImpl->mFontDefaults = new FontDefaults();
916 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
917 mImpl->mFontDefaults->sizeDefined = true;
922 // Point size = Pixel size * 72.f / DPI
923 unsigned int horizontalDpi = 0u;
924 unsigned int verticalDpi = 0u;
925 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
926 fontClient.GetDpi( horizontalDpi, verticalDpi );
928 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
929 mImpl->mFontDefaults->sizeDefined = true;
934 // Clear the font-specific data
937 mImpl->RequestRelayout();
940 float Controller::GetDefaultFontSize( FontSizeType type ) const
943 if( NULL != mImpl->mFontDefaults )
949 value = mImpl->mFontDefaults->mDefaultPointSize;
954 // Pixel size = Point size * DPI / 72.f
955 unsigned int horizontalDpi = 0u;
956 unsigned int verticalDpi = 0u;
957 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
958 fontClient.GetDpi( horizontalDpi, verticalDpi );
960 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
970 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
972 if( NULL != mImpl->mEventData )
974 if( NULL == mImpl->mEventData->mPlaceholderFont )
976 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
983 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
984 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
985 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
990 // Point size = Pixel size * 72.f / DPI
991 unsigned int horizontalDpi = 0u;
992 unsigned int verticalDpi = 0u;
993 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
994 fontClient.GetDpi( horizontalDpi, verticalDpi );
996 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
997 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
998 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1003 mImpl->RequestRelayout();
1007 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1010 if( NULL != mImpl->mEventData )
1016 if( NULL != mImpl->mEventData->mPlaceholderFont )
1018 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1022 // If the placeholder text font size is not set, then return the default font size.
1023 value = GetDefaultFontSize( POINT_SIZE );
1029 if( NULL != mImpl->mEventData->mPlaceholderFont )
1031 // Pixel size = Point size * DPI / 72.f
1032 unsigned int horizontalDpi = 0u;
1033 unsigned int verticalDpi = 0u;
1034 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1035 fontClient.GetDpi( horizontalDpi, verticalDpi );
1037 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1041 // If the placeholder text font size is not set, then return the default font size.
1042 value = GetDefaultFontSize( PIXEL_SIZE );
1053 void Controller::SetDefaultColor( const Vector4& color )
1055 mImpl->mTextColor = color;
1057 if( !mImpl->IsShowingPlaceholderText() )
1059 mImpl->mModel->mVisualModel->SetTextColor( color );
1061 mImpl->RequestRelayout();
1065 const Vector4& Controller::GetDefaultColor() const
1067 return mImpl->mTextColor;
1070 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1072 if( NULL != mImpl->mEventData )
1074 mImpl->mEventData->mPlaceholderTextColor = textColor;
1077 if( mImpl->IsShowingPlaceholderText() )
1079 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1080 mImpl->RequestRelayout();
1084 const Vector4& Controller::GetPlaceholderTextColor() const
1086 if( NULL != mImpl->mEventData )
1088 return mImpl->mEventData->mPlaceholderTextColor;
1091 return Color::BLACK;
1094 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1096 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1098 mImpl->RequestRelayout();
1101 const Vector2& Controller::GetShadowOffset() const
1103 return mImpl->mModel->mVisualModel->GetShadowOffset();
1106 void Controller::SetShadowColor( const Vector4& shadowColor )
1108 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1110 mImpl->RequestRelayout();
1113 const Vector4& Controller::GetShadowColor() const
1115 return mImpl->mModel->mVisualModel->GetShadowColor();
1118 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1120 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1122 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1124 mImpl->RequestRelayout();
1128 const float& Controller::GetShadowBlurRadius() const
1130 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1133 void Controller::SetUnderlineColor( const Vector4& color )
1135 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1137 mImpl->RequestRelayout();
1140 const Vector4& Controller::GetUnderlineColor() const
1142 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1145 void Controller::SetUnderlineEnabled( bool enabled )
1147 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1149 mImpl->RequestRelayout();
1152 bool Controller::IsUnderlineEnabled() const
1154 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1157 void Controller::SetUnderlineHeight( float height )
1159 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1161 mImpl->RequestRelayout();
1164 float Controller::GetUnderlineHeight() const
1166 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1169 void Controller::SetOutlineColor( const Vector4& color )
1171 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1173 mImpl->RequestRelayout();
1176 const Vector4& Controller::GetOutlineColor() const
1178 return mImpl->mModel->mVisualModel->GetOutlineColor();
1181 void Controller::SetOutlineWidth( float width )
1183 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1185 mImpl->RequestRelayout();
1188 float Controller::GetOutlineWidth() const
1190 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1193 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1195 if( NULL == mImpl->mEmbossDefaults )
1197 mImpl->mEmbossDefaults = new EmbossDefaults();
1200 mImpl->mEmbossDefaults->properties = embossProperties;
1203 const std::string& Controller::GetDefaultEmbossProperties() const
1205 if( NULL != mImpl->mEmbossDefaults )
1207 return mImpl->mEmbossDefaults->properties;
1210 return EMPTY_STRING;
1213 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1215 if( NULL == mImpl->mOutlineDefaults )
1217 mImpl->mOutlineDefaults = new OutlineDefaults();
1220 mImpl->mOutlineDefaults->properties = outlineProperties;
1223 const std::string& Controller::GetDefaultOutlineProperties() const
1225 if( NULL != mImpl->mOutlineDefaults )
1227 return mImpl->mOutlineDefaults->properties;
1230 return EMPTY_STRING;
1233 void Controller::SetDefaultLineSpacing( float lineSpacing )
1235 //TODO finish implementation
1236 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1239 float Controller::GetDefaultLineSpacing() const
1241 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1244 void Controller::SetInputColor( const Vector4& color )
1246 if( NULL != mImpl->mEventData )
1248 mImpl->mEventData->mInputStyle.textColor = color;
1249 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1251 if( EventData::SELECTING == mImpl->mEventData->mState )
1253 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1255 // Get start and end position of selection
1256 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1257 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1259 // Add the color run.
1260 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1261 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1263 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1264 colorRun.color = color;
1265 colorRun.characterRun.characterIndex = startOfSelectedText;
1266 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1268 // Request to relayout.
1269 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1270 mImpl->RequestRelayout();
1272 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1273 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1274 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1279 const Vector4& Controller::GetInputColor() const
1281 if( NULL != mImpl->mEventData )
1283 return mImpl->mEventData->mInputStyle.textColor;
1286 // Return the default text's color if there is no EventData.
1287 return mImpl->mTextColor;
1291 void Controller::SetInputFontFamily( const std::string& fontFamily )
1293 if( NULL != mImpl->mEventData )
1295 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1296 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1298 if( EventData::SELECTING == mImpl->mEventData->mState )
1300 CharacterIndex startOfSelectedText = 0u;
1301 Length lengthOfSelectedText = 0u;
1302 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1303 mImpl->mModel->mLogicalModel,
1304 startOfSelectedText,
1305 lengthOfSelectedText );
1307 fontDescriptionRun.familyLength = fontFamily.size();
1308 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1309 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1310 fontDescriptionRun.familyDefined = true;
1312 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1314 // Request to relayout.
1315 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1320 UPDATE_LAYOUT_SIZE |
1323 mImpl->mRecalculateNaturalSize = true;
1324 mImpl->RequestRelayout();
1326 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1327 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1328 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1330 // As the font changes, recalculate the handle positions is needed.
1331 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1332 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1333 mImpl->mEventData->mUpdateHighlightBox = true;
1334 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1339 const std::string& Controller::GetInputFontFamily() const
1341 if( NULL != mImpl->mEventData )
1343 return mImpl->mEventData->mInputStyle.familyName;
1346 // Return the default font's family if there is no EventData.
1347 return GetDefaultFontFamily();
1350 void Controller::SetInputFontWeight( FontWeight weight )
1352 if( NULL != mImpl->mEventData )
1354 mImpl->mEventData->mInputStyle.weight = weight;
1355 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1357 if( EventData::SELECTING == mImpl->mEventData->mState )
1359 CharacterIndex startOfSelectedText = 0u;
1360 Length lengthOfSelectedText = 0u;
1361 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1362 mImpl->mModel->mLogicalModel,
1363 startOfSelectedText,
1364 lengthOfSelectedText );
1366 fontDescriptionRun.weight = weight;
1367 fontDescriptionRun.weightDefined = true;
1369 // Request to relayout.
1370 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1375 UPDATE_LAYOUT_SIZE |
1378 mImpl->mRecalculateNaturalSize = true;
1379 mImpl->RequestRelayout();
1381 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1382 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1383 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1385 // As the font might change, recalculate the handle positions is needed.
1386 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1387 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1388 mImpl->mEventData->mUpdateHighlightBox = true;
1389 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1394 bool Controller::IsInputFontWeightDefined() const
1396 bool defined = false;
1398 if( NULL != mImpl->mEventData )
1400 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1406 FontWeight Controller::GetInputFontWeight() const
1408 if( NULL != mImpl->mEventData )
1410 return mImpl->mEventData->mInputStyle.weight;
1413 return GetDefaultFontWeight();
1416 void Controller::SetInputFontWidth( FontWidth width )
1418 if( NULL != mImpl->mEventData )
1420 mImpl->mEventData->mInputStyle.width = width;
1421 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1423 if( EventData::SELECTING == mImpl->mEventData->mState )
1425 CharacterIndex startOfSelectedText = 0u;
1426 Length lengthOfSelectedText = 0u;
1427 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1428 mImpl->mModel->mLogicalModel,
1429 startOfSelectedText,
1430 lengthOfSelectedText );
1432 fontDescriptionRun.width = width;
1433 fontDescriptionRun.widthDefined = true;
1435 // Request to relayout.
1436 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1441 UPDATE_LAYOUT_SIZE |
1444 mImpl->mRecalculateNaturalSize = true;
1445 mImpl->RequestRelayout();
1447 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1448 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1449 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1451 // As the font might change, recalculate the handle positions is needed.
1452 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1453 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1454 mImpl->mEventData->mUpdateHighlightBox = true;
1455 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1460 bool Controller::IsInputFontWidthDefined() const
1462 bool defined = false;
1464 if( NULL != mImpl->mEventData )
1466 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1472 FontWidth Controller::GetInputFontWidth() const
1474 if( NULL != mImpl->mEventData )
1476 return mImpl->mEventData->mInputStyle.width;
1479 return GetDefaultFontWidth();
1482 void Controller::SetInputFontSlant( FontSlant slant )
1484 if( NULL != mImpl->mEventData )
1486 mImpl->mEventData->mInputStyle.slant = slant;
1487 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1489 if( EventData::SELECTING == mImpl->mEventData->mState )
1491 CharacterIndex startOfSelectedText = 0u;
1492 Length lengthOfSelectedText = 0u;
1493 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1494 mImpl->mModel->mLogicalModel,
1495 startOfSelectedText,
1496 lengthOfSelectedText );
1498 fontDescriptionRun.slant = slant;
1499 fontDescriptionRun.slantDefined = true;
1501 // Request to relayout.
1502 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1507 UPDATE_LAYOUT_SIZE |
1510 mImpl->mRecalculateNaturalSize = true;
1511 mImpl->RequestRelayout();
1513 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1514 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1515 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1517 // As the font might change, recalculate the handle positions is needed.
1518 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1519 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1520 mImpl->mEventData->mUpdateHighlightBox = true;
1521 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1526 bool Controller::IsInputFontSlantDefined() const
1528 bool defined = false;
1530 if( NULL != mImpl->mEventData )
1532 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1538 FontSlant Controller::GetInputFontSlant() const
1540 if( NULL != mImpl->mEventData )
1542 return mImpl->mEventData->mInputStyle.slant;
1545 return GetDefaultFontSlant();
1548 void Controller::SetInputFontPointSize( float size )
1550 if( NULL != mImpl->mEventData )
1552 mImpl->mEventData->mInputStyle.size = size;
1553 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1555 if( EventData::SELECTING == mImpl->mEventData->mState )
1557 CharacterIndex startOfSelectedText = 0u;
1558 Length lengthOfSelectedText = 0u;
1559 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1560 mImpl->mModel->mLogicalModel,
1561 startOfSelectedText,
1562 lengthOfSelectedText );
1564 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1565 fontDescriptionRun.sizeDefined = true;
1567 // Request to relayout.
1568 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1573 UPDATE_LAYOUT_SIZE |
1576 mImpl->mRecalculateNaturalSize = true;
1577 mImpl->RequestRelayout();
1579 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1580 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1581 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1583 // As the font might change, recalculate the handle positions is needed.
1584 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1585 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1586 mImpl->mEventData->mUpdateHighlightBox = true;
1587 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1592 float Controller::GetInputFontPointSize() const
1594 if( NULL != mImpl->mEventData )
1596 return mImpl->mEventData->mInputStyle.size;
1599 // Return the default font's point size if there is no EventData.
1600 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1603 void Controller::SetInputLineSpacing( float lineSpacing )
1605 if( NULL != mImpl->mEventData )
1607 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1608 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1612 float Controller::GetInputLineSpacing() const
1614 if( NULL != mImpl->mEventData )
1616 return mImpl->mEventData->mInputStyle.lineSpacing;
1622 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1624 if( NULL != mImpl->mEventData )
1626 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1630 const std::string& Controller::GetInputShadowProperties() const
1632 if( NULL != mImpl->mEventData )
1634 return mImpl->mEventData->mInputStyle.shadowProperties;
1637 return EMPTY_STRING;
1640 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1642 if( NULL != mImpl->mEventData )
1644 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1648 const std::string& Controller::GetInputUnderlineProperties() const
1650 if( NULL != mImpl->mEventData )
1652 return mImpl->mEventData->mInputStyle.underlineProperties;
1655 return EMPTY_STRING;
1658 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1660 if( NULL != mImpl->mEventData )
1662 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1666 const std::string& Controller::GetInputEmbossProperties() const
1668 if( NULL != mImpl->mEventData )
1670 return mImpl->mEventData->mInputStyle.embossProperties;
1673 return GetDefaultEmbossProperties();
1676 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1678 if( NULL != mImpl->mEventData )
1680 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1684 const std::string& Controller::GetInputOutlineProperties() const
1686 if( NULL != mImpl->mEventData )
1688 return mImpl->mEventData->mInputStyle.outlineProperties;
1691 return GetDefaultOutlineProperties();
1694 void Controller::SetInputModePassword( bool passwordInput )
1696 if( NULL != mImpl->mEventData )
1698 mImpl->mEventData->mPasswordInput = passwordInput;
1702 bool Controller::IsInputModePassword()
1704 if( NULL != mImpl->mEventData )
1706 return mImpl->mEventData->mPasswordInput;
1711 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1713 if( NULL != mImpl->mEventData )
1715 mImpl->mEventData->mDoubleTapAction = action;
1719 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1721 NoTextTap::Action action = NoTextTap::NO_ACTION;
1723 if( NULL != mImpl->mEventData )
1725 action = mImpl->mEventData->mDoubleTapAction;
1731 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1733 if( NULL != mImpl->mEventData )
1735 mImpl->mEventData->mLongPressAction = action;
1739 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1741 NoTextTap::Action action = NoTextTap::NO_ACTION;
1743 if( NULL != mImpl->mEventData )
1745 action = mImpl->mEventData->mLongPressAction;
1751 bool Controller::IsUnderlineSetByString()
1753 return mImpl->mUnderlineSetByString;
1756 void Controller::UnderlineSetByString( bool setByString )
1758 mImpl->mUnderlineSetByString = setByString;
1761 bool Controller::IsShadowSetByString()
1763 return mImpl->mShadowSetByString;
1766 void Controller::ShadowSetByString( bool setByString )
1768 mImpl->mShadowSetByString = setByString;
1771 bool Controller::IsOutlineSetByString()
1773 return mImpl->mOutlineSetByString;
1776 void Controller::OutlineSetByString( bool setByString )
1778 mImpl->mOutlineSetByString = setByString;
1781 bool Controller::IsFontStyleSetByString()
1783 return mImpl->mFontStyleSetByString;
1786 void Controller::FontStyleSetByString( bool setByString )
1788 mImpl->mFontStyleSetByString = setByString;
1791 // public : Queries & retrieves.
1793 Layout::Engine& Controller::GetLayoutEngine()
1795 return mImpl->mLayoutEngine;
1798 View& Controller::GetView()
1800 return mImpl->mView;
1803 Vector3 Controller::GetNaturalSize()
1805 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1806 Vector3 naturalSize;
1808 // Make sure the model is up-to-date before layouting
1809 ProcessModifyEvents();
1811 if( mImpl->mRecalculateNaturalSize )
1813 // Operations that can be done only once until the text changes.
1814 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1821 GET_GLYPH_METRICS );
1823 // Set the update info to relayout the whole text.
1824 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1825 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1827 // Make sure the model is up-to-date before layouting
1828 mImpl->UpdateModel( onlyOnceOperations );
1830 // Layout the text for the new width.
1831 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1833 // Store the actual control's size to restore later.
1834 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1836 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1837 static_cast<OperationsMask>( onlyOnceOperations |
1839 naturalSize.GetVectorXY() );
1841 // Do not do again the only once operations.
1842 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1844 // Do the size related operations again.
1845 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1848 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1850 // Stores the natural size to avoid recalculate it again
1851 // unless the text/style changes.
1852 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1854 mImpl->mRecalculateNaturalSize = false;
1856 // Clear the update info. This info will be set the next time the text is updated.
1857 mImpl->mTextUpdateInfo.Clear();
1859 // Restore the actual control's size.
1860 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1862 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1866 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1868 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1871 naturalSize.x = ConvertToEven( naturalSize.x );
1872 naturalSize.y = ConvertToEven( naturalSize.y );
1877 float Controller::GetHeightForWidth( float width )
1879 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1880 // Make sure the model is up-to-date before layouting
1881 ProcessModifyEvents();
1884 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1885 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1886 mImpl->mTextUpdateInfo.mClearAll )
1888 // Operations that can be done only once until the text changes.
1889 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1896 GET_GLYPH_METRICS );
1898 // Set the update info to relayout the whole text.
1899 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1900 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1902 // Make sure the model is up-to-date before layouting
1903 mImpl->UpdateModel( onlyOnceOperations );
1906 // Layout the text for the new width.
1907 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1909 // Store the actual control's width.
1910 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1912 DoRelayout( Size( width, MAX_FLOAT ),
1913 static_cast<OperationsMask>( onlyOnceOperations |
1917 // Do not do again the only once operations.
1918 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1920 // Do the size related operations again.
1921 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1925 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1927 // Clear the update info. This info will be set the next time the text is updated.
1928 mImpl->mTextUpdateInfo.Clear();
1930 // Restore the actual control's width.
1931 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1933 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1937 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1938 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1941 return layoutSize.height;
1944 int Controller::GetLineCount( float width )
1946 GetHeightForWidth( width );
1947 int numberofLines = mImpl->mModel->GetNumberOfLines();
1948 return numberofLines;
1951 const ModelInterface* const Controller::GetTextModel() const
1953 return mImpl->mModel.Get();
1956 float Controller::GetScrollAmountByUserInput()
1958 float scrollAmount = 0.0f;
1960 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1962 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1963 mImpl->mEventData->mCheckScrollAmount = false;
1965 return scrollAmount;
1968 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1970 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1973 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1974 layoutHeight = layout.height;
1975 scrollPosition = mImpl->mModel->mScrollPosition.y;
1976 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1980 void Controller::SetHiddenInputOption(const Property::Map& options )
1982 if( NULL == mImpl->mHiddenInput )
1984 mImpl->mHiddenInput = new HiddenText( this );
1986 mImpl->mHiddenInput->SetProperties(options);
1989 void Controller::GetHiddenInputOption(Property::Map& options )
1991 if( NULL != mImpl->mHiddenInput )
1993 mImpl->mHiddenInput->GetProperties(options);
1997 void Controller::SetPlaceholderProperty( const Property::Map& map )
1999 const Property::Map::SizeType count = map.Count();
2001 for( Property::Map::SizeType position = 0; position < count; ++position )
2003 KeyValuePair keyValue = map.GetKeyValue( position );
2004 Property::Key& key = keyValue.first;
2005 Property::Value& value = keyValue.second;
2007 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2009 std::string text = "";
2011 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2013 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2015 std::string text = "";
2017 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2019 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2022 value.Get( textColor );
2023 if( GetPlaceholderTextColor() != textColor )
2025 SetPlaceholderTextColor( textColor );
2028 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2030 std::string fontFamily = "";
2031 value.Get( fontFamily );
2032 SetPlaceholderFontFamily( fontFamily );
2034 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2036 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2038 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2041 value.Get( pointSize );
2042 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2044 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2047 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2050 value.Get( pixelSize );
2051 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2053 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2056 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2059 value.Get( ellipsis );
2060 SetPlaceholderTextElideEnabled( ellipsis );
2065 void Controller::GetPlaceholderProperty( Property::Map& map )
2067 if( NULL != mImpl->mEventData )
2069 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2071 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2073 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2075 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2078 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2079 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2081 Property::Value fontStyleMapGet;
2082 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2083 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2085 // Choose font size : POINT_SIZE or PIXEL_SIZE
2086 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2088 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2092 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2095 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2097 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2102 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2104 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
2105 if ( firstline && firstline->direction )
2107 return Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT;
2110 return Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2113 // public : Relayout.
2115 Controller::UpdateTextType Controller::Relayout( const Size& size )
2117 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2119 UpdateTextType updateTextType = NONE_UPDATED;
2121 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2123 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2125 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2126 updateTextType = MODEL_UPDATED;
2129 // Clear the update info. This info will be set the next time the text is updated.
2130 mImpl->mTextUpdateInfo.Clear();
2132 // Not worth to relayout if width or height is equal to zero.
2133 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2135 return updateTextType;
2138 // Whether a new size has been set.
2139 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2143 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2145 // Layout operations that need to be done if the size changes.
2146 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2149 UPDATE_LAYOUT_SIZE |
2151 // Set the update info to relayout the whole text.
2152 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2153 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2155 // Store the size used to layout the text.
2156 mImpl->mModel->mVisualModel->mControlSize = size;
2159 // Whether there are modify events.
2160 if( 0u != mImpl->mModifyEvents.Count() )
2162 // Style operations that need to be done if the text is modified.
2163 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2167 // Set the update info to elide the text.
2168 if( mImpl->mModel->mElideEnabled ||
2169 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2171 // Update Text layout for applying elided
2172 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2175 UPDATE_LAYOUT_SIZE |
2177 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2178 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2181 // Make sure the model is up-to-date before layouting.
2182 ProcessModifyEvents();
2183 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2187 updated = DoRelayout( size,
2188 mImpl->mOperationsPending,
2189 layoutSize ) || updated;
2193 updateTextType = MODEL_UPDATED;
2196 // Do not re-do any operation until something changes.
2197 mImpl->mOperationsPending = NO_OPERATION;
2198 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2200 // Whether the text control is editable
2201 const bool isEditable = NULL != mImpl->mEventData;
2203 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2205 if( newSize && isEditable )
2207 offset = mImpl->mModel->mScrollPosition;
2210 if( !isEditable || !IsMultiLineEnabled() )
2212 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2213 CalculateVerticalOffset( size );
2220 // If there is a new size, the scroll position needs to be clamped.
2221 mImpl->ClampHorizontalScroll( layoutSize );
2223 // Update the decorator's positions is needed if there is a new size.
2224 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2227 // Move the cursor, grab handle etc.
2228 if( mImpl->ProcessInputEvents() )
2230 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2234 // Clear the update info. This info will be set the next time the text is updated.
2235 mImpl->mTextUpdateInfo.Clear();
2236 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2238 return updateTextType;
2241 void Controller::RequestRelayout()
2243 mImpl->RequestRelayout();
2246 // public : Input style change signals.
2248 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2250 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2253 void Controller::ProcessInputStyleChangedSignals()
2255 if( NULL == mImpl->mEventData )
2261 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2262 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2266 const InputStyle::Mask mask = *it;
2268 if( NULL != mImpl->mEditableControlInterface )
2270 // Emit the input style changed signal.
2271 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2275 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2278 // public : Text-input Event Queuing.
2280 void Controller::KeyboardFocusGainEvent()
2282 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2284 if( NULL != mImpl->mEventData )
2286 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2287 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2289 mImpl->ChangeState( EventData::EDITING );
2290 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2291 mImpl->mEventData->mUpdateInputStyle = true;
2293 mImpl->NotifyImfMultiLineStatus();
2294 if( mImpl->IsShowingPlaceholderText() )
2296 // Show alternative placeholder-text when editing
2297 ShowPlaceholderText();
2300 mImpl->RequestRelayout();
2304 void Controller::KeyboardFocusLostEvent()
2306 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2308 if( NULL != mImpl->mEventData )
2310 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2312 mImpl->ChangeState( EventData::INACTIVE );
2314 if( !mImpl->IsShowingRealText() )
2316 // Revert to regular placeholder-text when not editing
2317 ShowPlaceholderText();
2321 mImpl->RequestRelayout();
2324 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2326 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2328 bool textChanged = false;
2329 bool relayoutNeeded = false;
2331 if( ( NULL != mImpl->mEventData ) &&
2332 ( keyEvent.state == KeyEvent::Down ) )
2334 int keyCode = keyEvent.keyCode;
2335 const std::string& keyString = keyEvent.keyPressed;
2337 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2339 // Pre-process to separate modifying events from non-modifying input events.
2342 // In some platforms arrive key events with no key code.
2346 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2351 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2352 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2353 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2354 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2356 // If don't have any text, do nothing.
2357 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2362 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2363 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2364 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2365 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2367 // Logic to determine whether this text control will lose focus or not.
2368 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2369 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2370 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2371 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2372 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2373 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2378 mImpl->mEventData->mCheckScrollAmount = true;
2379 Event event( Event::CURSOR_KEY_EVENT );
2380 event.p1.mInt = keyCode;
2381 mImpl->mEventData->mEventQueue.push_back( event );
2383 // Will request for relayout.
2384 relayoutNeeded = true;
2386 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2387 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2389 textChanged = DeleteEvent( keyCode );
2391 // Will request for relayout.
2392 relayoutNeeded = true;
2394 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2395 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2396 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2398 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2399 mImpl->ChangeState( EventData::INACTIVE );
2401 // Will request for relayout.
2402 relayoutNeeded = true;
2404 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2406 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2408 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2409 // and a character is typed after the type of a upper case latin character.
2414 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2416 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2422 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2424 // IMF manager is no longer handling key-events
2425 mImpl->ClearPreEditFlag();
2427 InsertText( keyString, COMMIT );
2430 // Will request for relayout.
2431 relayoutNeeded = true;
2434 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2435 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2437 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2438 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2439 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2441 // Should not change the state if the key is the shift send by the imf manager.
2442 // Otherwise, when the state is SELECTING the text controller can't send the right
2443 // surrounding info to the imf.
2444 mImpl->ChangeState( EventData::EDITING );
2446 // Will request for relayout.
2447 relayoutNeeded = true;
2450 if( relayoutNeeded )
2452 mImpl->RequestRelayout();
2457 ( NULL != mImpl->mEditableControlInterface ) )
2459 // Do this last since it provides callbacks into application code
2460 mImpl->mEditableControlInterface->TextChanged();
2466 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2468 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2470 if( NULL != mImpl->mEventData )
2472 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2473 EventData::State state( mImpl->mEventData->mState );
2474 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2476 if( mImpl->IsClipboardVisible() )
2478 if( EventData::INACTIVE == state || EventData::EDITING == state)
2480 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2482 relayoutNeeded = true;
2484 else if( 1u == tapCount )
2486 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2488 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2491 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2493 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2494 relayoutNeeded = true;
2498 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2500 // Hide placeholder text
2504 if( EventData::INACTIVE == state )
2506 mImpl->ChangeState( EventData::EDITING );
2508 else if( !mImpl->IsClipboardEmpty() )
2510 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2512 relayoutNeeded = true;
2515 else if( 2u == tapCount )
2517 if( mImpl->mEventData->mSelectionEnabled &&
2518 mImpl->IsShowingRealText() )
2520 relayoutNeeded = true;
2521 mImpl->mEventData->mIsLeftHandleSelected = true;
2522 mImpl->mEventData->mIsRightHandleSelected = true;
2526 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2527 if( relayoutNeeded )
2529 Event event( Event::TAP_EVENT );
2530 event.p1.mUint = tapCount;
2531 event.p2.mFloat = x;
2532 event.p3.mFloat = y;
2533 mImpl->mEventData->mEventQueue.push_back( event );
2535 mImpl->RequestRelayout();
2539 // Reset keyboard as tap event has occurred.
2540 mImpl->ResetImfManager();
2543 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2545 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2547 if( NULL != mImpl->mEventData )
2549 Event event( Event::PAN_EVENT );
2550 event.p1.mInt = state;
2551 event.p2.mFloat = displacement.x;
2552 event.p3.mFloat = displacement.y;
2553 mImpl->mEventData->mEventQueue.push_back( event );
2555 mImpl->RequestRelayout();
2559 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2561 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2563 if( ( state == Gesture::Started ) &&
2564 ( NULL != mImpl->mEventData ) )
2566 // The 1st long-press on inactive text-field is treated as tap
2567 if( EventData::INACTIVE == mImpl->mEventData->mState )
2569 mImpl->ChangeState( EventData::EDITING );
2571 Event event( Event::TAP_EVENT );
2573 event.p2.mFloat = x;
2574 event.p3.mFloat = y;
2575 mImpl->mEventData->mEventQueue.push_back( event );
2577 mImpl->RequestRelayout();
2579 else if( !mImpl->IsShowingRealText() )
2581 Event event( Event::LONG_PRESS_EVENT );
2582 event.p1.mInt = state;
2583 event.p2.mFloat = x;
2584 event.p3.mFloat = y;
2585 mImpl->mEventData->mEventQueue.push_back( event );
2586 mImpl->RequestRelayout();
2588 else if( !mImpl->IsClipboardVisible() )
2590 // Reset the imf manager to commit the pre-edit before selecting the text.
2591 mImpl->ResetImfManager();
2593 Event event( Event::LONG_PRESS_EVENT );
2594 event.p1.mInt = state;
2595 event.p2.mFloat = x;
2596 event.p3.mFloat = y;
2597 mImpl->mEventData->mEventQueue.push_back( event );
2598 mImpl->RequestRelayout();
2600 mImpl->mEventData->mIsLeftHandleSelected = true;
2601 mImpl->mEventData->mIsRightHandleSelected = true;
2606 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2608 // Whether the text needs to be relaid-out.
2609 bool requestRelayout = false;
2611 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2612 bool retrieveText = false;
2613 bool retrieveCursor = false;
2615 switch( imfEvent.eventName )
2617 case ImfManager::COMMIT:
2619 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2620 requestRelayout = true;
2621 retrieveCursor = true;
2624 case ImfManager::PREEDIT:
2626 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2627 requestRelayout = true;
2628 retrieveCursor = true;
2631 case ImfManager::DELETESURROUNDING:
2633 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2634 imfEvent.numberOfChars,
2635 DONT_UPDATE_INPUT_STYLE );
2639 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2640 !mImpl->IsPlaceholderAvailable() )
2642 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2646 ShowPlaceholderText();
2648 mImpl->mEventData->mUpdateCursorPosition = true;
2649 mImpl->mEventData->mScrollAfterDelete = true;
2651 requestRelayout = true;
2655 case ImfManager::GETSURROUNDING:
2657 retrieveText = true;
2658 retrieveCursor = true;
2661 case ImfManager::PRIVATECOMMAND:
2663 // PRIVATECOMMAND event is just for getting the private command message
2664 retrieveText = true;
2665 retrieveCursor = true;
2668 case ImfManager::VOID:
2675 if( requestRelayout )
2677 mImpl->mOperationsPending = ALL_OPERATIONS;
2678 mImpl->RequestRelayout();
2682 CharacterIndex cursorPosition = 0u;
2683 Length numberOfWhiteSpaces = 0u;
2685 if( retrieveCursor )
2687 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2689 cursorPosition = mImpl->GetLogicalCursorPosition();
2691 if( cursorPosition < numberOfWhiteSpaces )
2693 cursorPosition = 0u;
2697 cursorPosition -= numberOfWhiteSpaces;
2703 mImpl->GetText( numberOfWhiteSpaces, text );
2706 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2708 if( requestRelayout &&
2709 ( NULL != mImpl->mEditableControlInterface ) )
2711 // Do this last since it provides callbacks into application code
2712 mImpl->mEditableControlInterface->TextChanged();
2715 return callbackData;
2718 void Controller::PasteClipboardItemEvent()
2720 // Retrieve the clipboard contents first
2721 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2722 std::string stringToPaste( notifier.GetContent() );
2724 // Commit the current pre-edit text; the contents of the clipboard should be appended
2725 mImpl->ResetImfManager();
2727 // Temporary disable hiding clipboard
2728 mImpl->SetClipboardHideEnable( false );
2731 PasteText( stringToPaste );
2733 mImpl->SetClipboardHideEnable( true );
2736 // protected : Inherit from Text::Decorator::ControllerInterface.
2738 void Controller::GetTargetSize( Vector2& targetSize )
2740 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2743 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2745 if( NULL != mImpl->mEditableControlInterface )
2747 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2751 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2753 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2755 if( NULL != mImpl->mEventData )
2757 switch( handleType )
2761 Event event( Event::GRAB_HANDLE_EVENT );
2762 event.p1.mUint = state;
2763 event.p2.mFloat = x;
2764 event.p3.mFloat = y;
2766 mImpl->mEventData->mEventQueue.push_back( event );
2769 case LEFT_SELECTION_HANDLE:
2771 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2772 event.p1.mUint = state;
2773 event.p2.mFloat = x;
2774 event.p3.mFloat = y;
2776 mImpl->mEventData->mEventQueue.push_back( event );
2779 case RIGHT_SELECTION_HANDLE:
2781 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2782 event.p1.mUint = state;
2783 event.p2.mFloat = x;
2784 event.p3.mFloat = y;
2786 mImpl->mEventData->mEventQueue.push_back( event );
2789 case LEFT_SELECTION_HANDLE_MARKER:
2790 case RIGHT_SELECTION_HANDLE_MARKER:
2792 // Markers do not move the handles.
2795 case HANDLE_TYPE_COUNT:
2797 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2801 mImpl->RequestRelayout();
2805 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2807 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2809 if( NULL == mImpl->mEventData )
2816 case Toolkit::TextSelectionPopup::CUT:
2818 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2819 mImpl->mOperationsPending = ALL_OPERATIONS;
2821 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2822 !mImpl->IsPlaceholderAvailable() )
2824 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2828 ShowPlaceholderText();
2831 mImpl->mEventData->mUpdateCursorPosition = true;
2832 mImpl->mEventData->mScrollAfterDelete = true;
2834 mImpl->RequestRelayout();
2836 if( NULL != mImpl->mEditableControlInterface )
2838 mImpl->mEditableControlInterface->TextChanged();
2842 case Toolkit::TextSelectionPopup::COPY:
2844 mImpl->SendSelectionToClipboard( false ); // Text not modified
2846 mImpl->mEventData->mUpdateCursorPosition = true;
2848 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2851 case Toolkit::TextSelectionPopup::PASTE:
2853 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2856 case Toolkit::TextSelectionPopup::SELECT:
2858 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2860 if( mImpl->mEventData->mSelectionEnabled )
2862 // Creates a SELECT event.
2863 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2867 case Toolkit::TextSelectionPopup::SELECT_ALL:
2869 // Creates a SELECT_ALL event
2870 SelectEvent( 0.f, 0.f, true );
2873 case Toolkit::TextSelectionPopup::CLIPBOARD:
2875 mImpl->ShowClipboard();
2878 case Toolkit::TextSelectionPopup::NONE:
2886 void Controller::DisplayTimeExpired()
2888 mImpl->mEventData->mUpdateCursorPosition = true;
2889 // Apply modifications to the model
2890 mImpl->mOperationsPending = ALL_OPERATIONS;
2892 mImpl->RequestRelayout();
2895 // private : Update.
2897 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2899 bool removedPrevious = false;
2900 bool removedSelected = false;
2901 bool maxLengthReached = false;
2903 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2905 if( NULL == mImpl->mEventData )
2910 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2911 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2912 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2914 // TODO: At the moment the underline runs are only for pre-edit.
2915 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2917 // Remove the previous IMF pre-edit.
2918 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2920 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2921 mImpl->mEventData->mPreEditLength,
2922 DONT_UPDATE_INPUT_STYLE );
2924 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2925 mImpl->mEventData->mPreEditLength = 0u;
2929 // Remove the previous Selection.
2930 removedSelected = RemoveSelectedText();
2934 Vector<Character> utf32Characters;
2935 Length characterCount = 0u;
2939 // Convert text into UTF-32
2940 utf32Characters.Resize( text.size() );
2942 // This is a bit horrible but std::string returns a (signed) char*
2943 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2945 // Transform a text array encoded in utf8 into an array encoded in utf32.
2946 // It returns the actual number of characters.
2947 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2948 utf32Characters.Resize( characterCount );
2950 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2951 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2954 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2956 // The placeholder text is no longer needed
2957 if( mImpl->IsShowingPlaceholderText() )
2962 mImpl->ChangeState( EventData::EDITING );
2964 // Handle the IMF (predicitive text) state changes
2965 if( COMMIT == type )
2967 // IMF manager is no longer handling key-events
2968 mImpl->ClearPreEditFlag();
2972 if( !mImpl->mEventData->mPreEditFlag )
2974 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2976 // Record the start of the pre-edit text
2977 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2980 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2981 mImpl->mEventData->mPreEditFlag = true;
2983 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2986 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2988 // Restrict new text to fit within Maximum characters setting.
2989 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2990 maxLengthReached = ( characterCount > maxSizeOfNewText );
2992 // The cursor position.
2993 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2995 // Update the text's style.
2997 // Updates the text style runs by adding characters.
2998 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3000 // Get the character index from the cursor index.
3001 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3003 // Retrieve the text's style for the given index.
3005 mImpl->RetrieveDefaultInputStyle( style );
3006 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3008 // Whether to add a new text color run.
3009 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3011 // Whether to add a new font run.
3012 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3013 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3014 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3015 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3016 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3021 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3022 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3024 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3025 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3026 colorRun.characterRun.characterIndex = cursorIndex;
3027 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3030 if( addFontNameRun ||
3036 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3037 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3039 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3041 if( addFontNameRun )
3043 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3044 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3045 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3046 fontDescriptionRun.familyDefined = true;
3048 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3051 if( addFontWeightRun )
3053 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3054 fontDescriptionRun.weightDefined = true;
3057 if( addFontWidthRun )
3059 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3060 fontDescriptionRun.widthDefined = true;
3063 if( addFontSlantRun )
3065 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3066 fontDescriptionRun.slantDefined = true;
3069 if( addFontSizeRun )
3071 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3072 fontDescriptionRun.sizeDefined = true;
3075 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3076 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3079 // Insert at current cursor position.
3080 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3082 if( cursorIndex < numberOfCharactersInModel )
3084 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3088 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3091 // Mark the first paragraph to be updated.
3092 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3094 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3095 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3096 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3097 mImpl->mTextUpdateInfo.mClearAll = true;
3101 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3102 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3105 // Update the cursor index.
3106 cursorIndex += maxSizeOfNewText;
3108 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 );
3111 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3112 mImpl->IsPlaceholderAvailable() )
3114 // Show place-holder if empty after removing the pre-edit text
3115 ShowPlaceholderText();
3116 mImpl->mEventData->mUpdateCursorPosition = true;
3117 mImpl->ClearPreEditFlag();
3119 else if( removedPrevious ||
3121 ( 0 != utf32Characters.Count() ) )
3123 // Queue an inserted event
3124 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3126 mImpl->mEventData->mUpdateCursorPosition = true;
3127 if( removedSelected )
3129 mImpl->mEventData->mScrollAfterDelete = true;
3133 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3137 if( maxLengthReached )
3139 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3141 mImpl->ResetImfManager();
3143 if( NULL != mImpl->mEditableControlInterface )
3145 // Do this last since it provides callbacks into application code
3146 mImpl->mEditableControlInterface->MaxLengthReached();
3151 void Controller::PasteText( const std::string& stringToPaste )
3153 InsertText( stringToPaste, Text::Controller::COMMIT );
3154 mImpl->ChangeState( EventData::EDITING );
3155 mImpl->RequestRelayout();
3157 if( NULL != mImpl->mEditableControlInterface )
3159 // Do this last since it provides callbacks into application code
3160 mImpl->mEditableControlInterface->TextChanged();
3164 bool Controller::RemoveText( int cursorOffset,
3165 int numberOfCharacters,
3166 UpdateInputStyleType type )
3168 bool removed = false;
3170 if( NULL == mImpl->mEventData )
3175 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3176 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3178 if( !mImpl->IsShowingPlaceholderText() )
3180 // Delete at current cursor position
3181 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3182 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3184 CharacterIndex cursorIndex = 0;
3186 // Validate the cursor position & number of characters
3187 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3189 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3192 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3194 numberOfCharacters = currentText.Count() - cursorIndex;
3197 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.
3198 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3200 // Mark the paragraphs to be updated.
3201 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3203 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3204 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3205 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3206 mImpl->mTextUpdateInfo.mClearAll = true;
3210 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3211 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3214 // Update the input style and remove the text's style before removing the text.
3216 if( UPDATE_INPUT_STYLE == type )
3218 // Keep a copy of the current input style.
3219 InputStyle currentInputStyle;
3220 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3222 // Set first the default input style.
3223 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3225 // Update the input style.
3226 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3228 // Compare if the input style has changed.
3229 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3231 if( hasInputStyleChanged )
3233 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3234 // Queue the input style changed signal.
3235 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3239 // Updates the text style runs by removing characters. Runs with no characters are removed.
3240 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3242 // Remove the characters.
3243 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3244 Vector<Character>::Iterator last = first + numberOfCharacters;
3246 currentText.Erase( first, last );
3248 // Cursor position retreat
3249 oldCursorIndex = cursorIndex;
3251 mImpl->mEventData->mScrollAfterDelete = true;
3253 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3261 bool Controller::RemoveSelectedText()
3263 bool textRemoved( false );
3265 if( EventData::SELECTING == mImpl->mEventData->mState )
3267 std::string removedString;
3268 mImpl->RetrieveSelection( removedString, true );
3270 if( !removedString.empty() )
3273 mImpl->ChangeState( EventData::EDITING );
3280 // private : Relayout.
3282 bool Controller::DoRelayout( const Size& size,
3283 OperationsMask operationsRequired,
3286 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3287 bool viewUpdated( false );
3289 // Calculate the operations to be done.
3290 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3292 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3293 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3295 // Get the current layout size.
3296 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3298 if( NO_OPERATION != ( LAYOUT & operations ) )
3300 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3302 // Some vectors with data needed to layout and reorder may be void
3303 // after the first time the text has been laid out.
3304 // Fill the vectors again.
3306 // Calculate the number of glyphs to layout.
3307 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3308 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3309 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3310 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3312 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3313 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3314 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3315 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3317 if( 0u == totalNumberOfGlyphs )
3319 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3321 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3324 // Nothing else to do if there is no glyphs.
3325 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3329 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3330 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3331 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3332 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3333 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3334 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3335 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3336 float outlineWidth = mImpl->mModel->GetOutlineWidth();
3338 // Set the layout parameters.
3339 Layout::Parameters layoutParameters( size,
3341 lineBreakInfo.Begin(),
3342 wordBreakInfo.Begin(),
3343 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3345 glyphsToCharactersMap.Begin(),
3346 charactersPerGlyph.Begin(),
3347 charactersToGlyphBuffer,
3348 glyphsPerCharacterBuffer,
3349 totalNumberOfGlyphs,
3350 mImpl->mModel->mHorizontalAlignment,
3351 mImpl->mModel->mLineWrapMode,
3354 // Resize the vector of positions to have the same size than the vector of glyphs.
3355 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3356 glyphPositions.Resize( totalNumberOfGlyphs );
3358 // Whether the last character is a new paragraph character.
3359 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3360 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3362 // The initial glyph and the number of glyphs to layout.
3363 layoutParameters.startGlyphIndex = startGlyphIndex;
3364 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3365 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3366 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3368 // Update the ellipsis
3369 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3371 if( NULL != mImpl->mEventData )
3373 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3375 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3377 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3379 // Disable ellipsis when editing
3380 elideTextEnabled = false;
3383 // Reset the scroll position in inactive state
3384 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3386 ResetScrollPosition();
3390 // Update the visual model.
3392 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3394 mImpl->mModel->mVisualModel->mLines,
3398 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3402 layoutSize = newLayoutSize;
3404 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3406 mImpl->mAutoScrollDirectionRTL = false;
3409 // Reorder the lines
3410 if( NO_OPERATION != ( REORDER & operations ) )
3412 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3413 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3415 // Check first if there are paragraphs with bidirectional info.
3416 if( 0u != bidirectionalInfo.Count() )
3419 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3421 // Reorder the lines.
3422 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3423 ReorderLines( bidirectionalInfo,
3425 requestedNumberOfCharacters,
3426 mImpl->mModel->mVisualModel->mLines,
3427 bidirectionalLineInfo );
3429 // Set the bidirectional info per line into the layout parameters.
3430 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3431 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3433 // Re-layout the text. Reorder those lines with right to left characters.
3434 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3436 requestedNumberOfCharacters,
3439 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3441 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3444 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3450 // Sets the layout size.
3451 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3453 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3458 if( NO_OPERATION != ( ALIGN & operations ) )
3460 // The laid-out lines.
3461 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3463 // Need to align with the control's size as the text may contain lines
3464 // starting either with left to right text or right to left.
3465 mImpl->mLayoutEngine.Align( size,
3467 requestedNumberOfCharacters,
3468 mImpl->mModel->mHorizontalAlignment,
3470 mImpl->mModel->mAlignmentOffset );
3474 #if defined(DEBUG_ENABLED)
3475 std::string currentText;
3476 GetText( currentText );
3477 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3479 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3483 void Controller::CalculateVerticalOffset( const Size& controlSize )
3485 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3487 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3489 // Get the line height of the default font.
3490 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3493 switch( mImpl->mModel->mVerticalAlignment )
3495 case VerticalAlignment::TOP:
3497 mImpl->mModel->mScrollPosition.y = 0.f;
3500 case VerticalAlignment::CENTER:
3502 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3505 case VerticalAlignment::BOTTOM:
3507 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3513 // private : Events.
3515 void Controller::ProcessModifyEvents()
3517 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3519 if( 0u == events.Count() )
3525 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3526 endIt = events.End();
3530 const ModifyEvent& event = *it;
3532 if( ModifyEvent::TEXT_REPLACED == event.type )
3534 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3535 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3537 TextReplacedEvent();
3539 else if( ModifyEvent::TEXT_INSERTED == event.type )
3541 TextInsertedEvent();
3543 else if( ModifyEvent::TEXT_DELETED == event.type )
3545 // Placeholder-text cannot be deleted
3546 if( !mImpl->IsShowingPlaceholderText() )
3553 if( NULL != mImpl->mEventData )
3555 // When the text is being modified, delay cursor blinking
3556 mImpl->mEventData->mDecorator->DelayCursorBlink();
3559 // Discard temporary text
3563 void Controller::TextReplacedEvent()
3565 // The natural size needs to be re-calculated.
3566 mImpl->mRecalculateNaturalSize = true;
3568 // Apply modifications to the model
3569 mImpl->mOperationsPending = ALL_OPERATIONS;
3572 void Controller::TextInsertedEvent()
3574 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3576 if( NULL == mImpl->mEventData )
3581 mImpl->mEventData->mCheckScrollAmount = true;
3583 // The natural size needs to be re-calculated.
3584 mImpl->mRecalculateNaturalSize = true;
3586 // Apply modifications to the model; TODO - Optimize this
3587 mImpl->mOperationsPending = ALL_OPERATIONS;
3590 void Controller::TextDeletedEvent()
3592 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3594 if( NULL == mImpl->mEventData )
3599 mImpl->mEventData->mCheckScrollAmount = true;
3601 // The natural size needs to be re-calculated.
3602 mImpl->mRecalculateNaturalSize = true;
3604 // Apply modifications to the model; TODO - Optimize this
3605 mImpl->mOperationsPending = ALL_OPERATIONS;
3608 void Controller::SelectEvent( float x, float y, bool selectAll )
3610 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3612 if( NULL != mImpl->mEventData )
3616 Event event( Event::SELECT_ALL );
3617 mImpl->mEventData->mEventQueue.push_back( event );
3621 Event event( Event::SELECT );
3622 event.p2.mFloat = x;
3623 event.p3.mFloat = y;
3624 mImpl->mEventData->mEventQueue.push_back( event );
3627 mImpl->mEventData->mCheckScrollAmount = true;
3628 mImpl->mEventData->mIsLeftHandleSelected = true;
3629 mImpl->mEventData->mIsRightHandleSelected = true;
3630 mImpl->RequestRelayout();
3634 bool Controller::DeleteEvent( int keyCode )
3636 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3638 bool removed = false;
3640 if( NULL == mImpl->mEventData )
3645 // IMF manager is no longer handling key-events
3646 mImpl->ClearPreEditFlag();
3648 if( EventData::SELECTING == mImpl->mEventData->mState )
3650 removed = RemoveSelectedText();
3652 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3654 // Remove the character before the current cursor position
3655 removed = RemoveText( -1,