2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
30 #include <dali-toolkit/internal/text/bidirectional-support.h>
31 #include <dali-toolkit/internal/text/character-set-conversion.h>
32 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
33 #include <dali-toolkit/internal/text/markup-processor.h>
34 #include <dali-toolkit/internal/text/multi-language-support.h>
35 #include <dali-toolkit/internal/text/text-controller-impl.h>
36 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
37 #include <dali-toolkit/internal/text/text-font-style.h>
42 #if defined(DEBUG_ENABLED)
43 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
46 const float MAX_FLOAT = std::numeric_limits<float>::max();
48 const std::string EMPTY_STRING("");
50 const char * const PLACEHOLDER_TEXT = "placeholderText";
51 const char * const PLACEHOLDER_COLOR = "placeholderColor";
52 const char * const PLACEHOLDER_FONT_FAMILY = "placeholderFontFamily";
53 const char * const PLACEHOLDER_FONT_STYLE = "placeholderFontStyle";
54 const char * const PLACEHOLDER_POINT_SIZE = "placeholderPointSize";
55 const char * const PLACEHOLDER_PIXEL_SIZE = "placeholderPixelSize";
57 float ConvertToEven( float value )
59 int intValue(static_cast<int>( value ));
60 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
75 * @brief Adds a new font description run for the selected text.
77 * The new font parameters are added after the call to this method.
79 * @param[in] eventData The event data pointer.
80 * @param[in] logicalModel The logical model where to add the new font description run.
81 * @param[out] startOfSelectedText Index to the first selected character.
82 * @param[out] lengthOfSelectedText Number of selected characters.
84 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
85 LogicalModelPtr logicalModel,
86 CharacterIndex& startOfSelectedText,
87 Length& lengthOfSelectedText )
89 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
91 // Get start and end position of selection
92 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
93 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
96 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
97 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
99 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
101 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
102 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
104 // Recalculate the selection highlight as the metrics may have changed.
105 eventData->mUpdateLeftSelectionPosition = true;
106 eventData->mUpdateRightSelectionPosition = true;
107 eventData->mUpdateHighlightBox = true;
109 return fontDescriptionRun;
112 // public : Constructor.
114 ControllerPtr Controller::New()
116 return ControllerPtr( new Controller() );
119 ControllerPtr Controller::New( ControlInterface* controlInterface )
121 return ControllerPtr( new Controller( controlInterface ) );
124 ControllerPtr Controller::New( ControlInterface* controlInterface,
125 EditableControlInterface* editableControlInterface )
127 return ControllerPtr( new Controller( controlInterface,
128 editableControlInterface ) );
131 // public : Configure the text controller.
133 void Controller::EnableTextInput( DecoratorPtr decorator )
137 delete mImpl->mEventData;
138 mImpl->mEventData = NULL;
140 // Nothing else to do.
144 if( NULL == mImpl->mEventData )
146 mImpl->mEventData = new EventData( decorator );
150 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
152 // Metrics for bitmap & vector based glyphs are different
153 mImpl->mMetrics->SetGlyphType( glyphType );
155 // Clear the font-specific data
158 mImpl->RequestRelayout();
161 void Controller::SetMarkupProcessorEnabled( bool enable )
163 mImpl->mMarkupProcessorEnabled = enable;
166 bool Controller::IsMarkupProcessorEnabled() const
168 return mImpl->mMarkupProcessorEnabled;
171 void Controller::SetAutoScrollEnabled( bool enable )
173 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 );
175 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
179 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
180 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
190 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
191 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
198 mImpl->mIsAutoScrollEnabled = enable;
199 mImpl->RequestRelayout();
203 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
204 mImpl->mIsAutoScrollEnabled = false;
208 bool Controller::IsAutoScrollEnabled() const
210 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
212 return mImpl->mIsAutoScrollEnabled;
215 CharacterDirection Controller::GetAutoScrollDirection() const
217 return mImpl->mAutoScrollDirectionRTL;
220 float Controller::GetAutoScrollLineAlignment() const
224 if( mImpl->mModel->mVisualModel &&
225 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
227 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
233 void Controller::SetHorizontalScrollEnabled( bool enable )
235 if( ( NULL != mImpl->mEventData ) &&
236 mImpl->mEventData->mDecorator )
238 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
241 bool Controller::IsHorizontalScrollEnabled() const
243 if( ( NULL != mImpl->mEventData ) &&
244 mImpl->mEventData->mDecorator )
246 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
252 void Controller::SetVerticalScrollEnabled( bool enable )
254 if( ( NULL != mImpl->mEventData ) &&
255 mImpl->mEventData->mDecorator )
257 if( mImpl->mEventData->mDecorator )
259 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
264 bool Controller::IsVerticalScrollEnabled() const
266 if( ( NULL != mImpl->mEventData ) &&
267 mImpl->mEventData->mDecorator )
269 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
275 void Controller::SetSmoothHandlePanEnabled( bool enable )
277 if( ( NULL != mImpl->mEventData ) &&
278 mImpl->mEventData->mDecorator )
280 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
284 bool Controller::IsSmoothHandlePanEnabled() const
286 if( ( NULL != mImpl->mEventData ) &&
287 mImpl->mEventData->mDecorator )
289 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
295 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
297 mImpl->mMaximumNumberOfCharacters = maxCharacters;
300 int Controller::GetMaximumNumberOfCharacters()
302 return mImpl->mMaximumNumberOfCharacters;
305 void Controller::SetEnableCursorBlink( bool enable )
307 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
309 if( NULL != mImpl->mEventData )
311 mImpl->mEventData->mCursorBlinkEnabled = enable;
314 mImpl->mEventData->mDecorator )
316 mImpl->mEventData->mDecorator->StopCursorBlink();
321 bool Controller::GetEnableCursorBlink() const
323 if( NULL != mImpl->mEventData )
325 return mImpl->mEventData->mCursorBlinkEnabled;
331 void Controller::SetMultiLineEnabled( bool enable )
333 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
335 if( layout != mImpl->mLayoutEngine.GetLayout() )
337 // Set the layout type.
338 mImpl->mLayoutEngine.SetLayout( layout );
340 // Set the flags to redo the layout operations
341 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
346 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
348 mImpl->RequestRelayout();
352 bool Controller::IsMultiLineEnabled() const
354 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
357 void Controller::SetHorizontalAlignment( Layout::HorizontalAlignment alignment )
359 if( alignment != mImpl->mModel->mHorizontalAlignment )
361 // Set the alignment.
362 mImpl->mModel->mHorizontalAlignment = alignment;
364 // Set the flag to redo the alignment operation.
365 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
367 mImpl->RequestRelayout();
371 Layout::HorizontalAlignment Controller::GetHorizontalAlignment() const
373 return mImpl->mModel->mHorizontalAlignment;
376 void Controller::SetVerticalAlignment( Layout::VerticalAlignment alignment )
378 if( alignment != mImpl->mModel->mVerticalAlignment )
380 // Set the alignment.
381 mImpl->mModel->mVerticalAlignment = alignment;
383 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
385 mImpl->RequestRelayout();
389 Layout::VerticalAlignment Controller::GetVerticalAlignment() const
391 return mImpl->mModel->mVerticalAlignment;
394 void Controller::SetTextElideEnabled( bool enabled )
396 mImpl->mModel->mElideEnabled = enabled;
399 bool Controller::IsTextElideEnabled() const
401 return mImpl->mModel->mElideEnabled;
404 void Controller::SetSelectionEnabled( bool enabled )
406 mImpl->mEventData->mSelectionEnabled = enabled;
409 bool Controller::IsSelectionEnabled() const
411 return mImpl->mEventData->mSelectionEnabled;
416 void Controller::SetText( const std::string& text )
418 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
420 // Reset keyboard as text changed
421 mImpl->ResetImfManager();
423 // Remove the previously set text and style.
429 CharacterIndex lastCursorIndex = 0u;
431 if( NULL != mImpl->mEventData )
433 // If popup shown then hide it by switching to Editing state
434 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
435 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
436 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
437 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
439 mImpl->ChangeState( EventData::EDITING );
445 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
447 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
448 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
450 Length textSize = 0u;
451 const uint8_t* utf8 = NULL;
452 if( mImpl->mMarkupProcessorEnabled )
454 ProcessMarkupString( text, markupProcessData );
455 textSize = markupProcessData.markupProcessedText.size();
457 // This is a bit horrible but std::string returns a (signed) char*
458 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
462 textSize = text.size();
464 // This is a bit horrible but std::string returns a (signed) char*
465 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
468 // Convert text into UTF-32
469 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
470 utf32Characters.Resize( textSize );
472 // Transform a text array encoded in utf8 into an array encoded in utf32.
473 // It returns the actual number of characters.
474 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
475 utf32Characters.Resize( characterCount );
477 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
478 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
480 // The characters to be added.
481 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
483 // To reset the cursor position
484 lastCursorIndex = characterCount;
486 // Update the rest of the model during size negotiation
487 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
489 // The natural size needs to be re-calculated.
490 mImpl->mRecalculateNaturalSize = true;
492 // Apply modifications to the model
493 mImpl->mOperationsPending = ALL_OPERATIONS;
497 ShowPlaceholderText();
500 // Resets the cursor position.
501 ResetCursorPosition( lastCursorIndex );
503 // Scrolls the text to make the cursor visible.
504 ResetScrollPosition();
506 mImpl->RequestRelayout();
508 if( NULL != mImpl->mEventData )
510 // Cancel previously queued events
511 mImpl->mEventData->mEventQueue.clear();
514 // Do this last since it provides callbacks into application code.
515 if( NULL != mImpl->mEditableControlInterface )
517 mImpl->mEditableControlInterface->TextChanged();
521 void Controller::GetText( std::string& text ) const
523 if( !mImpl->IsShowingPlaceholderText() )
525 // Retrieves the text string.
526 mImpl->GetText( 0u, text );
530 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
534 void Controller::SetPlaceholderText( const std::string& text )
536 if( NULL != mImpl->mEventData )
538 mImpl->mEventData->mPlaceholderText = text;
540 // Update placeholder if there is no text
541 if( mImpl->IsShowingPlaceholderText() ||
542 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
544 ShowPlaceholderText();
549 // This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field
550 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
552 if( NULL != mImpl->mEventData )
554 if( PLACEHOLDER_TYPE_INACTIVE == type )
556 mImpl->mEventData->mPlaceholderTextInactive = text;
560 mImpl->mEventData->mPlaceholderTextActive = text;
563 // Update placeholder if there is no text
564 if( mImpl->IsShowingPlaceholderText() ||
565 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
567 ShowPlaceholderText();
572 void Controller::GetPlaceholderText( std::string& text ) const
574 if( NULL != mImpl->mEventData )
576 text = mImpl->mEventData->mPlaceholderText;
580 // This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field
581 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
583 if( NULL != mImpl->mEventData )
585 if( PLACEHOLDER_TYPE_INACTIVE == type )
587 text = mImpl->mEventData->mPlaceholderTextInactive;
591 text = mImpl->mEventData->mPlaceholderTextActive;
596 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
598 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
600 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
602 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
603 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
607 mImpl->RequestRelayout();
611 // public : Default style & Input style
613 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
615 if( NULL == mImpl->mFontDefaults )
617 mImpl->mFontDefaults = new FontDefaults();
620 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
621 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
622 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
624 // Clear the font-specific data
627 mImpl->RequestRelayout();
630 const std::string& Controller::GetDefaultFontFamily() const
632 if( NULL != mImpl->mFontDefaults )
634 return mImpl->mFontDefaults->mFontDescription.family;
640 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
642 if( NULL != mImpl->mEventData )
644 if( NULL == mImpl->mEventData->mPlaceholderFont )
646 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
649 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
650 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
651 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
653 mImpl->RequestRelayout();
657 const std::string& Controller::GetPlaceholderFontFamily() const
659 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
661 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
667 void Controller::SetDefaultFontWeight( FontWeight weight )
669 if( NULL == mImpl->mFontDefaults )
671 mImpl->mFontDefaults = new FontDefaults();
674 mImpl->mFontDefaults->mFontDescription.weight = weight;
675 mImpl->mFontDefaults->weightDefined = true;
677 // Clear the font-specific data
680 mImpl->RequestRelayout();
683 bool Controller::IsDefaultFontWeightDefined() const
685 return mImpl->mFontDefaults->weightDefined;
688 FontWeight Controller::GetDefaultFontWeight() const
690 if( NULL != mImpl->mFontDefaults )
692 return mImpl->mFontDefaults->mFontDescription.weight;
695 return TextAbstraction::FontWeight::NORMAL;
698 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
700 if( NULL != mImpl->mEventData )
702 if( NULL == mImpl->mEventData->mPlaceholderFont )
704 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
707 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
708 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
710 mImpl->RequestRelayout();
714 bool Controller::IsPlaceholderTextFontWeightDefined() const
716 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
718 return mImpl->mEventData->mPlaceholderFont->weightDefined;
723 FontWeight Controller::GetPlaceholderTextFontWeight() const
725 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
727 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
730 return TextAbstraction::FontWeight::NORMAL;
733 void Controller::SetDefaultFontWidth( FontWidth width )
735 if( NULL == mImpl->mFontDefaults )
737 mImpl->mFontDefaults = new FontDefaults();
740 mImpl->mFontDefaults->mFontDescription.width = width;
741 mImpl->mFontDefaults->widthDefined = true;
743 // Clear the font-specific data
746 mImpl->RequestRelayout();
749 bool Controller::IsDefaultFontWidthDefined() const
751 return mImpl->mFontDefaults->widthDefined;
754 FontWidth Controller::GetDefaultFontWidth() const
756 if( NULL != mImpl->mFontDefaults )
758 return mImpl->mFontDefaults->mFontDescription.width;
761 return TextAbstraction::FontWidth::NORMAL;
764 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
766 if( NULL != mImpl->mEventData )
768 if( NULL == mImpl->mEventData->mPlaceholderFont )
770 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
773 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
774 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
776 mImpl->RequestRelayout();
780 bool Controller::IsPlaceholderTextFontWidthDefined() const
782 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
784 return mImpl->mEventData->mPlaceholderFont->widthDefined;
789 FontWidth Controller::GetPlaceholderTextFontWidth() const
791 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
793 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
796 return TextAbstraction::FontWidth::NORMAL;
799 void Controller::SetDefaultFontSlant( FontSlant slant )
801 if( NULL == mImpl->mFontDefaults )
803 mImpl->mFontDefaults = new FontDefaults();
806 mImpl->mFontDefaults->mFontDescription.slant = slant;
807 mImpl->mFontDefaults->slantDefined = true;
809 // Clear the font-specific data
812 mImpl->RequestRelayout();
815 bool Controller::IsDefaultFontSlantDefined() const
817 return mImpl->mFontDefaults->slantDefined;
820 FontSlant Controller::GetDefaultFontSlant() const
822 if( NULL != mImpl->mFontDefaults )
824 return mImpl->mFontDefaults->mFontDescription.slant;
827 return TextAbstraction::FontSlant::NORMAL;
830 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
832 if( NULL != mImpl->mEventData )
834 if( NULL == mImpl->mEventData->mPlaceholderFont )
836 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
839 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
840 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
842 mImpl->RequestRelayout();
846 bool Controller::IsPlaceholderTextFontSlantDefined() const
848 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
850 return mImpl->mEventData->mPlaceholderFont->slantDefined;
855 FontSlant Controller::GetPlaceholderTextFontSlant() const
857 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
859 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
862 return TextAbstraction::FontSlant::NORMAL;
865 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
867 if( NULL == mImpl->mFontDefaults )
869 mImpl->mFontDefaults = new FontDefaults();
876 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
877 mImpl->mFontDefaults->sizeDefined = true;
882 // Point size = Pixel size * 72.f / DPI
883 unsigned int horizontalDpi = 0u;
884 unsigned int verticalDpi = 0u;
885 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
886 fontClient.GetDpi( horizontalDpi, verticalDpi );
888 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
889 mImpl->mFontDefaults->sizeDefined = true;
894 // Clear the font-specific data
897 mImpl->RequestRelayout();
900 float Controller::GetDefaultFontSize( FontSizeType type ) const
903 if( NULL != mImpl->mFontDefaults )
909 value = mImpl->mFontDefaults->mDefaultPointSize;
914 // Pixel size = Point size * DPI / 72.f
915 unsigned int horizontalDpi = 0u;
916 unsigned int verticalDpi = 0u;
917 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
918 fontClient.GetDpi( horizontalDpi, verticalDpi );
920 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
930 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
932 if( NULL != mImpl->mEventData )
934 if( NULL == mImpl->mEventData->mPlaceholderFont )
936 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
943 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
944 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
945 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
950 // Point size = Pixel size * 72.f / DPI
951 unsigned int horizontalDpi = 0u;
952 unsigned int verticalDpi = 0u;
953 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
954 fontClient.GetDpi( horizontalDpi, verticalDpi );
956 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
957 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
958 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
963 mImpl->RequestRelayout();
967 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
970 if( NULL != mImpl->mEventData )
976 if( NULL != mImpl->mEventData->mPlaceholderFont )
978 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
982 // If the placeholder text font size is not set, then return the default font size.
983 value = GetDefaultFontSize( POINT_SIZE );
989 if( NULL != mImpl->mEventData->mPlaceholderFont )
991 // Pixel size = Point size * DPI / 72.f
992 unsigned int horizontalDpi = 0u;
993 unsigned int verticalDpi = 0u;
994 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
995 fontClient.GetDpi( horizontalDpi, verticalDpi );
997 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1001 // If the placeholder text font size is not set, then return the default font size.
1002 value = GetDefaultFontSize( PIXEL_SIZE );
1013 void Controller::SetDefaultColor( const Vector4& color )
1015 mImpl->mTextColor = color;
1017 if( !mImpl->IsShowingPlaceholderText() )
1019 mImpl->mModel->mVisualModel->SetTextColor( color );
1021 mImpl->RequestRelayout();
1025 const Vector4& Controller::GetDefaultColor() const
1027 return mImpl->mTextColor;
1030 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1032 if( NULL != mImpl->mEventData )
1034 mImpl->mEventData->mPlaceholderTextColor = textColor;
1037 if( mImpl->IsShowingPlaceholderText() )
1039 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1040 mImpl->RequestRelayout();
1044 const Vector4& Controller::GetPlaceholderTextColor() const
1046 if( NULL != mImpl->mEventData )
1048 return mImpl->mEventData->mPlaceholderTextColor;
1051 return Color::BLACK;
1054 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1056 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1058 mImpl->RequestRelayout();
1061 const Vector2& Controller::GetShadowOffset() const
1063 return mImpl->mModel->mVisualModel->GetShadowOffset();
1066 void Controller::SetShadowColor( const Vector4& shadowColor )
1068 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1070 mImpl->RequestRelayout();
1073 const Vector4& Controller::GetShadowColor() const
1075 return mImpl->mModel->mVisualModel->GetShadowColor();
1078 void Controller::SetUnderlineColor( const Vector4& color )
1080 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1082 mImpl->RequestRelayout();
1085 const Vector4& Controller::GetUnderlineColor() const
1087 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1090 void Controller::SetUnderlineEnabled( bool enabled )
1092 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1094 mImpl->RequestRelayout();
1097 bool Controller::IsUnderlineEnabled() const
1099 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1102 void Controller::SetUnderlineHeight( float height )
1104 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1106 mImpl->RequestRelayout();
1109 float Controller::GetUnderlineHeight() const
1111 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1114 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1116 if( NULL == mImpl->mEmbossDefaults )
1118 mImpl->mEmbossDefaults = new EmbossDefaults();
1121 mImpl->mEmbossDefaults->properties = embossProperties;
1124 const std::string& Controller::GetDefaultEmbossProperties() const
1126 if( NULL != mImpl->mEmbossDefaults )
1128 return mImpl->mEmbossDefaults->properties;
1131 return EMPTY_STRING;
1134 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1136 if( NULL == mImpl->mOutlineDefaults )
1138 mImpl->mOutlineDefaults = new OutlineDefaults();
1141 mImpl->mOutlineDefaults->properties = outlineProperties;
1144 const std::string& Controller::GetDefaultOutlineProperties() const
1146 if( NULL != mImpl->mOutlineDefaults )
1148 return mImpl->mOutlineDefaults->properties;
1151 return EMPTY_STRING;
1154 void Controller::SetDefaultLineSpacing( float lineSpacing )
1156 //TODO finish implementation
1157 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1160 float Controller::GetDefaultLineSpacing() const
1162 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1165 void Controller::SetInputColor( const Vector4& color )
1167 if( NULL != mImpl->mEventData )
1169 mImpl->mEventData->mInputStyle.textColor = color;
1170 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1172 if( EventData::SELECTING == mImpl->mEventData->mState )
1174 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1176 // Get start and end position of selection
1177 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1178 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1180 // Add the color run.
1181 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1182 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1184 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1185 colorRun.color = color;
1186 colorRun.characterRun.characterIndex = startOfSelectedText;
1187 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1189 // Request to relayout.
1190 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1191 mImpl->RequestRelayout();
1193 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1194 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1195 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1200 const Vector4& Controller::GetInputColor() const
1202 if( NULL != mImpl->mEventData )
1204 return mImpl->mEventData->mInputStyle.textColor;
1207 // Return the default text's color if there is no EventData.
1208 return mImpl->mTextColor;
1212 void Controller::SetInputFontFamily( const std::string& fontFamily )
1214 if( NULL != mImpl->mEventData )
1216 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1217 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1219 if( EventData::SELECTING == mImpl->mEventData->mState )
1221 CharacterIndex startOfSelectedText = 0u;
1222 Length lengthOfSelectedText = 0u;
1223 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1224 mImpl->mModel->mLogicalModel,
1225 startOfSelectedText,
1226 lengthOfSelectedText );
1228 fontDescriptionRun.familyLength = fontFamily.size();
1229 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1230 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1231 fontDescriptionRun.familyDefined = true;
1233 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1235 // Request to relayout.
1236 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1241 UPDATE_LAYOUT_SIZE |
1244 mImpl->mRecalculateNaturalSize = true;
1245 mImpl->RequestRelayout();
1247 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1248 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1249 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1251 // As the font changes, recalculate the handle positions is needed.
1252 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1253 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1254 mImpl->mEventData->mUpdateHighlightBox = true;
1255 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1260 const std::string& Controller::GetInputFontFamily() const
1262 if( NULL != mImpl->mEventData )
1264 return mImpl->mEventData->mInputStyle.familyName;
1267 // Return the default font's family if there is no EventData.
1268 return GetDefaultFontFamily();
1271 void Controller::SetInputFontWeight( FontWeight weight )
1273 if( NULL != mImpl->mEventData )
1275 mImpl->mEventData->mInputStyle.weight = weight;
1276 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1278 if( EventData::SELECTING == mImpl->mEventData->mState )
1280 CharacterIndex startOfSelectedText = 0u;
1281 Length lengthOfSelectedText = 0u;
1282 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1283 mImpl->mModel->mLogicalModel,
1284 startOfSelectedText,
1285 lengthOfSelectedText );
1287 fontDescriptionRun.weight = weight;
1288 fontDescriptionRun.weightDefined = true;
1290 // Request to relayout.
1291 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1296 UPDATE_LAYOUT_SIZE |
1299 mImpl->mRecalculateNaturalSize = true;
1300 mImpl->RequestRelayout();
1302 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1303 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1304 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1306 // As the font might change, recalculate the handle positions is needed.
1307 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1308 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1309 mImpl->mEventData->mUpdateHighlightBox = true;
1310 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1315 bool Controller::IsInputFontWeightDefined() const
1317 bool defined = false;
1319 if( NULL != mImpl->mEventData )
1321 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1327 FontWeight Controller::GetInputFontWeight() const
1329 if( NULL != mImpl->mEventData )
1331 return mImpl->mEventData->mInputStyle.weight;
1334 return GetDefaultFontWeight();
1337 void Controller::SetInputFontWidth( FontWidth width )
1339 if( NULL != mImpl->mEventData )
1341 mImpl->mEventData->mInputStyle.width = width;
1342 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1344 if( EventData::SELECTING == mImpl->mEventData->mState )
1346 CharacterIndex startOfSelectedText = 0u;
1347 Length lengthOfSelectedText = 0u;
1348 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1349 mImpl->mModel->mLogicalModel,
1350 startOfSelectedText,
1351 lengthOfSelectedText );
1353 fontDescriptionRun.width = width;
1354 fontDescriptionRun.widthDefined = true;
1356 // Request to relayout.
1357 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1362 UPDATE_LAYOUT_SIZE |
1365 mImpl->mRecalculateNaturalSize = true;
1366 mImpl->RequestRelayout();
1368 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1369 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1370 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1372 // As the font might change, recalculate the handle positions is needed.
1373 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1374 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1375 mImpl->mEventData->mUpdateHighlightBox = true;
1376 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1381 bool Controller::IsInputFontWidthDefined() const
1383 bool defined = false;
1385 if( NULL != mImpl->mEventData )
1387 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1393 FontWidth Controller::GetInputFontWidth() const
1395 if( NULL != mImpl->mEventData )
1397 return mImpl->mEventData->mInputStyle.width;
1400 return GetDefaultFontWidth();
1403 void Controller::SetInputFontSlant( FontSlant slant )
1405 if( NULL != mImpl->mEventData )
1407 mImpl->mEventData->mInputStyle.slant = slant;
1408 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1410 if( EventData::SELECTING == mImpl->mEventData->mState )
1412 CharacterIndex startOfSelectedText = 0u;
1413 Length lengthOfSelectedText = 0u;
1414 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1415 mImpl->mModel->mLogicalModel,
1416 startOfSelectedText,
1417 lengthOfSelectedText );
1419 fontDescriptionRun.slant = slant;
1420 fontDescriptionRun.slantDefined = true;
1422 // Request to relayout.
1423 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1428 UPDATE_LAYOUT_SIZE |
1431 mImpl->mRecalculateNaturalSize = true;
1432 mImpl->RequestRelayout();
1434 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1435 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1436 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1438 // As the font might change, recalculate the handle positions is needed.
1439 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1440 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1441 mImpl->mEventData->mUpdateHighlightBox = true;
1442 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1447 bool Controller::IsInputFontSlantDefined() const
1449 bool defined = false;
1451 if( NULL != mImpl->mEventData )
1453 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1459 FontSlant Controller::GetInputFontSlant() const
1461 if( NULL != mImpl->mEventData )
1463 return mImpl->mEventData->mInputStyle.slant;
1466 return GetDefaultFontSlant();
1469 void Controller::SetInputFontPointSize( float size )
1471 if( NULL != mImpl->mEventData )
1473 mImpl->mEventData->mInputStyle.size = size;
1474 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1476 if( EventData::SELECTING == mImpl->mEventData->mState )
1478 CharacterIndex startOfSelectedText = 0u;
1479 Length lengthOfSelectedText = 0u;
1480 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1481 mImpl->mModel->mLogicalModel,
1482 startOfSelectedText,
1483 lengthOfSelectedText );
1485 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1486 fontDescriptionRun.sizeDefined = true;
1488 // Request to relayout.
1489 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1494 UPDATE_LAYOUT_SIZE |
1497 mImpl->mRecalculateNaturalSize = true;
1498 mImpl->RequestRelayout();
1500 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1501 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1502 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1504 // As the font might change, recalculate the handle positions is needed.
1505 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1506 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1507 mImpl->mEventData->mUpdateHighlightBox = true;
1508 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1513 float Controller::GetInputFontPointSize() const
1515 if( NULL != mImpl->mEventData )
1517 return mImpl->mEventData->mInputStyle.size;
1520 // Return the default font's point size if there is no EventData.
1521 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1524 void Controller::SetInputLineSpacing( float lineSpacing )
1526 if( NULL != mImpl->mEventData )
1528 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1529 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1533 float Controller::GetInputLineSpacing() const
1535 if( NULL != mImpl->mEventData )
1537 return mImpl->mEventData->mInputStyle.lineSpacing;
1543 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1545 if( NULL != mImpl->mEventData )
1547 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1551 const std::string& Controller::GetInputShadowProperties() const
1553 if( NULL != mImpl->mEventData )
1555 return mImpl->mEventData->mInputStyle.shadowProperties;
1558 return EMPTY_STRING;
1561 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1563 if( NULL != mImpl->mEventData )
1565 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1569 const std::string& Controller::GetInputUnderlineProperties() const
1571 if( NULL != mImpl->mEventData )
1573 return mImpl->mEventData->mInputStyle.underlineProperties;
1576 return EMPTY_STRING;
1579 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1581 if( NULL != mImpl->mEventData )
1583 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1587 const std::string& Controller::GetInputEmbossProperties() const
1589 if( NULL != mImpl->mEventData )
1591 return mImpl->mEventData->mInputStyle.embossProperties;
1594 return GetDefaultEmbossProperties();
1597 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1599 if( NULL != mImpl->mEventData )
1601 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1605 const std::string& Controller::GetInputOutlineProperties() const
1607 if( NULL != mImpl->mEventData )
1609 return mImpl->mEventData->mInputStyle.outlineProperties;
1612 return GetDefaultOutlineProperties();
1615 void Controller::SetInputModePassword( bool passwordInput )
1617 if( NULL != mImpl->mEventData )
1619 mImpl->mEventData->mPasswordInput = passwordInput;
1623 bool Controller::IsInputModePassword()
1625 if( NULL != mImpl->mEventData )
1627 return mImpl->mEventData->mPasswordInput;
1632 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1634 if( NULL != mImpl->mEventData )
1636 mImpl->mEventData->mDoubleTapAction = action;
1640 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1642 NoTextTap::Action action = NoTextTap::NO_ACTION;
1644 if( NULL != mImpl->mEventData )
1646 action = mImpl->mEventData->mDoubleTapAction;
1652 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1654 if( NULL != mImpl->mEventData )
1656 mImpl->mEventData->mLongPressAction = action;
1660 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1662 NoTextTap::Action action = NoTextTap::NO_ACTION;
1664 if( NULL != mImpl->mEventData )
1666 action = mImpl->mEventData->mLongPressAction;
1672 bool Controller::IsUnderlineSetByString()
1674 return mImpl->mUnderlineSetByString;
1677 void Controller::UnderlineSetByString( bool setByString )
1679 mImpl->mUnderlineSetByString = setByString;
1682 bool Controller::IsShadowSetByString()
1684 return mImpl->mShadowSetByString;
1687 void Controller::ShadowSetByString( bool setByString )
1689 mImpl->mShadowSetByString = setByString;
1692 bool Controller::IsFontStyleSetByString()
1694 return mImpl->mFontStyleSetByString;
1697 void Controller::FontStyleSetByString( bool setByString )
1699 mImpl->mFontStyleSetByString = setByString;
1702 // public : Queries & retrieves.
1704 Layout::Engine& Controller::GetLayoutEngine()
1706 return mImpl->mLayoutEngine;
1709 View& Controller::GetView()
1711 return mImpl->mView;
1714 Vector3 Controller::GetNaturalSize()
1716 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1717 Vector3 naturalSize;
1719 // Make sure the model is up-to-date before layouting
1720 ProcessModifyEvents();
1722 if( mImpl->mRecalculateNaturalSize )
1724 // Operations that can be done only once until the text changes.
1725 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1732 GET_GLYPH_METRICS );
1734 // Set the update info to relayout the whole text.
1735 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1736 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1738 // Make sure the model is up-to-date before layouting
1739 mImpl->UpdateModel( onlyOnceOperations );
1741 // Layout the text for the new width.
1742 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1744 // Store the actual control's size to restore later.
1745 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1747 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1748 static_cast<OperationsMask>( onlyOnceOperations |
1750 naturalSize.GetVectorXY() );
1752 // Do not do again the only once operations.
1753 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1755 // Do the size related operations again.
1756 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1759 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1761 // Stores the natural size to avoid recalculate it again
1762 // unless the text/style changes.
1763 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1765 mImpl->mRecalculateNaturalSize = false;
1767 // Clear the update info. This info will be set the next time the text is updated.
1768 mImpl->mTextUpdateInfo.Clear();
1770 // Restore the actual control's size.
1771 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1773 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1777 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1779 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1782 naturalSize.x = ConvertToEven( naturalSize.x );
1783 naturalSize.y = ConvertToEven( naturalSize.y );
1788 float Controller::GetHeightForWidth( float width )
1790 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1791 // Make sure the model is up-to-date before layouting
1792 ProcessModifyEvents();
1795 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1796 mImpl->mTextUpdateInfo.mFullRelayoutNeeded )
1798 // Operations that can be done only once until the text changes.
1799 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1806 GET_GLYPH_METRICS );
1808 // Set the update info to relayout the whole text.
1809 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1810 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1812 // Make sure the model is up-to-date before layouting
1813 mImpl->UpdateModel( onlyOnceOperations );
1816 // Layout the text for the new width.
1817 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1819 // Store the actual control's width.
1820 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1822 DoRelayout( Size( width, MAX_FLOAT ),
1823 static_cast<OperationsMask>( onlyOnceOperations |
1827 // Do not do again the only once operations.
1828 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1830 // Do the size related operations again.
1831 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1835 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1837 // Clear the update info. This info will be set the next time the text is updated.
1838 mImpl->mTextUpdateInfo.Clear();
1840 // Restore the actual control's width.
1841 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1843 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1847 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1848 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1851 return layoutSize.height;
1854 int Controller::GetLineCount( float width )
1856 GetHeightForWidth( width );
1857 int numberofLines = mImpl->mModel->GetNumberOfLines();
1858 return numberofLines;
1861 const ModelInterface* const Controller::GetTextModel() const
1863 return mImpl->mModel.Get();
1866 float Controller::GetScrollAmountByUserInput()
1868 float scrollAmount = 0.0f;
1870 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1872 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1873 mImpl->mEventData->mCheckScrollAmount = false;
1875 return scrollAmount;
1878 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1880 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1883 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1884 layoutHeight = layout.height;
1885 scrollPosition = mImpl->mModel->mScrollPosition.y;
1886 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1890 void Controller::SetHiddenInputOption(const Property::Map& options )
1892 if( NULL == mImpl->mHiddenInput )
1894 mImpl->mHiddenInput = new HiddenText( this );
1896 mImpl->mHiddenInput->SetProperties(options);
1899 void Controller::GetHiddenInputOption(Property::Map& options )
1901 if( NULL != mImpl->mHiddenInput )
1903 mImpl->mHiddenInput->GetProperties(options);
1907 void Controller::SetPlaceholderProperty( const Property::Map& map )
1909 const Property::Map::SizeType count = map.Count();
1911 for( Property::Map::SizeType position = 0; position < count; ++position )
1913 KeyValuePair keyValue = map.GetKeyValue( position );
1914 Property::Key& key = keyValue.first;
1915 Property::Value& value = keyValue.second;
1917 if( key == PLACEHOLDER_TEXT )
1919 std::string text = "";
1921 SetPlaceholderText( text );
1923 else if( key == PLACEHOLDER_COLOR )
1926 value.Get( textColor );
1927 if( GetPlaceholderTextColor() != textColor )
1929 SetPlaceholderTextColor( textColor );
1932 else if( key == PLACEHOLDER_FONT_FAMILY )
1934 std::string fontFamily = "";
1935 value.Get( fontFamily );
1936 SetPlaceholderFontFamily( fontFamily );
1938 else if( key == PLACEHOLDER_FONT_STYLE )
1940 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
1942 else if( key == PLACEHOLDER_POINT_SIZE )
1945 value.Get( pointSize );
1946 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
1948 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
1951 else if( key == PLACEHOLDER_PIXEL_SIZE )
1954 value.Get( pixelSize );
1955 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
1957 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
1963 void Controller::GetPlaceholderProperty( Property::Map& map )
1965 if( NULL != mImpl->mEventData )
1967 map[ PLACEHOLDER_TEXT ] = mImpl->mEventData->mPlaceholderText;
1968 map[ PLACEHOLDER_COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
1969 map[ PLACEHOLDER_FONT_FAMILY ] = GetPlaceholderFontFamily();
1971 Property::Value fontStyleMapGet;
1972 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
1973 map[ PLACEHOLDER_FONT_STYLE ] = fontStyleMapGet;
1975 // Choose font size : POINT_SIZE or PIXEL_SIZE
1976 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
1978 map[ PLACEHOLDER_POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
1982 map[ PLACEHOLDER_PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
1987 // public : Relayout.
1989 Controller::UpdateTextType Controller::Relayout( const Size& size )
1991 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
1993 UpdateTextType updateTextType = NONE_UPDATED;
1995 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
1997 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
1999 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2000 updateTextType = MODEL_UPDATED;
2003 // Clear the update info. This info will be set the next time the text is updated.
2004 mImpl->mTextUpdateInfo.Clear();
2006 // Not worth to relayout if width or height is equal to zero.
2007 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2009 return updateTextType;
2012 // Whether a new size has been set.
2013 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2017 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2019 // Layout operations that need to be done if the size changes.
2020 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2023 UPDATE_LAYOUT_SIZE |
2025 // Set the update info to relayout the whole text.
2026 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2027 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2029 // Store the size used to layout the text.
2030 mImpl->mModel->mVisualModel->mControlSize = size;
2033 // Whether there are modify events.
2034 if( 0u != mImpl->mModifyEvents.Count() )
2036 // Style operations that need to be done if the text is modified.
2037 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2041 // Make sure the model is up-to-date before layouting.
2042 ProcessModifyEvents();
2043 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2047 updated = DoRelayout( size,
2048 mImpl->mOperationsPending,
2049 layoutSize ) || updated;
2053 updateTextType = MODEL_UPDATED;
2056 // Do not re-do any operation until something changes.
2057 mImpl->mOperationsPending = NO_OPERATION;
2058 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2060 // Whether the text control is editable
2061 const bool isEditable = NULL != mImpl->mEventData;
2063 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2065 if( newSize && isEditable )
2067 offset = mImpl->mModel->mScrollPosition;
2070 if( !isEditable || !IsMultiLineEnabled() )
2072 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2073 CalculateVerticalOffset( size );
2080 // If there is a new size, the scroll position needs to be clamped.
2081 mImpl->ClampHorizontalScroll( layoutSize );
2083 // Update the decorator's positions is needed if there is a new size.
2084 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2087 // Move the cursor, grab handle etc.
2088 if( mImpl->ProcessInputEvents() )
2090 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2094 // Clear the update info. This info will be set the next time the text is updated.
2095 mImpl->mTextUpdateInfo.Clear();
2096 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2098 return updateTextType;
2101 void Controller::RequestRelayout()
2103 mImpl->RequestRelayout();
2106 // public : Input style change signals.
2108 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2110 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2113 void Controller::ProcessInputStyleChangedSignals()
2115 if( NULL == mImpl->mEventData )
2121 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2122 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2126 const InputStyle::Mask mask = *it;
2128 if( NULL != mImpl->mEditableControlInterface )
2130 // Emit the input style changed signal.
2131 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2135 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2138 // public : Text-input Event Queuing.
2140 void Controller::KeyboardFocusGainEvent()
2142 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2144 if( NULL != mImpl->mEventData )
2146 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2147 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2149 mImpl->ChangeState( EventData::EDITING );
2150 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2151 mImpl->mEventData->mUpdateInputStyle = true;
2153 mImpl->NotifyImfMultiLineStatus();
2154 if( mImpl->IsShowingPlaceholderText() )
2156 // Show alternative placeholder-text when editing
2157 ShowPlaceholderText();
2160 mImpl->RequestRelayout();
2164 void Controller::KeyboardFocusLostEvent()
2166 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2168 if( NULL != mImpl->mEventData )
2170 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2172 mImpl->ChangeState( EventData::INACTIVE );
2174 if( !mImpl->IsShowingRealText() )
2176 // Revert to regular placeholder-text when not editing
2177 ShowPlaceholderText();
2181 mImpl->RequestRelayout();
2184 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2186 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2188 bool textChanged = false;
2189 bool relayoutNeeded = false;
2191 if( ( NULL != mImpl->mEventData ) &&
2192 ( keyEvent.state == KeyEvent::Down ) )
2194 int keyCode = keyEvent.keyCode;
2195 const std::string& keyString = keyEvent.keyPressed;
2197 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2199 // Pre-process to separate modifying events from non-modifying input events.
2202 // In some platforms arrive key events with no key code.
2205 else if( Dali::DALI_KEY_ESCAPE == keyCode )
2207 // Escape key is a special case which causes focus loss
2208 KeyboardFocusLostEvent();
2210 // Will request for relayout.
2211 relayoutNeeded = true;
2213 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2214 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2215 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2216 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2218 // If don't have any text, do nothing.
2219 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2224 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2225 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2226 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2227 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2229 // Logic to determine whether this text control will lose focus or not.
2230 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2231 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2232 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2233 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2234 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2235 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2240 mImpl->mEventData->mCheckScrollAmount = true;
2241 Event event( Event::CURSOR_KEY_EVENT );
2242 event.p1.mInt = keyCode;
2243 mImpl->mEventData->mEventQueue.push_back( event );
2245 // Will request for relayout.
2246 relayoutNeeded = true;
2248 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
2250 textChanged = BackspaceKeyEvent();
2252 // Will request for relayout.
2253 relayoutNeeded = true;
2255 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2256 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2257 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2259 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2260 mImpl->ChangeState( EventData::INACTIVE );
2262 // Will request for relayout.
2263 relayoutNeeded = true;
2265 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2267 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2269 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2270 // and a character is typed after the type of a upper case latin character.
2274 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2276 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2281 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2283 // IMF manager is no longer handling key-events
2284 mImpl->ClearPreEditFlag();
2286 InsertText( keyString, COMMIT );
2289 // Will request for relayout.
2290 relayoutNeeded = true;
2293 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2294 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2296 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2297 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2298 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2300 // Should not change the state if the key is the shift send by the imf manager.
2301 // Otherwise, when the state is SELECTING the text controller can't send the right
2302 // surrounding info to the imf.
2303 mImpl->ChangeState( EventData::EDITING );
2305 // Will request for relayout.
2306 relayoutNeeded = true;
2309 if( relayoutNeeded )
2311 mImpl->RequestRelayout();
2316 ( NULL != mImpl->mEditableControlInterface ) )
2318 // Do this last since it provides callbacks into application code
2319 mImpl->mEditableControlInterface->TextChanged();
2325 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2327 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2329 if( NULL != mImpl->mEventData )
2331 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2332 EventData::State state( mImpl->mEventData->mState );
2333 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2335 if( mImpl->IsClipboardVisible() )
2337 if( EventData::INACTIVE == state || EventData::EDITING == state)
2339 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2341 relayoutNeeded = true;
2343 else if( 1u == tapCount )
2345 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2347 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2350 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2352 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2353 relayoutNeeded = true;
2357 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2359 // Hide placeholder text
2363 if( EventData::INACTIVE == state )
2365 mImpl->ChangeState( EventData::EDITING );
2367 else if( !mImpl->IsClipboardEmpty() )
2369 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2371 relayoutNeeded = true;
2374 else if( 2u == tapCount )
2376 if( mImpl->mEventData->mSelectionEnabled &&
2377 mImpl->IsShowingRealText() )
2379 relayoutNeeded = true;
2380 mImpl->mEventData->mIsLeftHandleSelected = true;
2381 mImpl->mEventData->mIsRightHandleSelected = true;
2385 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2386 if( relayoutNeeded )
2388 Event event( Event::TAP_EVENT );
2389 event.p1.mUint = tapCount;
2390 event.p2.mFloat = x;
2391 event.p3.mFloat = y;
2392 mImpl->mEventData->mEventQueue.push_back( event );
2394 mImpl->RequestRelayout();
2398 // Reset keyboard as tap event has occurred.
2399 mImpl->ResetImfManager();
2402 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2404 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2406 if( NULL != mImpl->mEventData )
2408 Event event( Event::PAN_EVENT );
2409 event.p1.mInt = state;
2410 event.p2.mFloat = displacement.x;
2411 event.p3.mFloat = displacement.y;
2412 mImpl->mEventData->mEventQueue.push_back( event );
2414 mImpl->RequestRelayout();
2418 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2420 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2422 if( ( state == Gesture::Started ) &&
2423 ( NULL != mImpl->mEventData ) )
2425 // The 1st long-press on inactive text-field is treated as tap
2426 if( EventData::INACTIVE == mImpl->mEventData->mState )
2428 mImpl->ChangeState( EventData::EDITING );
2430 Event event( Event::TAP_EVENT );
2432 event.p2.mFloat = x;
2433 event.p3.mFloat = y;
2434 mImpl->mEventData->mEventQueue.push_back( event );
2436 mImpl->RequestRelayout();
2438 else if( !mImpl->IsShowingRealText() )
2440 Event event( Event::LONG_PRESS_EVENT );
2441 event.p1.mInt = state;
2442 event.p2.mFloat = x;
2443 event.p3.mFloat = y;
2444 mImpl->mEventData->mEventQueue.push_back( event );
2445 mImpl->RequestRelayout();
2447 else if( !mImpl->IsClipboardVisible() )
2449 // Reset the imf manager to commit the pre-edit before selecting the text.
2450 mImpl->ResetImfManager();
2452 Event event( Event::LONG_PRESS_EVENT );
2453 event.p1.mInt = state;
2454 event.p2.mFloat = x;
2455 event.p3.mFloat = y;
2456 mImpl->mEventData->mEventQueue.push_back( event );
2457 mImpl->RequestRelayout();
2459 mImpl->mEventData->mIsLeftHandleSelected = true;
2460 mImpl->mEventData->mIsRightHandleSelected = true;
2465 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2467 // Whether the text needs to be relaid-out.
2468 bool requestRelayout = false;
2470 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2471 bool retrieveText = false;
2472 bool retrieveCursor = false;
2474 switch( imfEvent.eventName )
2476 case ImfManager::COMMIT:
2478 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2479 requestRelayout = true;
2480 retrieveCursor = true;
2483 case ImfManager::PREEDIT:
2485 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2486 requestRelayout = true;
2487 retrieveCursor = true;
2490 case ImfManager::DELETESURROUNDING:
2492 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2493 imfEvent.numberOfChars,
2494 DONT_UPDATE_INPUT_STYLE );
2498 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2499 !mImpl->IsPlaceholderAvailable() )
2501 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2505 ShowPlaceholderText();
2507 mImpl->mEventData->mUpdateCursorPosition = true;
2508 mImpl->mEventData->mScrollAfterDelete = true;
2510 requestRelayout = true;
2514 case ImfManager::GETSURROUNDING:
2516 retrieveText = true;
2517 retrieveCursor = true;
2520 case ImfManager::PRIVATECOMMAND:
2522 // PRIVATECOMMAND event is just for getting the private command message
2523 retrieveText = true;
2524 retrieveCursor = true;
2527 case ImfManager::VOID:
2534 if( requestRelayout )
2536 mImpl->mOperationsPending = ALL_OPERATIONS;
2537 mImpl->RequestRelayout();
2541 CharacterIndex cursorPosition = 0u;
2542 Length numberOfWhiteSpaces = 0u;
2544 if( retrieveCursor )
2546 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2548 cursorPosition = mImpl->GetLogicalCursorPosition();
2550 if( cursorPosition < numberOfWhiteSpaces )
2552 cursorPosition = 0u;
2556 cursorPosition -= numberOfWhiteSpaces;
2562 mImpl->GetText( numberOfWhiteSpaces, text );
2565 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2567 if( requestRelayout &&
2568 ( NULL != mImpl->mEditableControlInterface ) )
2570 // Do this last since it provides callbacks into application code
2571 mImpl->mEditableControlInterface->TextChanged();
2574 return callbackData;
2577 void Controller::PasteClipboardItemEvent()
2579 // Retrieve the clipboard contents first
2580 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2581 std::string stringToPaste( notifier.GetContent() );
2583 // Commit the current pre-edit text; the contents of the clipboard should be appended
2584 mImpl->ResetImfManager();
2586 // Temporary disable hiding clipboard
2587 mImpl->SetClipboardHideEnable( false );
2590 PasteText( stringToPaste );
2592 mImpl->SetClipboardHideEnable( true );
2595 // protected : Inherit from Text::Decorator::ControllerInterface.
2597 void Controller::GetTargetSize( Vector2& targetSize )
2599 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2602 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2604 if( NULL != mImpl->mEditableControlInterface )
2606 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2610 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2612 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2614 if( NULL != mImpl->mEventData )
2616 switch( handleType )
2620 Event event( Event::GRAB_HANDLE_EVENT );
2621 event.p1.mUint = state;
2622 event.p2.mFloat = x;
2623 event.p3.mFloat = y;
2625 mImpl->mEventData->mEventQueue.push_back( event );
2628 case LEFT_SELECTION_HANDLE:
2630 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2631 event.p1.mUint = state;
2632 event.p2.mFloat = x;
2633 event.p3.mFloat = y;
2635 mImpl->mEventData->mEventQueue.push_back( event );
2638 case RIGHT_SELECTION_HANDLE:
2640 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2641 event.p1.mUint = state;
2642 event.p2.mFloat = x;
2643 event.p3.mFloat = y;
2645 mImpl->mEventData->mEventQueue.push_back( event );
2648 case LEFT_SELECTION_HANDLE_MARKER:
2649 case RIGHT_SELECTION_HANDLE_MARKER:
2651 // Markers do not move the handles.
2654 case HANDLE_TYPE_COUNT:
2656 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2660 mImpl->RequestRelayout();
2664 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2666 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2668 if( NULL == mImpl->mEventData )
2675 case Toolkit::TextSelectionPopup::CUT:
2677 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2678 mImpl->mOperationsPending = ALL_OPERATIONS;
2680 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2681 !mImpl->IsPlaceholderAvailable() )
2683 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2687 ShowPlaceholderText();
2690 mImpl->mEventData->mUpdateCursorPosition = true;
2691 mImpl->mEventData->mScrollAfterDelete = true;
2693 mImpl->RequestRelayout();
2695 if( NULL != mImpl->mEditableControlInterface )
2697 mImpl->mEditableControlInterface->TextChanged();
2701 case Toolkit::TextSelectionPopup::COPY:
2703 mImpl->SendSelectionToClipboard( false ); // Text not modified
2705 mImpl->mEventData->mUpdateCursorPosition = true;
2707 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2710 case Toolkit::TextSelectionPopup::PASTE:
2712 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2715 case Toolkit::TextSelectionPopup::SELECT:
2717 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2719 if( mImpl->mEventData->mSelectionEnabled )
2721 // Creates a SELECT event.
2722 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2726 case Toolkit::TextSelectionPopup::SELECT_ALL:
2728 // Creates a SELECT_ALL event
2729 SelectEvent( 0.f, 0.f, true );
2732 case Toolkit::TextSelectionPopup::CLIPBOARD:
2734 mImpl->ShowClipboard();
2737 case Toolkit::TextSelectionPopup::NONE:
2745 void Controller::DisplayTimeExpired()
2747 mImpl->mEventData->mUpdateCursorPosition = true;
2748 // Apply modifications to the model
2749 mImpl->mOperationsPending = ALL_OPERATIONS;
2751 mImpl->RequestRelayout();
2754 // private : Update.
2756 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2758 bool removedPrevious = false;
2759 bool removedSelected = false;
2760 bool maxLengthReached = false;
2762 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2764 if( NULL == mImpl->mEventData )
2769 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2770 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2771 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2773 // TODO: At the moment the underline runs are only for pre-edit.
2774 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2776 // Remove the previous IMF pre-edit.
2777 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2779 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2780 mImpl->mEventData->mPreEditLength,
2781 DONT_UPDATE_INPUT_STYLE );
2783 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2784 mImpl->mEventData->mPreEditLength = 0u;
2788 // Remove the previous Selection.
2789 removedSelected = RemoveSelectedText();
2793 Vector<Character> utf32Characters;
2794 Length characterCount = 0u;
2798 // Convert text into UTF-32
2799 utf32Characters.Resize( text.size() );
2801 // This is a bit horrible but std::string returns a (signed) char*
2802 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2804 // Transform a text array encoded in utf8 into an array encoded in utf32.
2805 // It returns the actual number of characters.
2806 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2807 utf32Characters.Resize( characterCount );
2809 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2810 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2813 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2815 // The placeholder text is no longer needed
2816 if( mImpl->IsShowingPlaceholderText() )
2821 mImpl->ChangeState( EventData::EDITING );
2823 // Handle the IMF (predicitive text) state changes
2824 if( COMMIT == type )
2826 // IMF manager is no longer handling key-events
2827 mImpl->ClearPreEditFlag();
2831 if( !mImpl->mEventData->mPreEditFlag )
2833 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2835 // Record the start of the pre-edit text
2836 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2839 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2840 mImpl->mEventData->mPreEditFlag = true;
2842 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2845 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2847 // Restrict new text to fit within Maximum characters setting.
2848 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2849 maxLengthReached = ( characterCount > maxSizeOfNewText );
2851 // The cursor position.
2852 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2854 // Update the text's style.
2856 // Updates the text style runs by adding characters.
2857 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2859 // Get the character index from the cursor index.
2860 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2862 // Retrieve the text's style for the given index.
2864 mImpl->RetrieveDefaultInputStyle( style );
2865 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2867 // Whether to add a new text color run.
2868 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2870 // Whether to add a new font run.
2871 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2872 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2873 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2874 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2875 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2880 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2881 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2883 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2884 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2885 colorRun.characterRun.characterIndex = cursorIndex;
2886 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2889 if( addFontNameRun ||
2895 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2896 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2898 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2900 if( addFontNameRun )
2902 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2903 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2904 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2905 fontDescriptionRun.familyDefined = true;
2907 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2910 if( addFontWeightRun )
2912 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2913 fontDescriptionRun.weightDefined = true;
2916 if( addFontWidthRun )
2918 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2919 fontDescriptionRun.widthDefined = true;
2922 if( addFontSlantRun )
2924 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2925 fontDescriptionRun.slantDefined = true;
2928 if( addFontSizeRun )
2930 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2931 fontDescriptionRun.sizeDefined = true;
2934 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2935 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2938 // Insert at current cursor position.
2939 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2941 if( cursorIndex < numberOfCharactersInModel )
2943 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2947 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2950 // Mark the first paragraph to be updated.
2951 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
2953 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
2954 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2955 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
2956 mImpl->mTextUpdateInfo.mClearAll = true;
2960 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2961 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2964 // Update the cursor index.
2965 cursorIndex += maxSizeOfNewText;
2967 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 );
2970 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
2971 mImpl->IsPlaceholderAvailable() )
2973 // Show place-holder if empty after removing the pre-edit text
2974 ShowPlaceholderText();
2975 mImpl->mEventData->mUpdateCursorPosition = true;
2976 mImpl->ClearPreEditFlag();
2978 else if( removedPrevious ||
2980 ( 0 != utf32Characters.Count() ) )
2982 // Queue an inserted event
2983 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
2985 mImpl->mEventData->mUpdateCursorPosition = true;
2986 if( removedSelected )
2988 mImpl->mEventData->mScrollAfterDelete = true;
2992 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2996 if( maxLengthReached )
2998 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3000 mImpl->ResetImfManager();
3002 if( NULL != mImpl->mEditableControlInterface )
3004 // Do this last since it provides callbacks into application code
3005 mImpl->mEditableControlInterface->MaxLengthReached();
3010 void Controller::PasteText( const std::string& stringToPaste )
3012 InsertText( stringToPaste, Text::Controller::COMMIT );
3013 mImpl->ChangeState( EventData::EDITING );
3014 mImpl->RequestRelayout();
3016 if( NULL != mImpl->mEditableControlInterface )
3018 // Do this last since it provides callbacks into application code
3019 mImpl->mEditableControlInterface->TextChanged();
3023 bool Controller::RemoveText( int cursorOffset,
3024 int numberOfCharacters,
3025 UpdateInputStyleType type )
3027 bool removed = false;
3029 if( NULL == mImpl->mEventData )
3034 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3035 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3037 if( !mImpl->IsShowingPlaceholderText() )
3039 // Delete at current cursor position
3040 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3041 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3043 CharacterIndex cursorIndex = 0;
3045 // Validate the cursor position & number of characters
3046 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3048 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3051 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3053 numberOfCharacters = currentText.Count() - cursorIndex;
3056 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.
3057 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3059 // Mark the paragraphs to be updated.
3060 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3062 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3063 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3064 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3065 mImpl->mTextUpdateInfo.mClearAll = true;
3069 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3070 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3073 // Update the input style and remove the text's style before removing the text.
3075 if( UPDATE_INPUT_STYLE == type )
3077 // Keep a copy of the current input style.
3078 InputStyle currentInputStyle;
3079 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3081 // Set first the default input style.
3082 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3084 // Update the input style.
3085 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3087 // Compare if the input style has changed.
3088 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3090 if( hasInputStyleChanged )
3092 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3093 // Queue the input style changed signal.
3094 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3098 // Updates the text style runs by removing characters. Runs with no characters are removed.
3099 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3101 // Remove the characters.
3102 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3103 Vector<Character>::Iterator last = first + numberOfCharacters;
3105 currentText.Erase( first, last );
3107 // Cursor position retreat
3108 oldCursorIndex = cursorIndex;
3110 mImpl->mEventData->mScrollAfterDelete = true;
3112 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3120 bool Controller::RemoveSelectedText()
3122 bool textRemoved( false );
3124 if( EventData::SELECTING == mImpl->mEventData->mState )
3126 std::string removedString;
3127 mImpl->RetrieveSelection( removedString, true );
3129 if( !removedString.empty() )
3132 mImpl->ChangeState( EventData::EDITING );
3139 // private : Relayout.
3141 bool Controller::DoRelayout( const Size& size,
3142 OperationsMask operationsRequired,
3145 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3146 bool viewUpdated( false );
3148 // Calculate the operations to be done.
3149 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3151 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3152 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3154 // Get the current layout size.
3155 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3157 if( NO_OPERATION != ( LAYOUT & operations ) )
3159 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3161 // Some vectors with data needed to layout and reorder may be void
3162 // after the first time the text has been laid out.
3163 // Fill the vectors again.
3165 // Calculate the number of glyphs to layout.
3166 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3167 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3168 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3169 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3171 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3172 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3173 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3174 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3176 if( 0u == totalNumberOfGlyphs )
3178 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3180 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3183 // Nothing else to do if there is no glyphs.
3184 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3188 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3189 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3190 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3191 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3192 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3193 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3194 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3196 // Set the layout parameters.
3197 Layout::Parameters layoutParameters( size,
3199 lineBreakInfo.Begin(),
3200 wordBreakInfo.Begin(),
3201 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3203 glyphsToCharactersMap.Begin(),
3204 charactersPerGlyph.Begin(),
3205 charactersToGlyphBuffer,
3206 glyphsPerCharacterBuffer,
3207 totalNumberOfGlyphs,
3208 mImpl->mModel->mHorizontalAlignment );
3210 // Resize the vector of positions to have the same size than the vector of glyphs.
3211 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3212 glyphPositions.Resize( totalNumberOfGlyphs );
3214 // Whether the last character is a new paragraph character.
3215 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3216 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3218 // The initial glyph and the number of glyphs to layout.
3219 layoutParameters.startGlyphIndex = startGlyphIndex;
3220 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3221 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3222 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3224 // Update the visual model.
3226 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3228 mImpl->mModel->mVisualModel->mLines,
3230 mImpl->mModel->mElideEnabled );
3232 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3236 layoutSize = newLayoutSize;
3238 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3240 mImpl->mAutoScrollDirectionRTL = false;
3243 // Reorder the lines
3244 if( NO_OPERATION != ( REORDER & operations ) )
3246 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3247 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3249 // Check first if there are paragraphs with bidirectional info.
3250 if( 0u != bidirectionalInfo.Count() )
3253 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3255 // Reorder the lines.
3256 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3257 ReorderLines( bidirectionalInfo,
3259 requestedNumberOfCharacters,
3260 mImpl->mModel->mVisualModel->mLines,
3261 bidirectionalLineInfo );
3263 // Set the bidirectional info per line into the layout parameters.
3264 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3265 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3267 // Re-layout the text. Reorder those lines with right to left characters.
3268 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3270 requestedNumberOfCharacters,
3273 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3275 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3278 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3284 // Sets the layout size.
3285 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3287 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3292 if( NO_OPERATION != ( ALIGN & operations ) )
3294 // The laid-out lines.
3295 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3297 // Need to align with the control's size as the text may contain lines
3298 // starting either with left to right text or right to left.
3299 mImpl->mLayoutEngine.Align( size,
3301 requestedNumberOfCharacters,
3302 mImpl->mModel->mHorizontalAlignment,
3304 mImpl->mModel->mAlignmentOffset );
3308 #if defined(DEBUG_ENABLED)
3309 std::string currentText;
3310 GetText( currentText );
3311 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3313 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3317 void Controller::CalculateVerticalOffset( const Size& controlSize )
3319 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3321 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3323 // Get the line height of the default font.
3324 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3327 switch( mImpl->mModel->mVerticalAlignment )
3329 case Layout::VERTICAL_ALIGN_TOP:
3331 mImpl->mModel->mScrollPosition.y = 0.f;
3334 case Layout::VERTICAL_ALIGN_CENTER:
3336 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3339 case Layout::VERTICAL_ALIGN_BOTTOM:
3341 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3347 // private : Events.
3349 void Controller::ProcessModifyEvents()
3351 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3353 if( 0u == events.Count() )
3359 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3360 endIt = events.End();
3364 const ModifyEvent& event = *it;
3366 if( ModifyEvent::TEXT_REPLACED == event.type )
3368 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3369 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3371 TextReplacedEvent();
3373 else if( ModifyEvent::TEXT_INSERTED == event.type )
3375 TextInsertedEvent();
3377 else if( ModifyEvent::TEXT_DELETED == event.type )
3379 // Placeholder-text cannot be deleted
3380 if( !mImpl->IsShowingPlaceholderText() )
3387 if( NULL != mImpl->mEventData )
3389 // When the text is being modified, delay cursor blinking
3390 mImpl->mEventData->mDecorator->DelayCursorBlink();
3393 // Discard temporary text
3397 void Controller::TextReplacedEvent()
3399 // The natural size needs to be re-calculated.
3400 mImpl->mRecalculateNaturalSize = true;
3402 // Apply modifications to the model
3403 mImpl->mOperationsPending = ALL_OPERATIONS;
3406 void Controller::TextInsertedEvent()
3408 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3410 if( NULL == mImpl->mEventData )
3415 mImpl->mEventData->mCheckScrollAmount = true;
3417 // The natural size needs to be re-calculated.
3418 mImpl->mRecalculateNaturalSize = true;
3420 // Apply modifications to the model; TODO - Optimize this
3421 mImpl->mOperationsPending = ALL_OPERATIONS;
3424 void Controller::TextDeletedEvent()
3426 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3428 if( NULL == mImpl->mEventData )
3433 mImpl->mEventData->mCheckScrollAmount = true;
3435 // The natural size needs to be re-calculated.
3436 mImpl->mRecalculateNaturalSize = true;
3438 // Apply modifications to the model; TODO - Optimize this
3439 mImpl->mOperationsPending = ALL_OPERATIONS;
3442 void Controller::SelectEvent( float x, float y, bool selectAll )
3444 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3446 if( NULL != mImpl->mEventData )
3450 Event event( Event::SELECT_ALL );
3451 mImpl->mEventData->mEventQueue.push_back( event );
3455 Event event( Event::SELECT );
3456 event.p2.mFloat = x;
3457 event.p3.mFloat = y;
3458 mImpl->mEventData->mEventQueue.push_back( event );
3461 mImpl->mEventData->mCheckScrollAmount = true;
3462 mImpl->mEventData->mIsLeftHandleSelected = true;
3463 mImpl->mEventData->mIsRightHandleSelected = true;
3464 mImpl->RequestRelayout();
3468 bool Controller::BackspaceKeyEvent()
3470 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3472 bool removed = false;
3474 if( NULL == mImpl->mEventData )
3479 // IMF manager is no longer handling key-events
3480 mImpl->ClearPreEditFlag();
3482 if( EventData::SELECTING == mImpl->mEventData->mState )
3484 removed = RemoveSelectedText();
3486 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3488 // Remove the character before the current cursor position
3489 removed = RemoveText( -1,
3491 UPDATE_INPUT_STYLE );
3496 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3497 !mImpl->IsPlaceholderAvailable() )
3499 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3503 ShowPlaceholderText();
3505 mImpl->mEventData->mUpdateCursorPosition = true;
3506 mImpl->mEventData->mScrollAfterDelete = true;
3512 // private : Helpers.
3514 void Controller::ResetText()
3517 mImpl->mModel->mLogicalModel->mText.Clear();
3519 // We have cleared everything including the placeholder-text
3520 mImpl->PlaceholderCleared();
3522 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3523 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3524 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3526 // Clear any previous text.
3527 mImpl->mTextUpdateInfo.mClearAll = true;
3529 // The natural size needs to be re-calculated.
3530 mImpl->mRecalculateNaturalSize = true;
3532 // Apply modifications to the model
3533 mImpl->mOperationsPending = ALL_OPERATIONS;
3536 void Controller::ShowPlaceholderText()
3538 if( mImpl->IsPlaceholderAvailable() )
3540 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3542 if( NULL == mImpl->mEventData )
3547 mImpl->mEventData->mIsShowingPlaceholderText = true;
3549 // Disable handles when showing place-holder text
3550 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3551 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3552 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3554 const char* text( NULL );
3557 if( !mImpl->mEventData->mPlaceholderTextActive.empty() || !mImpl->mEventData->mPlaceholderTextInactive.empty() )
3559 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3560 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3562 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3563 size = mImpl->mEventData->mPlaceholderTextActive.size();
3567 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3568 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3573 if( 0u != mImpl->mEventData->mPlaceholderText.c_str() )
3575 text = mImpl->mEventData->mPlaceholderText.c_str();
3576 size = mImpl->mEventData->mPlaceholderText.size();
3580 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3581 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3583 // Reset model for showing placeholder.
3584 mImpl->mModel->mLogicalModel->mText.Clear();
3585 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3587 // Convert text into UTF-32
3588 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3589 utf32Characters.Resize( size );
3591 // This is a bit horrible but std::string returns a (signed) char*
3592 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3594 // Transform a text array encoded in utf8 into an array encoded in utf32.
3595 // It returns the actual number of characters.
3596 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3597 utf32Characters.Resize( characterCount );
3599 // The characters to be added.
3600 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3602 // Reset the cursor position
3603 mImpl->mEventData->mPrimaryCursorPosition = 0;
3605 // The natural size needs to be re-calculated.
3606 mImpl->mRecalculateNaturalSize = true;
3608 // Apply modifications to the model
3609 mImpl->mOperationsPending = ALL_OPERATIONS;
3611 // Update the rest of the model during size negotiation
3612 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3616 void Controller::ClearFontData()
3618 if( mImpl->mFontDefaults )
3620 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3623 // Set flags to update the model.
3624 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3625 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3626 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3628 mImpl->mTextUpdateInfo.mClearAll = true;
3629 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3630 mImpl->mRecalculateNaturalSize = true;
3632 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3637 UPDATE_LAYOUT_SIZE |
3642 void Controller::ClearStyleData()
3644 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3645 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3648 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3650 // Reset the cursor position
3651 if( NULL != mImpl->mEventData )
3653 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3655 // Update the cursor if it's in editing mode.
3656 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3658 mImpl->mEventData->mUpdateCursorPosition = true;
3663 void Controller::ResetScrollPosition()
3665 if( NULL != mImpl->mEventData )
3667 // Reset the scroll position.
3668 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3669 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3673 // private : Private contructors & copy operator.
3675 Controller::Controller()
3678 mImpl = new Controller::Impl( NULL, NULL );
3681 Controller::Controller( ControlInterface* controlInterface )
3683 mImpl = new Controller::Impl( controlInterface, NULL );
3686 Controller::Controller( ControlInterface* controlInterface,
3687 EditableControlInterface* editableControlInterface )
3689 mImpl = new Controller::Impl( controlInterface,
3690 editableControlInterface );
3693 // The copy constructor and operator are left unimplemented.
3695 // protected : Destructor.
3697 Controller::~Controller()
3704 } // namespace Toolkit