2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
28 #include <dali/devel-api/adaptor-framework/key-devel.h>
31 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
32 #include <dali-toolkit/internal/text/bidirectional-support.h>
33 #include <dali-toolkit/internal/text/character-set-conversion.h>
34 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
35 #include <dali-toolkit/internal/text/markup-processor.h>
36 #include <dali-toolkit/internal/text/multi-language-support.h>
37 #include <dali-toolkit/internal/text/text-controller-impl.h>
38 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
39 #include <dali-toolkit/internal/text/text-font-style.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
48 const float MAX_FLOAT = std::numeric_limits<float>::max();
50 const std::string EMPTY_STRING("");
52 const std::string KEY_C_NAME = "c";
53 const std::string KEY_V_NAME = "v";
54 const std::string KEY_X_NAME = "x";
56 const char * const PLACEHOLDER_TEXT = "text";
57 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
58 const char * const PLACEHOLDER_COLOR = "color";
59 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
60 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
61 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
62 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
63 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 float ConvertToEven( float value )
67 int intValue(static_cast<int>( value ));
68 return static_cast<float>( intValue + ( intValue & 1 ) );
83 * @brief Adds a new font description run for the selected text.
85 * The new font parameters are added after the call to this method.
87 * @param[in] eventData The event data pointer.
88 * @param[in] logicalModel The logical model where to add the new font description run.
89 * @param[out] startOfSelectedText Index to the first selected character.
90 * @param[out] lengthOfSelectedText Number of selected characters.
92 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
93 LogicalModelPtr logicalModel,
94 CharacterIndex& startOfSelectedText,
95 Length& lengthOfSelectedText )
97 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
99 // Get start and end position of selection
100 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
101 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
104 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
105 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
107 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
109 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
110 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
112 // Recalculate the selection highlight as the metrics may have changed.
113 eventData->mUpdateLeftSelectionPosition = true;
114 eventData->mUpdateRightSelectionPosition = true;
115 eventData->mUpdateHighlightBox = true;
117 return fontDescriptionRun;
120 // public : Constructor.
122 ControllerPtr Controller::New()
124 return ControllerPtr( new Controller() );
127 ControllerPtr Controller::New( ControlInterface* controlInterface )
129 return ControllerPtr( new Controller( controlInterface ) );
132 ControllerPtr Controller::New( ControlInterface* controlInterface,
133 EditableControlInterface* editableControlInterface )
135 return ControllerPtr( new Controller( controlInterface,
136 editableControlInterface ) );
139 // public : Configure the text controller.
141 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
145 delete mImpl->mEventData;
146 mImpl->mEventData = NULL;
148 // Nothing else to do.
152 if( NULL == mImpl->mEventData )
154 mImpl->mEventData = new EventData( decorator, inputMethodContext );
158 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
160 // Metrics for bitmap & vector based glyphs are different
161 mImpl->mMetrics->SetGlyphType( glyphType );
163 // Clear the font-specific data
166 mImpl->RequestRelayout();
169 void Controller::SetMarkupProcessorEnabled( bool enable )
171 if( enable != mImpl->mMarkupProcessorEnabled )
173 //If Text was already set, call the SetText again for enabling or disabling markup
174 mImpl->mMarkupProcessorEnabled = enable;
181 bool Controller::IsMarkupProcessorEnabled() const
183 return mImpl->mMarkupProcessorEnabled;
186 void Controller::SetAutoScrollEnabled( bool enable )
188 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 );
190 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
194 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
195 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
205 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
206 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
213 mImpl->mIsAutoScrollEnabled = enable;
214 mImpl->RequestRelayout();
218 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
219 mImpl->mIsAutoScrollEnabled = false;
223 bool Controller::IsAutoScrollEnabled() const
225 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
227 return mImpl->mIsAutoScrollEnabled;
230 CharacterDirection Controller::GetAutoScrollDirection() const
232 return mImpl->mIsTextDirectionRTL;
235 float Controller::GetAutoScrollLineAlignment() const
239 if( mImpl->mModel->mVisualModel &&
240 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
242 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
248 void Controller::SetHorizontalScrollEnabled( bool enable )
250 if( ( NULL != mImpl->mEventData ) &&
251 mImpl->mEventData->mDecorator )
253 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
256 bool Controller::IsHorizontalScrollEnabled() const
258 if( ( NULL != mImpl->mEventData ) &&
259 mImpl->mEventData->mDecorator )
261 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
267 void Controller::SetVerticalScrollEnabled( bool enable )
269 if( ( NULL != mImpl->mEventData ) &&
270 mImpl->mEventData->mDecorator )
272 if( mImpl->mEventData->mDecorator )
274 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
279 bool Controller::IsVerticalScrollEnabled() const
281 if( ( NULL != mImpl->mEventData ) &&
282 mImpl->mEventData->mDecorator )
284 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
290 void Controller::SetSmoothHandlePanEnabled( bool enable )
292 if( ( NULL != mImpl->mEventData ) &&
293 mImpl->mEventData->mDecorator )
295 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
299 bool Controller::IsSmoothHandlePanEnabled() const
301 if( ( NULL != mImpl->mEventData ) &&
302 mImpl->mEventData->mDecorator )
304 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
310 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
312 mImpl->mMaximumNumberOfCharacters = maxCharacters;
315 int Controller::GetMaximumNumberOfCharacters()
317 return mImpl->mMaximumNumberOfCharacters;
320 void Controller::SetEnableCursorBlink( bool enable )
322 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
324 if( NULL != mImpl->mEventData )
326 mImpl->mEventData->mCursorBlinkEnabled = enable;
329 mImpl->mEventData->mDecorator )
331 mImpl->mEventData->mDecorator->StopCursorBlink();
336 bool Controller::GetEnableCursorBlink() const
338 if( NULL != mImpl->mEventData )
340 return mImpl->mEventData->mCursorBlinkEnabled;
346 void Controller::SetMultiLineEnabled( bool enable )
348 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
350 if( layout != mImpl->mLayoutEngine.GetLayout() )
352 // Set the layout type.
353 mImpl->mLayoutEngine.SetLayout( layout );
355 // Set the flags to redo the layout operations
356 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
361 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
362 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
364 // Need to recalculate natural size
365 mImpl->mRecalculateNaturalSize = true;
367 mImpl->RequestRelayout();
371 bool Controller::IsMultiLineEnabled() const
373 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
376 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
378 if( alignment != mImpl->mModel->mHorizontalAlignment )
380 // Set the alignment.
381 mImpl->mModel->mHorizontalAlignment = alignment;
383 // Set the flag to redo the alignment operation.
384 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
386 mImpl->RequestRelayout();
390 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
392 return mImpl->mModel->mHorizontalAlignment;
395 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
397 if( alignment != mImpl->mModel->mVerticalAlignment )
399 // Set the alignment.
400 mImpl->mModel->mVerticalAlignment = alignment;
402 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
404 mImpl->RequestRelayout();
408 VerticalAlignment::Type Controller::GetVerticalAlignment() const
410 return mImpl->mModel->mVerticalAlignment;
413 bool Controller::IsIgnoreSpacesAfterText() const
415 return mImpl->mModel->mIgnoreSpacesAfterText;
418 void Controller::SetIgnoreSpacesAfterText( bool ignore )
420 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
423 bool Controller::IsMatchSystemLanguageDirection() const
425 return mImpl->mModel->mMatchSystemLanguageDirection;
428 void Controller::SetMatchSystemLanguageDirection( bool match )
430 mImpl->mModel->mMatchSystemLanguageDirection = match;
433 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
435 mImpl->mLayoutDirection = layoutDirection;
439 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
441 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
443 // Set the text wrap mode.
444 mImpl->mModel->mLineWrapMode = lineWrapMode;
447 // Update Text layout for applying wrap mode
448 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
453 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
454 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
455 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
458 mImpl->RequestRelayout();
462 Text::LineWrap::Mode Controller::GetLineWrapMode() const
464 return mImpl->mModel->mLineWrapMode;
467 void Controller::SetTextElideEnabled( bool enabled )
469 mImpl->mModel->mElideEnabled = enabled;
472 bool Controller::IsTextElideEnabled() const
474 return mImpl->mModel->mElideEnabled;
477 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
479 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
480 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
482 // Update placeholder if there is no text
483 if( mImpl->IsShowingPlaceholderText() ||
484 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
486 ShowPlaceholderText();
490 bool Controller::IsPlaceholderTextElideEnabled() const
492 return mImpl->mEventData->mIsPlaceholderElideEnabled;
495 void Controller::SetSelectionEnabled( bool enabled )
497 mImpl->mEventData->mSelectionEnabled = enabled;
500 bool Controller::IsSelectionEnabled() const
502 return mImpl->mEventData->mSelectionEnabled;
505 void Controller::SetShiftSelectionEnabled( bool enabled )
507 mImpl->mEventData->mShiftSelectionFlag = enabled;
510 bool Controller::IsShiftSelectionEnabled() const
512 return mImpl->mEventData->mShiftSelectionFlag;
515 void Controller::SetGrabHandleEnabled( bool enabled )
517 mImpl->mEventData->mGrabHandleEnabled = enabled;
520 bool Controller::IsGrabHandleEnabled() const
522 return mImpl->mEventData->mGrabHandleEnabled;
527 void Controller::SetText( const std::string& text )
529 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
531 // Reset keyboard as text changed
532 mImpl->ResetInputMethodContext();
534 // Remove the previously set text and style.
540 CharacterIndex lastCursorIndex = 0u;
542 if( NULL != mImpl->mEventData )
544 // If popup shown then hide it by switching to Editing state
545 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
546 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
547 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
548 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
550 mImpl->ChangeState( EventData::EDITING );
556 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
558 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
559 mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
560 mImpl->mModel->mLogicalModel->mEmbeddedItems );
562 Length textSize = 0u;
563 const uint8_t* utf8 = NULL;
564 if( mImpl->mMarkupProcessorEnabled )
566 ProcessMarkupString( text, markupProcessData );
567 textSize = markupProcessData.markupProcessedText.size();
569 // This is a bit horrible but std::string returns a (signed) char*
570 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
574 textSize = text.size();
576 // This is a bit horrible but std::string returns a (signed) char*
577 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
580 // Convert text into UTF-32
581 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
582 utf32Characters.Resize( textSize );
584 // Transform a text array encoded in utf8 into an array encoded in utf32.
585 // It returns the actual number of characters.
586 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
587 utf32Characters.Resize( characterCount );
589 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
590 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
592 // The characters to be added.
593 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
595 // To reset the cursor position
596 lastCursorIndex = characterCount;
598 // Update the rest of the model during size negotiation
599 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
601 // The natural size needs to be re-calculated.
602 mImpl->mRecalculateNaturalSize = true;
604 // The text direction needs to be updated.
605 mImpl->mUpdateTextDirection = true;
607 // Apply modifications to the model
608 mImpl->mOperationsPending = ALL_OPERATIONS;
612 ShowPlaceholderText();
615 // Resets the cursor position.
616 ResetCursorPosition( lastCursorIndex );
618 // Scrolls the text to make the cursor visible.
619 ResetScrollPosition();
621 mImpl->RequestRelayout();
623 if( NULL != mImpl->mEventData )
625 // Cancel previously queued events
626 mImpl->mEventData->mEventQueue.clear();
629 // Do this last since it provides callbacks into application code.
630 if( NULL != mImpl->mEditableControlInterface )
632 mImpl->mEditableControlInterface->TextChanged();
636 void Controller::GetText( std::string& text ) const
638 if( !mImpl->IsShowingPlaceholderText() )
640 // Retrieves the text string.
641 mImpl->GetText( 0u, text );
645 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
649 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
651 if( NULL != mImpl->mEventData )
653 if( PLACEHOLDER_TYPE_INACTIVE == type )
655 mImpl->mEventData->mPlaceholderTextInactive = text;
659 mImpl->mEventData->mPlaceholderTextActive = text;
662 // Update placeholder if there is no text
663 if( mImpl->IsShowingPlaceholderText() ||
664 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
666 ShowPlaceholderText();
671 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
673 if( NULL != mImpl->mEventData )
675 if( PLACEHOLDER_TYPE_INACTIVE == type )
677 text = mImpl->mEventData->mPlaceholderTextInactive;
681 text = mImpl->mEventData->mPlaceholderTextActive;
686 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
688 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
690 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
692 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
693 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
697 mImpl->RequestRelayout();
701 // public : Default style & Input style
703 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
705 if( NULL == mImpl->mFontDefaults )
707 mImpl->mFontDefaults = new FontDefaults();
710 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
711 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
712 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
714 // Clear the font-specific data
717 mImpl->RequestRelayout();
720 const std::string& Controller::GetDefaultFontFamily() const
722 if( NULL != mImpl->mFontDefaults )
724 return mImpl->mFontDefaults->mFontDescription.family;
730 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
732 if( NULL != mImpl->mEventData )
734 if( NULL == mImpl->mEventData->mPlaceholderFont )
736 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
739 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
740 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
741 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
743 mImpl->RequestRelayout();
747 const std::string& Controller::GetPlaceholderFontFamily() const
749 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
751 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
757 void Controller::SetDefaultFontWeight( FontWeight weight )
759 if( NULL == mImpl->mFontDefaults )
761 mImpl->mFontDefaults = new FontDefaults();
764 mImpl->mFontDefaults->mFontDescription.weight = weight;
765 mImpl->mFontDefaults->weightDefined = true;
767 // Clear the font-specific data
770 mImpl->RequestRelayout();
773 bool Controller::IsDefaultFontWeightDefined() const
775 if( NULL != mImpl->mFontDefaults )
777 return mImpl->mFontDefaults->weightDefined;
783 FontWeight Controller::GetDefaultFontWeight() const
785 if( NULL != mImpl->mFontDefaults )
787 return mImpl->mFontDefaults->mFontDescription.weight;
790 return TextAbstraction::FontWeight::NORMAL;
793 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
795 if( NULL != mImpl->mEventData )
797 if( NULL == mImpl->mEventData->mPlaceholderFont )
799 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
802 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
803 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
805 mImpl->RequestRelayout();
809 bool Controller::IsPlaceholderTextFontWeightDefined() const
811 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
813 return mImpl->mEventData->mPlaceholderFont->weightDefined;
818 FontWeight Controller::GetPlaceholderTextFontWeight() const
820 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
822 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
825 return TextAbstraction::FontWeight::NORMAL;
828 void Controller::SetDefaultFontWidth( FontWidth width )
830 if( NULL == mImpl->mFontDefaults )
832 mImpl->mFontDefaults = new FontDefaults();
835 mImpl->mFontDefaults->mFontDescription.width = width;
836 mImpl->mFontDefaults->widthDefined = true;
838 // Clear the font-specific data
841 mImpl->RequestRelayout();
844 bool Controller::IsDefaultFontWidthDefined() const
846 if( NULL != mImpl->mFontDefaults )
848 return mImpl->mFontDefaults->widthDefined;
854 FontWidth Controller::GetDefaultFontWidth() const
856 if( NULL != mImpl->mFontDefaults )
858 return mImpl->mFontDefaults->mFontDescription.width;
861 return TextAbstraction::FontWidth::NORMAL;
864 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
866 if( NULL != mImpl->mEventData )
868 if( NULL == mImpl->mEventData->mPlaceholderFont )
870 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
873 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
874 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
876 mImpl->RequestRelayout();
880 bool Controller::IsPlaceholderTextFontWidthDefined() const
882 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
884 return mImpl->mEventData->mPlaceholderFont->widthDefined;
889 FontWidth Controller::GetPlaceholderTextFontWidth() const
891 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
893 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
896 return TextAbstraction::FontWidth::NORMAL;
899 void Controller::SetDefaultFontSlant( FontSlant slant )
901 if( NULL == mImpl->mFontDefaults )
903 mImpl->mFontDefaults = new FontDefaults();
906 mImpl->mFontDefaults->mFontDescription.slant = slant;
907 mImpl->mFontDefaults->slantDefined = true;
909 // Clear the font-specific data
912 mImpl->RequestRelayout();
915 bool Controller::IsDefaultFontSlantDefined() const
917 if( NULL != mImpl->mFontDefaults )
919 return mImpl->mFontDefaults->slantDefined;
924 FontSlant Controller::GetDefaultFontSlant() const
926 if( NULL != mImpl->mFontDefaults )
928 return mImpl->mFontDefaults->mFontDescription.slant;
931 return TextAbstraction::FontSlant::NORMAL;
934 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
936 if( NULL != mImpl->mEventData )
938 if( NULL == mImpl->mEventData->mPlaceholderFont )
940 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
943 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
944 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
946 mImpl->RequestRelayout();
950 bool Controller::IsPlaceholderTextFontSlantDefined() const
952 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
954 return mImpl->mEventData->mPlaceholderFont->slantDefined;
959 FontSlant Controller::GetPlaceholderTextFontSlant() const
961 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
963 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
966 return TextAbstraction::FontSlant::NORMAL;
969 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
971 if( NULL == mImpl->mFontDefaults )
973 mImpl->mFontDefaults = new FontDefaults();
980 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
981 mImpl->mFontDefaults->sizeDefined = true;
986 // Point size = Pixel size * 72.f / DPI
987 unsigned int horizontalDpi = 0u;
988 unsigned int verticalDpi = 0u;
989 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
990 fontClient.GetDpi( horizontalDpi, verticalDpi );
992 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
993 mImpl->mFontDefaults->sizeDefined = true;
998 // Clear the font-specific data
1001 mImpl->RequestRelayout();
1004 float Controller::GetDefaultFontSize( FontSizeType type ) const
1007 if( NULL != mImpl->mFontDefaults )
1013 value = mImpl->mFontDefaults->mDefaultPointSize;
1018 // Pixel size = Point size * DPI / 72.f
1019 unsigned int horizontalDpi = 0u;
1020 unsigned int verticalDpi = 0u;
1021 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1022 fontClient.GetDpi( horizontalDpi, verticalDpi );
1024 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1034 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1036 if( NULL != mImpl->mEventData )
1038 if( NULL == mImpl->mEventData->mPlaceholderFont )
1040 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1047 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1048 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1049 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1054 // Point size = Pixel size * 72.f / DPI
1055 unsigned int horizontalDpi = 0u;
1056 unsigned int verticalDpi = 0u;
1057 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1058 fontClient.GetDpi( horizontalDpi, verticalDpi );
1060 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1061 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1062 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1067 mImpl->RequestRelayout();
1071 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1074 if( NULL != mImpl->mEventData )
1080 if( NULL != mImpl->mEventData->mPlaceholderFont )
1082 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1086 // If the placeholder text font size is not set, then return the default font size.
1087 value = GetDefaultFontSize( POINT_SIZE );
1093 if( NULL != mImpl->mEventData->mPlaceholderFont )
1095 // Pixel size = Point size * DPI / 72.f
1096 unsigned int horizontalDpi = 0u;
1097 unsigned int verticalDpi = 0u;
1098 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1099 fontClient.GetDpi( horizontalDpi, verticalDpi );
1101 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1105 // If the placeholder text font size is not set, then return the default font size.
1106 value = GetDefaultFontSize( PIXEL_SIZE );
1117 void Controller::SetDefaultColor( const Vector4& color )
1119 mImpl->mTextColor = color;
1121 if( !mImpl->IsShowingPlaceholderText() )
1123 mImpl->mModel->mVisualModel->SetTextColor( color );
1125 mImpl->RequestRelayout();
1129 const Vector4& Controller::GetDefaultColor() const
1131 return mImpl->mTextColor;
1134 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1136 if( NULL != mImpl->mEventData )
1138 mImpl->mEventData->mPlaceholderTextColor = textColor;
1141 if( mImpl->IsShowingPlaceholderText() )
1143 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1144 mImpl->RequestRelayout();
1148 const Vector4& Controller::GetPlaceholderTextColor() const
1150 if( NULL != mImpl->mEventData )
1152 return mImpl->mEventData->mPlaceholderTextColor;
1155 return Color::BLACK;
1158 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1160 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1162 mImpl->RequestRelayout();
1165 const Vector2& Controller::GetShadowOffset() const
1167 return mImpl->mModel->mVisualModel->GetShadowOffset();
1170 void Controller::SetShadowColor( const Vector4& shadowColor )
1172 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1174 mImpl->RequestRelayout();
1177 const Vector4& Controller::GetShadowColor() const
1179 return mImpl->mModel->mVisualModel->GetShadowColor();
1182 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1184 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1186 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1188 mImpl->RequestRelayout();
1192 const float& Controller::GetShadowBlurRadius() const
1194 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1197 void Controller::SetUnderlineColor( const Vector4& color )
1199 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1201 mImpl->RequestRelayout();
1204 const Vector4& Controller::GetUnderlineColor() const
1206 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1209 void Controller::SetUnderlineEnabled( bool enabled )
1211 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1213 mImpl->RequestRelayout();
1216 bool Controller::IsUnderlineEnabled() const
1218 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1221 void Controller::SetUnderlineHeight( float height )
1223 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1225 mImpl->RequestRelayout();
1228 float Controller::GetUnderlineHeight() const
1230 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1233 void Controller::SetOutlineColor( const Vector4& color )
1235 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1237 mImpl->RequestRelayout();
1240 const Vector4& Controller::GetOutlineColor() const
1242 return mImpl->mModel->mVisualModel->GetOutlineColor();
1245 void Controller::SetOutlineWidth( uint16_t width )
1247 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1249 mImpl->RequestRelayout();
1252 uint16_t Controller::GetOutlineWidth() const
1254 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1257 void Controller::SetBackgroundColor( const Vector4& color )
1259 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1261 mImpl->RequestRelayout();
1264 const Vector4& Controller::GetBackgroundColor() const
1266 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1269 void Controller::SetBackgroundEnabled( bool enabled )
1271 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1273 mImpl->RequestRelayout();
1276 bool Controller::IsBackgroundEnabled() const
1278 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1281 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1283 if( NULL == mImpl->mEmbossDefaults )
1285 mImpl->mEmbossDefaults = new EmbossDefaults();
1288 mImpl->mEmbossDefaults->properties = embossProperties;
1291 const std::string& Controller::GetDefaultEmbossProperties() const
1293 if( NULL != mImpl->mEmbossDefaults )
1295 return mImpl->mEmbossDefaults->properties;
1298 return EMPTY_STRING;
1301 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1303 if( NULL == mImpl->mOutlineDefaults )
1305 mImpl->mOutlineDefaults = new OutlineDefaults();
1308 mImpl->mOutlineDefaults->properties = outlineProperties;
1311 const std::string& Controller::GetDefaultOutlineProperties() const
1313 if( NULL != mImpl->mOutlineDefaults )
1315 return mImpl->mOutlineDefaults->properties;
1318 return EMPTY_STRING;
1321 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1323 if( std::abs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000 )
1325 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1326 mImpl->mRecalculateNaturalSize = true;
1332 float Controller::GetDefaultLineSpacing() const
1334 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1337 void Controller::SetInputColor( const Vector4& color )
1339 if( NULL != mImpl->mEventData )
1341 mImpl->mEventData->mInputStyle.textColor = color;
1342 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1344 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1346 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1348 // Get start and end position of selection
1349 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1350 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1352 // Add the color run.
1353 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1354 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1356 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1357 colorRun.color = color;
1358 colorRun.characterRun.characterIndex = startOfSelectedText;
1359 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1361 // Request to relayout.
1362 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1363 mImpl->RequestRelayout();
1365 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1366 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1367 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1372 const Vector4& Controller::GetInputColor() const
1374 if( NULL != mImpl->mEventData )
1376 return mImpl->mEventData->mInputStyle.textColor;
1379 // Return the default text's color if there is no EventData.
1380 return mImpl->mTextColor;
1384 void Controller::SetInputFontFamily( const std::string& fontFamily )
1386 if( NULL != mImpl->mEventData )
1388 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1389 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1391 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1393 CharacterIndex startOfSelectedText = 0u;
1394 Length lengthOfSelectedText = 0u;
1395 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1396 mImpl->mModel->mLogicalModel,
1397 startOfSelectedText,
1398 lengthOfSelectedText );
1400 fontDescriptionRun.familyLength = fontFamily.size();
1401 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1402 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1403 fontDescriptionRun.familyDefined = true;
1405 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1407 // Request to relayout.
1408 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1413 UPDATE_LAYOUT_SIZE |
1416 mImpl->mRecalculateNaturalSize = true;
1417 mImpl->RequestRelayout();
1419 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1420 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1421 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1423 // As the font changes, recalculate the handle positions is needed.
1424 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1425 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1426 mImpl->mEventData->mUpdateHighlightBox = true;
1427 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1432 const std::string& Controller::GetInputFontFamily() const
1434 if( NULL != mImpl->mEventData )
1436 return mImpl->mEventData->mInputStyle.familyName;
1439 // Return the default font's family if there is no EventData.
1440 return GetDefaultFontFamily();
1443 void Controller::SetInputFontWeight( FontWeight weight )
1445 if( NULL != mImpl->mEventData )
1447 mImpl->mEventData->mInputStyle.weight = weight;
1448 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1450 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1452 CharacterIndex startOfSelectedText = 0u;
1453 Length lengthOfSelectedText = 0u;
1454 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1455 mImpl->mModel->mLogicalModel,
1456 startOfSelectedText,
1457 lengthOfSelectedText );
1459 fontDescriptionRun.weight = weight;
1460 fontDescriptionRun.weightDefined = true;
1462 // Request to relayout.
1463 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1468 UPDATE_LAYOUT_SIZE |
1471 mImpl->mRecalculateNaturalSize = true;
1472 mImpl->RequestRelayout();
1474 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1475 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1476 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1478 // As the font might change, recalculate the handle positions is needed.
1479 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1480 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1481 mImpl->mEventData->mUpdateHighlightBox = true;
1482 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1487 bool Controller::IsInputFontWeightDefined() const
1489 bool defined = false;
1491 if( NULL != mImpl->mEventData )
1493 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1499 FontWeight Controller::GetInputFontWeight() const
1501 if( NULL != mImpl->mEventData )
1503 return mImpl->mEventData->mInputStyle.weight;
1506 return GetDefaultFontWeight();
1509 void Controller::SetInputFontWidth( FontWidth width )
1511 if( NULL != mImpl->mEventData )
1513 mImpl->mEventData->mInputStyle.width = width;
1514 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1516 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1518 CharacterIndex startOfSelectedText = 0u;
1519 Length lengthOfSelectedText = 0u;
1520 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1521 mImpl->mModel->mLogicalModel,
1522 startOfSelectedText,
1523 lengthOfSelectedText );
1525 fontDescriptionRun.width = width;
1526 fontDescriptionRun.widthDefined = true;
1528 // Request to relayout.
1529 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1534 UPDATE_LAYOUT_SIZE |
1537 mImpl->mRecalculateNaturalSize = true;
1538 mImpl->RequestRelayout();
1540 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1541 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1542 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1544 // As the font might change, recalculate the handle positions is needed.
1545 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1546 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1547 mImpl->mEventData->mUpdateHighlightBox = true;
1548 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1553 bool Controller::IsInputFontWidthDefined() const
1555 bool defined = false;
1557 if( NULL != mImpl->mEventData )
1559 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1565 FontWidth Controller::GetInputFontWidth() const
1567 if( NULL != mImpl->mEventData )
1569 return mImpl->mEventData->mInputStyle.width;
1572 return GetDefaultFontWidth();
1575 void Controller::SetInputFontSlant( FontSlant slant )
1577 if( NULL != mImpl->mEventData )
1579 mImpl->mEventData->mInputStyle.slant = slant;
1580 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1582 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1584 CharacterIndex startOfSelectedText = 0u;
1585 Length lengthOfSelectedText = 0u;
1586 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1587 mImpl->mModel->mLogicalModel,
1588 startOfSelectedText,
1589 lengthOfSelectedText );
1591 fontDescriptionRun.slant = slant;
1592 fontDescriptionRun.slantDefined = true;
1594 // Request to relayout.
1595 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1600 UPDATE_LAYOUT_SIZE |
1603 mImpl->mRecalculateNaturalSize = true;
1604 mImpl->RequestRelayout();
1606 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1607 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1608 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1610 // As the font might change, recalculate the handle positions is needed.
1611 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1612 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1613 mImpl->mEventData->mUpdateHighlightBox = true;
1614 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1619 bool Controller::IsInputFontSlantDefined() const
1621 bool defined = false;
1623 if( NULL != mImpl->mEventData )
1625 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1631 FontSlant Controller::GetInputFontSlant() const
1633 if( NULL != mImpl->mEventData )
1635 return mImpl->mEventData->mInputStyle.slant;
1638 return GetDefaultFontSlant();
1641 void Controller::SetInputFontPointSize( float size )
1643 if( NULL != mImpl->mEventData )
1645 mImpl->mEventData->mInputStyle.size = size;
1646 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1648 if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1650 CharacterIndex startOfSelectedText = 0u;
1651 Length lengthOfSelectedText = 0u;
1652 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1653 mImpl->mModel->mLogicalModel,
1654 startOfSelectedText,
1655 lengthOfSelectedText );
1657 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1658 fontDescriptionRun.sizeDefined = true;
1660 // Request to relayout.
1661 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1666 UPDATE_LAYOUT_SIZE |
1669 mImpl->mRecalculateNaturalSize = true;
1670 mImpl->RequestRelayout();
1672 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1673 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1674 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1676 // As the font might change, recalculate the handle positions is needed.
1677 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1678 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1679 mImpl->mEventData->mUpdateHighlightBox = true;
1680 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1685 float Controller::GetInputFontPointSize() const
1687 if( NULL != mImpl->mEventData )
1689 return mImpl->mEventData->mInputStyle.size;
1692 // Return the default font's point size if there is no EventData.
1693 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1696 void Controller::SetInputLineSpacing( float lineSpacing )
1698 if( NULL != mImpl->mEventData )
1700 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1701 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1705 float Controller::GetInputLineSpacing() const
1707 if( NULL != mImpl->mEventData )
1709 return mImpl->mEventData->mInputStyle.lineSpacing;
1715 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1717 if( NULL != mImpl->mEventData )
1719 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1723 const std::string& Controller::GetInputShadowProperties() const
1725 if( NULL != mImpl->mEventData )
1727 return mImpl->mEventData->mInputStyle.shadowProperties;
1730 return EMPTY_STRING;
1733 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1735 if( NULL != mImpl->mEventData )
1737 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1741 const std::string& Controller::GetInputUnderlineProperties() const
1743 if( NULL != mImpl->mEventData )
1745 return mImpl->mEventData->mInputStyle.underlineProperties;
1748 return EMPTY_STRING;
1751 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1753 if( NULL != mImpl->mEventData )
1755 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1759 const std::string& Controller::GetInputEmbossProperties() const
1761 if( NULL != mImpl->mEventData )
1763 return mImpl->mEventData->mInputStyle.embossProperties;
1766 return GetDefaultEmbossProperties();
1769 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1771 if( NULL != mImpl->mEventData )
1773 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1777 const std::string& Controller::GetInputOutlineProperties() const
1779 if( NULL != mImpl->mEventData )
1781 return mImpl->mEventData->mInputStyle.outlineProperties;
1784 return GetDefaultOutlineProperties();
1787 void Controller::SetInputModePassword( bool passwordInput )
1789 if( NULL != mImpl->mEventData )
1791 mImpl->mEventData->mPasswordInput = passwordInput;
1795 bool Controller::IsInputModePassword()
1797 if( NULL != mImpl->mEventData )
1799 return mImpl->mEventData->mPasswordInput;
1804 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1806 if( NULL != mImpl->mEventData )
1808 mImpl->mEventData->mDoubleTapAction = action;
1812 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1814 NoTextTap::Action action = NoTextTap::NO_ACTION;
1816 if( NULL != mImpl->mEventData )
1818 action = mImpl->mEventData->mDoubleTapAction;
1824 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1826 if( NULL != mImpl->mEventData )
1828 mImpl->mEventData->mLongPressAction = action;
1832 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1834 NoTextTap::Action action = NoTextTap::NO_ACTION;
1836 if( NULL != mImpl->mEventData )
1838 action = mImpl->mEventData->mLongPressAction;
1844 bool Controller::IsUnderlineSetByString()
1846 return mImpl->mUnderlineSetByString;
1849 void Controller::UnderlineSetByString( bool setByString )
1851 mImpl->mUnderlineSetByString = setByString;
1854 bool Controller::IsShadowSetByString()
1856 return mImpl->mShadowSetByString;
1859 void Controller::ShadowSetByString( bool setByString )
1861 mImpl->mShadowSetByString = setByString;
1864 bool Controller::IsOutlineSetByString()
1866 return mImpl->mOutlineSetByString;
1869 void Controller::OutlineSetByString( bool setByString )
1871 mImpl->mOutlineSetByString = setByString;
1874 bool Controller::IsFontStyleSetByString()
1876 return mImpl->mFontStyleSetByString;
1879 void Controller::FontStyleSetByString( bool setByString )
1881 mImpl->mFontStyleSetByString = setByString;
1884 // public : Queries & retrieves.
1886 Layout::Engine& Controller::GetLayoutEngine()
1888 return mImpl->mLayoutEngine;
1891 View& Controller::GetView()
1893 return mImpl->mView;
1896 Vector3 Controller::GetNaturalSize()
1898 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1899 Vector3 naturalSize;
1901 // Make sure the model is up-to-date before layouting
1902 ProcessModifyEvents();
1904 if( mImpl->mRecalculateNaturalSize )
1906 // Operations that can be done only once until the text changes.
1907 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1914 GET_GLYPH_METRICS );
1916 // Set the update info to relayout the whole text.
1917 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1918 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1920 // Make sure the model is up-to-date before layouting
1921 mImpl->UpdateModel( onlyOnceOperations );
1923 // Layout the text for the new width.
1924 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1926 // Store the actual control's size to restore later.
1927 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1929 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1930 static_cast<OperationsMask>( onlyOnceOperations |
1932 naturalSize.GetVectorXY() );
1934 // Do not do again the only once operations.
1935 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1937 // Do the size related operations again.
1938 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1941 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1943 // Stores the natural size to avoid recalculate it again
1944 // unless the text/style changes.
1945 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1947 mImpl->mRecalculateNaturalSize = false;
1949 // Clear the update info. This info will be set the next time the text is updated.
1950 mImpl->mTextUpdateInfo.Clear();
1951 mImpl->mTextUpdateInfo.mClearAll = true;
1953 // Restore the actual control's size.
1954 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1956 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1960 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1962 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1965 naturalSize.x = ConvertToEven( naturalSize.x );
1966 naturalSize.y = ConvertToEven( naturalSize.y );
1971 float Controller::GetHeightForWidth( float width )
1973 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1974 // Make sure the model is up-to-date before layouting
1975 ProcessModifyEvents();
1978 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1979 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1980 mImpl->mTextUpdateInfo.mClearAll )
1982 // Operations that can be done only once until the text changes.
1983 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1990 GET_GLYPH_METRICS );
1992 // Set the update info to relayout the whole text.
1993 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1994 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1996 // Make sure the model is up-to-date before layouting
1997 mImpl->UpdateModel( onlyOnceOperations );
2000 // Layout the text for the new width.
2001 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2003 // Store the actual control's width.
2004 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2006 DoRelayout( Size( width, MAX_FLOAT ),
2007 static_cast<OperationsMask>( onlyOnceOperations |
2011 // Do not do again the only once operations.
2012 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2014 // Do the size related operations again.
2015 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
2019 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2021 // Clear the update info. This info will be set the next time the text is updated.
2022 mImpl->mTextUpdateInfo.Clear();
2023 mImpl->mTextUpdateInfo.mClearAll = true;
2025 // Restore the actual control's width.
2026 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2028 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2032 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2033 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2036 return layoutSize.height;
2039 int Controller::GetLineCount( float width )
2041 GetHeightForWidth( width );
2042 int numberofLines = mImpl->mModel->GetNumberOfLines();
2043 return numberofLines;
2046 const ModelInterface* const Controller::GetTextModel() const
2048 return mImpl->mModel.Get();
2051 float Controller::GetScrollAmountByUserInput()
2053 float scrollAmount = 0.0f;
2055 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2057 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2058 mImpl->mEventData->mCheckScrollAmount = false;
2060 return scrollAmount;
2063 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2065 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2068 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2069 layoutHeight = layout.height;
2070 scrollPosition = mImpl->mModel->mScrollPosition.y;
2071 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2075 void Controller::SetHiddenInputOption(const Property::Map& options )
2077 if( NULL == mImpl->mHiddenInput )
2079 mImpl->mHiddenInput = new HiddenText( this );
2081 mImpl->mHiddenInput->SetProperties(options);
2084 void Controller::GetHiddenInputOption(Property::Map& options )
2086 if( NULL != mImpl->mHiddenInput )
2088 mImpl->mHiddenInput->GetProperties(options);
2092 void Controller::SetPlaceholderProperty( const Property::Map& map )
2094 const Property::Map::SizeType count = map.Count();
2096 for( Property::Map::SizeType position = 0; position < count; ++position )
2098 KeyValuePair keyValue = map.GetKeyValue( position );
2099 Property::Key& key = keyValue.first;
2100 Property::Value& value = keyValue.second;
2102 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2104 std::string text = "";
2106 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2108 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2110 std::string text = "";
2112 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2114 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2117 value.Get( textColor );
2118 if( GetPlaceholderTextColor() != textColor )
2120 SetPlaceholderTextColor( textColor );
2123 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2125 std::string fontFamily = "";
2126 value.Get( fontFamily );
2127 SetPlaceholderFontFamily( fontFamily );
2129 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2131 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2133 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2136 value.Get( pointSize );
2137 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2139 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2142 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2145 value.Get( pixelSize );
2146 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2148 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2151 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2154 value.Get( ellipsis );
2155 SetPlaceholderTextElideEnabled( ellipsis );
2160 void Controller::GetPlaceholderProperty( Property::Map& map )
2162 if( NULL != mImpl->mEventData )
2164 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2166 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2168 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2170 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2173 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2174 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2176 Property::Value fontStyleMapGet;
2177 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2178 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2180 // Choose font size : POINT_SIZE or PIXEL_SIZE
2181 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2183 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2187 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2190 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2192 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2197 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2199 // Make sure the model is up-to-date before layouting
2200 ProcessModifyEvents();
2202 if ( mImpl->mUpdateTextDirection )
2204 // Operations that can be done only once until the text changes.
2205 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2212 GET_GLYPH_METRICS );
2214 // Set the update info to relayout the whole text.
2215 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2216 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2218 // Make sure the model is up-to-date before layouting
2219 mImpl->UpdateModel( onlyOnceOperations );
2221 Vector3 naturalSize;
2222 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2223 static_cast<OperationsMask>( onlyOnceOperations |
2224 LAYOUT | REORDER | UPDATE_DIRECTION ),
2225 naturalSize.GetVectorXY() );
2227 // Do not do again the only once operations.
2228 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2230 // Clear the update info. This info will be set the next time the text is updated.
2231 mImpl->mTextUpdateInfo.Clear();
2233 mImpl->mUpdateTextDirection = false;
2236 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2239 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2241 return mImpl->mModel->GetVerticalLineAlignment();
2244 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2246 mImpl->mModel->mVerticalLineAlignment = alignment;
2249 // public : Relayout.
2251 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2253 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2255 UpdateTextType updateTextType = NONE_UPDATED;
2257 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2259 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2261 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2262 updateTextType = MODEL_UPDATED;
2265 // Clear the update info. This info will be set the next time the text is updated.
2266 mImpl->mTextUpdateInfo.Clear();
2268 // Not worth to relayout if width or height is equal to zero.
2269 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2271 return updateTextType;
2274 // Whether a new size has been set.
2275 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2279 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2281 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2282 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2283 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2285 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2288 // Layout operations that need to be done if the size changes.
2289 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2292 UPDATE_LAYOUT_SIZE |
2294 // Set the update info to relayout the whole text.
2295 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2296 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2298 // Store the size used to layout the text.
2299 mImpl->mModel->mVisualModel->mControlSize = size;
2302 // Whether there are modify events.
2303 if( 0u != mImpl->mModifyEvents.Count() )
2305 // Style operations that need to be done if the text is modified.
2306 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2310 // Set the update info to elide the text.
2311 if( mImpl->mModel->mElideEnabled ||
2312 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2314 // Update Text layout for applying elided
2315 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2318 UPDATE_LAYOUT_SIZE |
2320 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2321 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2324 if( mImpl->mModel->mMatchSystemLanguageDirection && mImpl->mLayoutDirection != layoutDirection )
2326 // Clear the update info. This info will be set the next time the text is updated.
2327 mImpl->mTextUpdateInfo.mClearAll = true;
2328 // Apply modifications to the model
2329 // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2330 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2337 mImpl->mLayoutDirection = layoutDirection;
2340 // Make sure the model is up-to-date before layouting.
2341 ProcessModifyEvents();
2342 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2346 updated = DoRelayout( size,
2347 mImpl->mOperationsPending,
2348 layoutSize ) || updated;
2353 updateTextType = MODEL_UPDATED;
2356 // Do not re-do any operation until something changes.
2357 mImpl->mOperationsPending = NO_OPERATION;
2358 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2360 // Whether the text control is editable
2361 const bool isEditable = NULL != mImpl->mEventData;
2363 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2365 if( newSize && isEditable )
2367 offset = mImpl->mModel->mScrollPosition;
2370 if( !isEditable || !IsMultiLineEnabled() )
2372 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2373 CalculateVerticalOffset( size );
2380 // If there is a new size, the scroll position needs to be clamped.
2381 mImpl->ClampHorizontalScroll( layoutSize );
2383 // Update the decorator's positions is needed if there is a new size.
2384 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2387 // Move the cursor, grab handle etc.
2388 if( mImpl->ProcessInputEvents() )
2390 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2394 // Clear the update info. This info will be set the next time the text is updated.
2395 mImpl->mTextUpdateInfo.Clear();
2396 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2398 return updateTextType;
2401 void Controller::RequestRelayout()
2403 mImpl->RequestRelayout();
2406 // public : Input style change signals.
2408 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2410 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2413 void Controller::ProcessInputStyleChangedSignals()
2415 if( NULL == mImpl->mEventData )
2421 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2422 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2426 const InputStyle::Mask mask = *it;
2428 if( NULL != mImpl->mEditableControlInterface )
2430 // Emit the input style changed signal.
2431 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2435 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2438 // public : Text-input Event Queuing.
2440 void Controller::KeyboardFocusGainEvent()
2442 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2444 if( NULL != mImpl->mEventData )
2446 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2447 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2449 mImpl->ChangeState( EventData::EDITING );
2450 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2451 mImpl->mEventData->mUpdateInputStyle = true;
2452 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2454 mImpl->NotifyInputMethodContextMultiLineStatus();
2455 if( mImpl->IsShowingPlaceholderText() )
2457 // Show alternative placeholder-text when editing
2458 ShowPlaceholderText();
2461 mImpl->RequestRelayout();
2465 void Controller::KeyboardFocusLostEvent()
2467 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2469 if( NULL != mImpl->mEventData )
2471 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2473 mImpl->ChangeState( EventData::INACTIVE );
2475 if( !mImpl->IsShowingRealText() )
2477 // Revert to regular placeholder-text when not editing
2478 ShowPlaceholderText();
2482 mImpl->RequestRelayout();
2485 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2487 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2489 bool textChanged = false;
2490 bool relayoutNeeded = false;
2492 if( ( NULL != mImpl->mEventData ) &&
2493 ( keyEvent.state == KeyEvent::Down ) )
2495 int keyCode = keyEvent.keyCode;
2496 const std::string& keyString = keyEvent.keyPressed;
2497 const std::string keyName = keyEvent.keyPressedName;
2499 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2501 // Pre-process to separate modifying events from non-modifying input events.
2504 // In some platforms arrive key events with no key code.
2508 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2513 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2514 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2515 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2516 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2518 // If don't have any text, do nothing.
2519 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2524 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2525 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2526 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2527 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2529 // Logic to determine whether this text control will lose focus or not.
2530 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2531 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2532 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2533 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2534 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2535 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2537 // Release the active highlight.
2538 if( mImpl->mEventData->mState == EventData::SELECTING )
2540 mImpl->ChangeState( EventData::EDITING );
2542 // Update selection position.
2543 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2544 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2545 mImpl->mEventData->mUpdateCursorPosition = true;
2546 mImpl->RequestRelayout();
2551 mImpl->mEventData->mCheckScrollAmount = true;
2552 Event event( Event::CURSOR_KEY_EVENT );
2553 event.p1.mInt = keyCode;
2554 event.p2.mBool = keyEvent.IsShiftModifier();
2555 mImpl->mEventData->mEventQueue.push_back( event );
2557 // Will request for relayout.
2558 relayoutNeeded = true;
2560 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2562 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2563 // If not handle it here, any selected text will be deleted
2568 else if ( keyEvent.IsCtrlModifier() )
2570 bool consumed = false;
2571 if (keyName == KEY_C_NAME)
2573 // Ctrl-C to copy the selected text
2574 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2577 else if (keyName == KEY_V_NAME)
2579 // Ctrl-V to paste the copied text
2580 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2583 else if (keyName == KEY_X_NAME)
2585 // Ctrl-X to cut the selected text
2586 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2591 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2592 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2594 textChanged = DeleteEvent( keyCode );
2596 // Will request for relayout.
2597 relayoutNeeded = true;
2599 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2600 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2601 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2603 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2604 mImpl->ChangeState( EventData::INACTIVE );
2606 // Will request for relayout.
2607 relayoutNeeded = true;
2609 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2611 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2613 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the InputMethodContext?) when the predictive text is enabled
2614 // and a character is typed after the type of a upper case latin character.
2619 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2621 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2627 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2629 if( !keyString.empty() )
2631 // InputMethodContext is no longer handling key-events
2632 mImpl->ClearPreEditFlag();
2634 InsertText( keyString, COMMIT );
2638 // Will request for relayout.
2639 relayoutNeeded = true;
2644 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2645 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2647 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2648 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2649 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2651 // Should not change the state if the key is the shift send by the InputMethodContext.
2652 // Otherwise, when the state is SELECTING the text controller can't send the right
2653 // surrounding info to the InputMethodContext.
2654 mImpl->ChangeState( EventData::EDITING );
2656 // Will request for relayout.
2657 relayoutNeeded = true;
2660 if( relayoutNeeded )
2662 mImpl->RequestRelayout();
2667 ( NULL != mImpl->mEditableControlInterface ) )
2669 // Do this last since it provides callbacks into application code
2670 mImpl->mEditableControlInterface->TextChanged();
2676 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2678 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2680 if( NULL != mImpl->mEventData )
2682 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2683 EventData::State state( mImpl->mEventData->mState );
2684 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2686 if( mImpl->IsClipboardVisible() )
2688 if( EventData::INACTIVE == state || EventData::EDITING == state)
2690 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2692 relayoutNeeded = true;
2694 else if( 1u == tapCount )
2696 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2698 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2701 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2703 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2704 relayoutNeeded = true;
2708 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2710 // Hide placeholder text
2714 if( EventData::INACTIVE == state )
2716 mImpl->ChangeState( EventData::EDITING );
2718 else if( !mImpl->IsClipboardEmpty() )
2720 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2722 relayoutNeeded = true;
2725 else if( 2u == tapCount )
2727 if( mImpl->mEventData->mSelectionEnabled &&
2728 mImpl->IsShowingRealText() )
2730 relayoutNeeded = true;
2731 mImpl->mEventData->mIsLeftHandleSelected = true;
2732 mImpl->mEventData->mIsRightHandleSelected = true;
2736 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2737 if( relayoutNeeded )
2739 Event event( Event::TAP_EVENT );
2740 event.p1.mUint = tapCount;
2741 event.p2.mFloat = x;
2742 event.p3.mFloat = y;
2743 mImpl->mEventData->mEventQueue.push_back( event );
2745 mImpl->RequestRelayout();
2749 // Reset keyboard as tap event has occurred.
2750 mImpl->ResetInputMethodContext();
2753 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2755 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2757 if( NULL != mImpl->mEventData )
2759 Event event( Event::PAN_EVENT );
2760 event.p1.mInt = state;
2761 event.p2.mFloat = displacement.x;
2762 event.p3.mFloat = displacement.y;
2763 mImpl->mEventData->mEventQueue.push_back( event );
2765 mImpl->RequestRelayout();
2769 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2771 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2773 if( ( state == Gesture::Started ) &&
2774 ( NULL != mImpl->mEventData ) )
2776 // The 1st long-press on inactive text-field is treated as tap
2777 if( EventData::INACTIVE == mImpl->mEventData->mState )
2779 mImpl->ChangeState( EventData::EDITING );
2781 Event event( Event::TAP_EVENT );
2783 event.p2.mFloat = x;
2784 event.p3.mFloat = y;
2785 mImpl->mEventData->mEventQueue.push_back( event );
2787 mImpl->RequestRelayout();
2789 else if( !mImpl->IsShowingRealText() )
2791 Event event( Event::LONG_PRESS_EVENT );
2792 event.p1.mInt = state;
2793 event.p2.mFloat = x;
2794 event.p3.mFloat = y;
2795 mImpl->mEventData->mEventQueue.push_back( event );
2796 mImpl->RequestRelayout();
2798 else if( !mImpl->IsClipboardVisible() )
2800 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
2801 mImpl->ResetInputMethodContext();
2803 Event event( Event::LONG_PRESS_EVENT );
2804 event.p1.mInt = state;
2805 event.p2.mFloat = x;
2806 event.p3.mFloat = y;
2807 mImpl->mEventData->mEventQueue.push_back( event );
2808 mImpl->RequestRelayout();
2810 mImpl->mEventData->mIsLeftHandleSelected = true;
2811 mImpl->mEventData->mIsRightHandleSelected = true;
2816 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
2818 // Whether the text needs to be relaid-out.
2819 bool requestRelayout = false;
2821 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
2822 bool retrieveText = false;
2823 bool retrieveCursor = false;
2825 switch( inputMethodContextEvent.eventName )
2827 case InputMethodContext::COMMIT:
2829 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
2830 requestRelayout = true;
2831 retrieveCursor = true;
2834 case InputMethodContext::PRE_EDIT:
2836 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
2837 requestRelayout = true;
2838 retrieveCursor = true;
2841 case InputMethodContext::DELETE_SURROUNDING:
2843 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
2844 inputMethodContextEvent.numberOfChars,
2845 DONT_UPDATE_INPUT_STYLE );
2849 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2850 !mImpl->IsPlaceholderAvailable() )
2852 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2856 ShowPlaceholderText();
2858 mImpl->mEventData->mUpdateCursorPosition = true;
2859 mImpl->mEventData->mScrollAfterDelete = true;
2861 requestRelayout = true;
2865 case InputMethodContext::GET_SURROUNDING:
2867 retrieveText = true;
2868 retrieveCursor = true;
2871 case InputMethodContext::PRIVATE_COMMAND:
2873 // PRIVATECOMMAND event is just for getting the private command message
2874 retrieveText = true;
2875 retrieveCursor = true;
2878 case InputMethodContext::VOID:
2885 if( requestRelayout )
2887 mImpl->mOperationsPending = ALL_OPERATIONS;
2888 mImpl->RequestRelayout();
2892 CharacterIndex cursorPosition = 0u;
2893 Length numberOfWhiteSpaces = 0u;
2895 if( retrieveCursor )
2897 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2899 cursorPosition = mImpl->GetLogicalCursorPosition();
2901 if( cursorPosition < numberOfWhiteSpaces )
2903 cursorPosition = 0u;
2907 cursorPosition -= numberOfWhiteSpaces;
2913 if( !mImpl->IsShowingPlaceholderText() )
2915 // Retrieves the normal text string.
2916 mImpl->GetText( numberOfWhiteSpaces, text );
2920 // When the current text is Placeholder Text, the surrounding text should be empty string.
2921 // It means DALi should send empty string ("") to IME.
2926 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2928 if( requestRelayout &&
2929 ( NULL != mImpl->mEditableControlInterface ) )
2931 // Do this last since it provides callbacks into application code
2932 mImpl->mEditableControlInterface->TextChanged();
2935 return callbackData;
2938 void Controller::PasteClipboardItemEvent()
2940 // Retrieve the clipboard contents first
2941 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2942 std::string stringToPaste( notifier.GetContent() );
2944 // Commit the current pre-edit text; the contents of the clipboard should be appended
2945 mImpl->ResetInputMethodContext();
2947 // Temporary disable hiding clipboard
2948 mImpl->SetClipboardHideEnable( false );
2951 PasteText( stringToPaste );
2953 mImpl->SetClipboardHideEnable( true );
2956 // protected : Inherit from Text::Decorator::ControllerInterface.
2958 void Controller::GetTargetSize( Vector2& targetSize )
2960 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2963 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2965 if( NULL != mImpl->mEditableControlInterface )
2967 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2971 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2973 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2975 if( NULL != mImpl->mEventData )
2977 switch( handleType )
2981 Event event( Event::GRAB_HANDLE_EVENT );
2982 event.p1.mUint = state;
2983 event.p2.mFloat = x;
2984 event.p3.mFloat = y;
2986 mImpl->mEventData->mEventQueue.push_back( event );
2989 case LEFT_SELECTION_HANDLE:
2991 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2992 event.p1.mUint = state;
2993 event.p2.mFloat = x;
2994 event.p3.mFloat = y;
2996 mImpl->mEventData->mEventQueue.push_back( event );
2999 case RIGHT_SELECTION_HANDLE:
3001 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3002 event.p1.mUint = state;
3003 event.p2.mFloat = x;
3004 event.p3.mFloat = y;
3006 mImpl->mEventData->mEventQueue.push_back( event );
3009 case LEFT_SELECTION_HANDLE_MARKER:
3010 case RIGHT_SELECTION_HANDLE_MARKER:
3012 // Markers do not move the handles.
3015 case HANDLE_TYPE_COUNT:
3017 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3021 mImpl->RequestRelayout();
3025 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3027 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3029 if( NULL == mImpl->mEventData )
3036 case Toolkit::TextSelectionPopup::CUT:
3038 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3039 mImpl->mOperationsPending = ALL_OPERATIONS;
3041 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3042 !mImpl->IsPlaceholderAvailable() )
3044 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3048 ShowPlaceholderText();
3051 mImpl->mEventData->mUpdateCursorPosition = true;
3052 mImpl->mEventData->mScrollAfterDelete = true;
3054 mImpl->RequestRelayout();
3056 if( NULL != mImpl->mEditableControlInterface )
3058 mImpl->mEditableControlInterface->TextChanged();
3062 case Toolkit::TextSelectionPopup::COPY:
3064 mImpl->SendSelectionToClipboard( false ); // Text not modified
3066 mImpl->mEventData->mUpdateCursorPosition = true;
3068 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3071 case Toolkit::TextSelectionPopup::PASTE:
3073 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3076 case Toolkit::TextSelectionPopup::SELECT:
3078 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3080 if( mImpl->mEventData->mSelectionEnabled )
3082 // Creates a SELECT event.
3083 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3087 case Toolkit::TextSelectionPopup::SELECT_ALL:
3089 // Creates a SELECT_ALL event
3090 SelectEvent( 0.f, 0.f, true );
3093 case Toolkit::TextSelectionPopup::CLIPBOARD:
3095 mImpl->ShowClipboard();
3098 case Toolkit::TextSelectionPopup::NONE:
3106 void Controller::DisplayTimeExpired()
3108 mImpl->mEventData->mUpdateCursorPosition = true;
3109 // Apply modifications to the model
3110 mImpl->mOperationsPending = ALL_OPERATIONS;
3112 mImpl->RequestRelayout();
3115 // private : Update.
3117 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3119 bool removedPrevious = false;
3120 bool removedSelected = false;
3121 bool maxLengthReached = false;
3123 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3125 if( NULL == mImpl->mEventData )
3130 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3131 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3132 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3134 // TODO: At the moment the underline runs are only for pre-edit.
3135 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3137 // Remove the previous InputMethodContext pre-edit.
3138 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3140 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3141 mImpl->mEventData->mPreEditLength,
3142 DONT_UPDATE_INPUT_STYLE );
3144 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3145 mImpl->mEventData->mPreEditLength = 0u;
3149 // Remove the previous Selection.
3150 removedSelected = RemoveSelectedText();
3154 Vector<Character> utf32Characters;
3155 Length characterCount = 0u;
3159 // Convert text into UTF-32
3160 utf32Characters.Resize( text.size() );
3162 // This is a bit horrible but std::string returns a (signed) char*
3163 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3165 // Transform a text array encoded in utf8 into an array encoded in utf32.
3166 // It returns the actual number of characters.
3167 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3168 utf32Characters.Resize( characterCount );
3170 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3171 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3174 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3176 // The placeholder text is no longer needed
3177 if( mImpl->IsShowingPlaceholderText() )
3182 mImpl->ChangeState( EventData::EDITING );
3184 // Handle the InputMethodContext (predicitive text) state changes
3185 if( COMMIT == type )
3187 // InputMethodContext is no longer handling key-events
3188 mImpl->ClearPreEditFlag();
3192 if( !mImpl->mEventData->mPreEditFlag )
3194 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3196 // Record the start of the pre-edit text
3197 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3200 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3201 mImpl->mEventData->mPreEditFlag = true;
3203 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3206 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3208 // Restrict new text to fit within Maximum characters setting.
3209 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3210 maxLengthReached = ( characterCount > maxSizeOfNewText );
3212 // The cursor position.
3213 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3215 // Update the text's style.
3217 // Updates the text style runs by adding characters.
3218 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3220 // Get the character index from the cursor index.
3221 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3223 // Retrieve the text's style for the given index.
3225 mImpl->RetrieveDefaultInputStyle( style );
3226 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3228 // Whether to add a new text color run.
3229 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3231 // Whether to add a new font run.
3232 const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3233 const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3234 const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3235 const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3236 const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3241 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3242 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3244 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3245 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3246 colorRun.characterRun.characterIndex = cursorIndex;
3247 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3250 if( addFontNameRun ||
3256 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3257 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3259 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3261 if( addFontNameRun )
3263 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3264 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3265 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3266 fontDescriptionRun.familyDefined = true;
3268 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3271 if( addFontWeightRun )
3273 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3274 fontDescriptionRun.weightDefined = true;
3277 if( addFontWidthRun )
3279 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3280 fontDescriptionRun.widthDefined = true;
3283 if( addFontSlantRun )
3285 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3286 fontDescriptionRun.slantDefined = true;
3289 if( addFontSizeRun )
3291 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3292 fontDescriptionRun.sizeDefined = true;
3295 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3296 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3299 // Insert at current cursor position.
3300 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3302 if( cursorIndex < numberOfCharactersInModel )
3304 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3308 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3311 // Mark the first paragraph to be updated.
3312 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3314 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3315 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3316 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3317 mImpl->mTextUpdateInfo.mClearAll = true;
3321 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3322 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3325 // Update the cursor index.
3326 cursorIndex += maxSizeOfNewText;
3328 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 );
3331 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3332 mImpl->IsPlaceholderAvailable() )
3334 // Show place-holder if empty after removing the pre-edit text
3335 ShowPlaceholderText();
3336 mImpl->mEventData->mUpdateCursorPosition = true;
3337 mImpl->ClearPreEditFlag();
3339 else if( removedPrevious ||
3341 ( 0 != utf32Characters.Count() ) )
3343 // Queue an inserted event
3344 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3346 mImpl->mEventData->mUpdateCursorPosition = true;
3347 if( removedSelected )
3349 mImpl->mEventData->mScrollAfterDelete = true;
3353 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3357 if( maxLengthReached )
3359 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3361 mImpl->ResetInputMethodContext();
3363 if( NULL != mImpl->mEditableControlInterface )
3365 // Do this last since it provides callbacks into application code
3366 mImpl->mEditableControlInterface->MaxLengthReached();
3371 void Controller::PasteText( const std::string& stringToPaste )
3373 InsertText( stringToPaste, Text::Controller::COMMIT );
3374 mImpl->ChangeState( EventData::EDITING );
3375 mImpl->RequestRelayout();
3377 if( NULL != mImpl->mEditableControlInterface )
3379 // Do this last since it provides callbacks into application code
3380 mImpl->mEditableControlInterface->TextChanged();
3384 bool Controller::RemoveText( int cursorOffset,
3385 int numberOfCharacters,
3386 UpdateInputStyleType type )
3388 bool removed = false;
3390 if( NULL == mImpl->mEventData )
3395 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3396 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3398 if( !mImpl->IsShowingPlaceholderText() )
3400 // Delete at current cursor position
3401 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3402 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3404 CharacterIndex cursorIndex = 0;
3406 // Validate the cursor position & number of characters
3407 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3409 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3412 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3414 numberOfCharacters = currentText.Count() - cursorIndex;
3417 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.
3418 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3420 // Mark the paragraphs to be updated.
3421 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3423 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3424 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3425 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3426 mImpl->mTextUpdateInfo.mClearAll = true;
3430 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3431 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3434 // Update the input style and remove the text's style before removing the text.
3436 if( UPDATE_INPUT_STYLE == type )
3438 // Keep a copy of the current input style.
3439 InputStyle currentInputStyle;
3440 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3442 // Set first the default input style.
3443 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3445 // Update the input style.
3446 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3448 // Compare if the input style has changed.
3449 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3451 if( hasInputStyleChanged )
3453 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3454 // Queue the input style changed signal.
3455 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3459 // Updates the text style runs by removing characters. Runs with no characters are removed.
3460 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3462 // Remove the characters.
3463 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3464 Vector<Character>::Iterator last = first + numberOfCharacters;
3466 currentText.Erase( first, last );
3468 // Cursor position retreat
3469 oldCursorIndex = cursorIndex;
3471 mImpl->mEventData->mScrollAfterDelete = true;
3473 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3481 bool Controller::RemoveSelectedText()
3483 bool textRemoved( false );
3485 if( EventData::SELECTING == mImpl->mEventData->mState )
3487 std::string removedString;
3488 mImpl->RetrieveSelection( removedString, true );
3490 if( !removedString.empty() )
3493 mImpl->ChangeState( EventData::EDITING );
3500 // private : Relayout.
3502 bool Controller::DoRelayout( const Size& size,
3503 OperationsMask operationsRequired,
3506 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3507 bool viewUpdated( false );
3509 // Calculate the operations to be done.
3510 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3512 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3513 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3515 // Get the current layout size.
3516 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3518 if( NO_OPERATION != ( LAYOUT & operations ) )
3520 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3522 // Some vectors with data needed to layout and reorder may be void
3523 // after the first time the text has been laid out.
3524 // Fill the vectors again.
3526 // Calculate the number of glyphs to layout.
3527 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3528 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3529 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3530 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3532 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3533 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3535 // Make sure the index is not out of bound
3536 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3537 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3538 ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3540 std::string currentText;
3541 GetText( currentText );
3543 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3544 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3545 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3550 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3551 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3553 if( 0u == totalNumberOfGlyphs )
3555 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3557 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3560 // Nothing else to do if there is no glyphs.
3561 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3565 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3566 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3567 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3568 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3569 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3570 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3571 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3572 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3574 // Set the layout parameters.
3575 Layout::Parameters layoutParameters( size,
3577 lineBreakInfo.Begin(),
3578 wordBreakInfo.Begin(),
3579 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3581 glyphsToCharactersMap.Begin(),
3582 charactersPerGlyph.Begin(),
3583 charactersToGlyphBuffer,
3584 glyphsPerCharacterBuffer,
3585 totalNumberOfGlyphs,
3586 mImpl->mModel->mHorizontalAlignment,
3587 mImpl->mModel->mLineWrapMode,
3589 mImpl->mModel->mIgnoreSpacesAfterText,
3590 mImpl->mModel->mMatchSystemLanguageDirection );
3592 // Resize the vector of positions to have the same size than the vector of glyphs.
3593 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3594 glyphPositions.Resize( totalNumberOfGlyphs );
3596 // Whether the last character is a new paragraph character.
3597 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3598 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3600 // The initial glyph and the number of glyphs to layout.
3601 layoutParameters.startGlyphIndex = startGlyphIndex;
3602 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3603 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3604 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3606 // Update the ellipsis
3607 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3609 if( NULL != mImpl->mEventData )
3611 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3613 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3615 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3617 // Disable ellipsis when editing
3618 elideTextEnabled = false;
3621 // Reset the scroll position in inactive state
3622 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3624 ResetScrollPosition();
3628 // Update the visual model.
3629 bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3631 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3633 mImpl->mModel->mVisualModel->mLines,
3636 isAutoScrollEnabled );
3637 mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3639 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3643 layoutSize = newLayoutSize;
3645 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3647 mImpl->mIsTextDirectionRTL = false;
3650 // Reorder the lines
3651 if( NO_OPERATION != ( REORDER & operations ) )
3653 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3654 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3656 // Check first if there are paragraphs with bidirectional info.
3657 if( 0u != bidirectionalInfo.Count() )
3660 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3662 // Reorder the lines.
3663 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3664 ReorderLines( bidirectionalInfo,
3666 requestedNumberOfCharacters,
3667 mImpl->mModel->mVisualModel->mLines,
3668 bidirectionalLineInfo );
3670 // Set the bidirectional info per line into the layout parameters.
3671 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3672 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3674 // Re-layout the text. Reorder those lines with right to left characters.
3675 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3677 requestedNumberOfCharacters,
3680 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3682 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3685 mImpl->mIsTextDirectionRTL = firstline->direction;
3691 // Sets the layout size.
3692 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3694 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3699 if( NO_OPERATION != ( ALIGN & operations ) )
3701 // The laid-out lines.
3702 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3704 // Need to align with the control's size as the text may contain lines
3705 // starting either with left to right text or right to left.
3706 mImpl->mLayoutEngine.Align( size,
3708 requestedNumberOfCharacters,
3709 mImpl->mModel->mHorizontalAlignment,
3711 mImpl->mModel->mAlignmentOffset,
3712 mImpl->mLayoutDirection,
3713 mImpl->mModel->mMatchSystemLanguageDirection );
3717 #if defined(DEBUG_ENABLED)
3718 std::string currentText;
3719 GetText( currentText );
3720 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3722 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3726 void Controller::CalculateVerticalOffset( const Size& controlSize )
3728 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3730 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3732 // Get the line height of the default font.
3733 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3736 switch( mImpl->mModel->mVerticalAlignment )
3738 case VerticalAlignment::TOP:
3740 mImpl->mModel->mScrollPosition.y = 0.f;
3743 case VerticalAlignment::CENTER:
3745 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3748 case VerticalAlignment::BOTTOM:
3750 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3756 // private : Events.
3758 void Controller::ProcessModifyEvents()
3760 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3762 if( 0u == events.Count() )
3768 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3769 endIt = events.End();
3773 const ModifyEvent& event = *it;
3775 if( ModifyEvent::TEXT_REPLACED == event.type )
3777 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3778 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3780 TextReplacedEvent();
3782 else if( ModifyEvent::TEXT_INSERTED == event.type )
3784 TextInsertedEvent();
3786 else if( ModifyEvent::TEXT_DELETED == event.type )
3788 // Placeholder-text cannot be deleted
3789 if( !mImpl->IsShowingPlaceholderText() )
3796 if( NULL != mImpl->mEventData )
3798 // When the text is being modified, delay cursor blinking
3799 mImpl->mEventData->mDecorator->DelayCursorBlink();
3801 // Update selection position after modifying the text
3802 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3803 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3806 // Discard temporary text
3810 void Controller::TextReplacedEvent()
3812 // The natural size needs to be re-calculated.
3813 mImpl->mRecalculateNaturalSize = true;
3815 // The text direction needs to be updated.
3816 mImpl->mUpdateTextDirection = true;
3818 // Apply modifications to the model
3819 mImpl->mOperationsPending = ALL_OPERATIONS;
3822 void Controller::TextInsertedEvent()
3824 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3826 if( NULL == mImpl->mEventData )
3831 mImpl->mEventData->mCheckScrollAmount = true;
3833 // The natural size needs to be re-calculated.
3834 mImpl->mRecalculateNaturalSize = true;
3836 // The text direction needs to be updated.
3837 mImpl->mUpdateTextDirection = true;
3839 // Apply modifications to the model; TODO - Optimize this
3840 mImpl->mOperationsPending = ALL_OPERATIONS;
3843 void Controller::TextDeletedEvent()
3845 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3847 if( NULL == mImpl->mEventData )
3852 mImpl->mEventData->mCheckScrollAmount = true;
3854 // The natural size needs to be re-calculated.
3855 mImpl->mRecalculateNaturalSize = true;
3857 // The text direction needs to be updated.
3858 mImpl->mUpdateTextDirection = true;
3860 // Apply modifications to the model; TODO - Optimize this
3861 mImpl->mOperationsPending = ALL_OPERATIONS;
3864 void Controller::SelectEvent( float x, float y, bool selectAll )
3866 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3868 if( NULL != mImpl->mEventData )
3872 Event event( Event::SELECT_ALL );
3873 mImpl->mEventData->mEventQueue.push_back( event );
3877 Event event( Event::SELECT );
3878 event.p2.mFloat = x;
3879 event.p3.mFloat = y;
3880 mImpl->mEventData->mEventQueue.push_back( event );
3883 mImpl->mEventData->mCheckScrollAmount = true;
3884 mImpl->mEventData->mIsLeftHandleSelected = true;
3885 mImpl->mEventData->mIsRightHandleSelected = true;
3886 mImpl->RequestRelayout();
3890 bool Controller::DeleteEvent( int keyCode )
3892 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3894 bool removed = false;
3896 if( NULL == mImpl->mEventData )
3901 // InputMethodContext is no longer handling key-events
3902 mImpl->ClearPreEditFlag();
3904 if( EventData::SELECTING == mImpl->mEventData->mState )
3906 removed = RemoveSelectedText();
3908 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3910 // Remove the character before the current cursor position
3911 removed = RemoveText( -1,
3913 UPDATE_INPUT_STYLE );
3915 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
3917 // Remove the character after the current cursor position
3918 removed = RemoveText( 0,
3920 UPDATE_INPUT_STYLE );
3925 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3926 !mImpl->IsPlaceholderAvailable() )
3928 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3932 ShowPlaceholderText();
3934 mImpl->mEventData->mUpdateCursorPosition = true;
3935 mImpl->mEventData->mScrollAfterDelete = true;
3941 // private : Helpers.
3943 void Controller::ResetText()
3946 mImpl->mModel->mLogicalModel->mText.Clear();
3948 // Reset the embedded images buffer.
3949 mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
3951 // We have cleared everything including the placeholder-text
3952 mImpl->PlaceholderCleared();
3954 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3955 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3956 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3958 // Clear any previous text.
3959 mImpl->mTextUpdateInfo.mClearAll = true;
3961 // The natural size needs to be re-calculated.
3962 mImpl->mRecalculateNaturalSize = true;
3964 // The text direction needs to be updated.
3965 mImpl->mUpdateTextDirection = true;
3967 // Apply modifications to the model
3968 mImpl->mOperationsPending = ALL_OPERATIONS;
3971 void Controller::ShowPlaceholderText()
3973 if( mImpl->IsPlaceholderAvailable() )
3975 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3977 if( NULL == mImpl->mEventData )
3982 mImpl->mEventData->mIsShowingPlaceholderText = true;
3984 // Disable handles when showing place-holder text
3985 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3986 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3987 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3989 const char* text( NULL );
3992 // TODO - Switch Placeholder text when changing state
3993 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3994 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3996 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3997 size = mImpl->mEventData->mPlaceholderTextActive.size();
4001 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4002 size = mImpl->mEventData->mPlaceholderTextInactive.size();
4005 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4006 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4008 // Reset model for showing placeholder.
4009 mImpl->mModel->mLogicalModel->mText.Clear();
4010 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4012 // Convert text into UTF-32
4013 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4014 utf32Characters.Resize( size );
4016 // This is a bit horrible but std::string returns a (signed) char*
4017 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4019 // Transform a text array encoded in utf8 into an array encoded in utf32.
4020 // It returns the actual number of characters.
4021 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4022 utf32Characters.Resize( characterCount );
4024 // The characters to be added.
4025 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4027 // Reset the cursor position
4028 mImpl->mEventData->mPrimaryCursorPosition = 0;
4030 // The natural size needs to be re-calculated.
4031 mImpl->mRecalculateNaturalSize = true;
4033 // The text direction needs to be updated.
4034 mImpl->mUpdateTextDirection = true;
4036 // Apply modifications to the model
4037 mImpl->mOperationsPending = ALL_OPERATIONS;
4039 // Update the rest of the model during size negotiation
4040 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4044 void Controller::ClearFontData()
4046 if( mImpl->mFontDefaults )
4048 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4051 // Set flags to update the model.
4052 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4053 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4054 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4056 mImpl->mTextUpdateInfo.mClearAll = true;
4057 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4058 mImpl->mRecalculateNaturalSize = true;
4060 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4066 UPDATE_LAYOUT_SIZE |
4071 void Controller::ClearStyleData()
4073 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4074 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4077 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4079 // Reset the cursor position
4080 if( NULL != mImpl->mEventData )
4082 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4084 // Update the cursor if it's in editing mode.
4085 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4087 mImpl->mEventData->mUpdateCursorPosition = true;
4092 void Controller::ResetScrollPosition()
4094 if( NULL != mImpl->mEventData )
4096 // Reset the scroll position.
4097 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4098 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4102 void Controller::SetControlInterface( ControlInterface* controlInterface )
4104 mImpl->mControlInterface = controlInterface;
4107 bool Controller::ShouldClearFocusOnEscape() const
4109 return mImpl->mShouldClearFocusOnEscape;
4112 // private : Private contructors & copy operator.
4114 Controller::Controller()
4117 mImpl = new Controller::Impl( NULL, NULL );
4120 Controller::Controller( ControlInterface* controlInterface )
4122 mImpl = new Controller::Impl( controlInterface, NULL );
4125 Controller::Controller( ControlInterface* controlInterface,
4126 EditableControlInterface* editableControlInterface )
4128 mImpl = new Controller::Impl( controlInterface,
4129 editableControlInterface );
4132 // The copy constructor and operator are left unimplemented.
4134 // protected : Destructor.
4136 Controller::~Controller()
4143 } // namespace Toolkit