2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
28 #include <dali/devel-api/adaptor-framework/key-devel.h>
31 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
32 #include <dali-toolkit/internal/text/bidirectional-support.h>
33 #include <dali-toolkit/internal/text/character-set-conversion.h>
34 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
35 #include <dali-toolkit/internal/text/markup-processor.h>
36 #include <dali-toolkit/internal/text/multi-language-support.h>
37 #include <dali-toolkit/internal/text/text-controller-impl.h>
38 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
39 #include <dali-toolkit/internal/text/text-font-style.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
48 const float MAX_FLOAT = std::numeric_limits<float>::max();
50 const std::string EMPTY_STRING("");
52 const std::string KEY_C_NAME = "c";
53 const std::string KEY_V_NAME = "v";
54 const std::string KEY_X_NAME = "x";
56 const char * const PLACEHOLDER_TEXT = "text";
57 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
58 const char * const PLACEHOLDER_COLOR = "color";
59 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
60 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
61 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
62 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
63 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 float ConvertToEven( float value )
67 int intValue(static_cast<int>( value ));
68 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
83 * @brief Adds a new font description run for the selected text.
85 * The new font parameters are added after the call to this method.
87 * @param[in] eventData The event data pointer.
88 * @param[in] logicalModel The logical model where to add the new font description run.
89 * @param[out] startOfSelectedText Index to the first selected character.
90 * @param[out] lengthOfSelectedText Number of selected characters.
92 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
93 LogicalModelPtr logicalModel,
94 CharacterIndex& startOfSelectedText,
95 Length& lengthOfSelectedText )
97 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
99 // Get start and end position of selection
100 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
101 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
104 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
105 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
107 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
109 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
110 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
112 // Recalculate the selection highlight as the metrics may have changed.
113 eventData->mUpdateLeftSelectionPosition = true;
114 eventData->mUpdateRightSelectionPosition = true;
115 eventData->mUpdateHighlightBox = true;
117 return fontDescriptionRun;
120 // public : Constructor.
122 ControllerPtr Controller::New()
124 return ControllerPtr( new Controller() );
127 ControllerPtr Controller::New( ControlInterface* controlInterface )
129 return ControllerPtr( new Controller( controlInterface ) );
132 ControllerPtr Controller::New( ControlInterface* controlInterface,
133 EditableControlInterface* editableControlInterface )
135 return ControllerPtr( new Controller( controlInterface,
136 editableControlInterface ) );
139 // public : Configure the text controller.
141 void Controller::EnableTextInput( DecoratorPtr decorator, 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 mImpl->RequestRelayout();
368 bool Controller::IsMultiLineEnabled() const
370 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
373 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
375 if( alignment != mImpl->mModel->mHorizontalAlignment )
377 // Set the alignment.
378 mImpl->mModel->mHorizontalAlignment = alignment;
380 // Set the flag to redo the alignment operation.
381 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
383 mImpl->RequestRelayout();
387 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
389 return mImpl->mModel->mHorizontalAlignment;
392 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
394 if( alignment != mImpl->mModel->mVerticalAlignment )
396 // Set the alignment.
397 mImpl->mModel->mVerticalAlignment = alignment;
399 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
401 mImpl->RequestRelayout();
405 VerticalAlignment::Type Controller::GetVerticalAlignment() const
407 return mImpl->mModel->mVerticalAlignment;
410 bool Controller::IsIgnoreSpacesAfterText() const
412 return mImpl->mModel->mIgnoreSpacesAfterText;
415 void Controller::SetIgnoreSpacesAfterText( bool ignore )
417 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
420 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
422 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
424 // Set the text wrap mode.
425 mImpl->mModel->mLineWrapMode = lineWrapMode;
428 // Update Text layout for applying wrap mode
429 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
434 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
435 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
436 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
439 mImpl->RequestRelayout();
443 Text::LineWrap::Mode Controller::GetLineWrapMode() const
445 return mImpl->mModel->mLineWrapMode;
448 void Controller::SetTextElideEnabled( bool enabled )
450 mImpl->mModel->mElideEnabled = enabled;
453 bool Controller::IsTextElideEnabled() const
455 return mImpl->mModel->mElideEnabled;
458 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
460 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
461 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
463 // Update placeholder if there is no text
464 if( mImpl->IsShowingPlaceholderText() ||
465 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
467 ShowPlaceholderText();
471 bool Controller::IsPlaceholderTextElideEnabled() const
473 return mImpl->mEventData->mIsPlaceholderElideEnabled;
476 void Controller::SetSelectionEnabled( bool enabled )
478 mImpl->mEventData->mSelectionEnabled = enabled;
481 bool Controller::IsSelectionEnabled() const
483 return mImpl->mEventData->mSelectionEnabled;
486 void Controller::SetShiftSelectionEnabled( bool enabled )
488 mImpl->mEventData->mShiftSelectionFlag = enabled;
491 bool Controller::IsShiftSelectionEnabled() const
493 return mImpl->mEventData->mShiftSelectionFlag;
496 void Controller::SetGrabHandleEnabled( bool enabled )
498 mImpl->mEventData->mGrabHandleEnabled = enabled;
501 bool Controller::IsGrabHandleEnabled() const
503 return mImpl->mEventData->mGrabHandleEnabled;
508 void Controller::SetText( const std::string& text )
510 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
512 // Reset keyboard as text changed
513 mImpl->ResetInputMethodContext();
515 // Remove the previously set text and style.
521 CharacterIndex lastCursorIndex = 0u;
523 if( NULL != mImpl->mEventData )
525 // If popup shown then hide it by switching to Editing state
526 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
527 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
528 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
529 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
531 mImpl->ChangeState( EventData::EDITING );
537 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
539 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
540 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
542 Length textSize = 0u;
543 const uint8_t* utf8 = NULL;
544 if( mImpl->mMarkupProcessorEnabled )
546 ProcessMarkupString( text, markupProcessData );
547 textSize = markupProcessData.markupProcessedText.size();
549 // This is a bit horrible but std::string returns a (signed) char*
550 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
554 textSize = text.size();
556 // This is a bit horrible but std::string returns a (signed) char*
557 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
560 // Convert text into UTF-32
561 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
562 utf32Characters.Resize( textSize );
564 // Transform a text array encoded in utf8 into an array encoded in utf32.
565 // It returns the actual number of characters.
566 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
567 utf32Characters.Resize( characterCount );
569 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
570 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
572 // The characters to be added.
573 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
575 // To reset the cursor position
576 lastCursorIndex = characterCount;
578 // Update the rest of the model during size negotiation
579 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
581 // The natural size needs to be re-calculated.
582 mImpl->mRecalculateNaturalSize = true;
584 // The text direction needs to be updated.
585 mImpl->mUpdateTextDirection = true;
587 // Apply modifications to the model
588 mImpl->mOperationsPending = ALL_OPERATIONS;
592 ShowPlaceholderText();
595 // Resets the cursor position.
596 ResetCursorPosition( lastCursorIndex );
598 // Scrolls the text to make the cursor visible.
599 ResetScrollPosition();
601 mImpl->RequestRelayout();
603 if( NULL != mImpl->mEventData )
605 // Cancel previously queued events
606 mImpl->mEventData->mEventQueue.clear();
609 // Do this last since it provides callbacks into application code.
610 if( NULL != mImpl->mEditableControlInterface )
612 mImpl->mEditableControlInterface->TextChanged();
616 void Controller::GetText( std::string& text ) const
618 if( !mImpl->IsShowingPlaceholderText() )
620 // Retrieves the text string.
621 mImpl->GetText( 0u, text );
625 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
629 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
631 if( NULL != mImpl->mEventData )
633 if( PLACEHOLDER_TYPE_INACTIVE == type )
635 mImpl->mEventData->mPlaceholderTextInactive = text;
639 mImpl->mEventData->mPlaceholderTextActive = text;
642 // Update placeholder if there is no text
643 if( mImpl->IsShowingPlaceholderText() ||
644 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
646 ShowPlaceholderText();
651 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
653 if( NULL != mImpl->mEventData )
655 if( PLACEHOLDER_TYPE_INACTIVE == type )
657 text = mImpl->mEventData->mPlaceholderTextInactive;
661 text = mImpl->mEventData->mPlaceholderTextActive;
666 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
668 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
670 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
672 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
673 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
677 mImpl->RequestRelayout();
681 // public : Default style & Input style
683 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
685 if( NULL == mImpl->mFontDefaults )
687 mImpl->mFontDefaults = new FontDefaults();
690 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
691 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
692 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
694 // Clear the font-specific data
697 mImpl->RequestRelayout();
700 const std::string& Controller::GetDefaultFontFamily() const
702 if( NULL != mImpl->mFontDefaults )
704 return mImpl->mFontDefaults->mFontDescription.family;
710 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
712 if( NULL != mImpl->mEventData )
714 if( NULL == mImpl->mEventData->mPlaceholderFont )
716 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
719 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
720 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
721 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
723 mImpl->RequestRelayout();
727 const std::string& Controller::GetPlaceholderFontFamily() const
729 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
731 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
737 void Controller::SetDefaultFontWeight( FontWeight weight )
739 if( NULL == mImpl->mFontDefaults )
741 mImpl->mFontDefaults = new FontDefaults();
744 mImpl->mFontDefaults->mFontDescription.weight = weight;
745 mImpl->mFontDefaults->weightDefined = true;
747 // Clear the font-specific data
750 mImpl->RequestRelayout();
753 bool Controller::IsDefaultFontWeightDefined() const
755 if( NULL != mImpl->mFontDefaults )
757 return mImpl->mFontDefaults->weightDefined;
763 FontWeight Controller::GetDefaultFontWeight() const
765 if( NULL != mImpl->mFontDefaults )
767 return mImpl->mFontDefaults->mFontDescription.weight;
770 return TextAbstraction::FontWeight::NORMAL;
773 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
775 if( NULL != mImpl->mEventData )
777 if( NULL == mImpl->mEventData->mPlaceholderFont )
779 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
782 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
783 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
785 mImpl->RequestRelayout();
789 bool Controller::IsPlaceholderTextFontWeightDefined() const
791 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
793 return mImpl->mEventData->mPlaceholderFont->weightDefined;
798 FontWeight Controller::GetPlaceholderTextFontWeight() const
800 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
802 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
805 return TextAbstraction::FontWeight::NORMAL;
808 void Controller::SetDefaultFontWidth( FontWidth width )
810 if( NULL == mImpl->mFontDefaults )
812 mImpl->mFontDefaults = new FontDefaults();
815 mImpl->mFontDefaults->mFontDescription.width = width;
816 mImpl->mFontDefaults->widthDefined = true;
818 // Clear the font-specific data
821 mImpl->RequestRelayout();
824 bool Controller::IsDefaultFontWidthDefined() const
826 if( NULL != mImpl->mFontDefaults )
828 return mImpl->mFontDefaults->widthDefined;
834 FontWidth Controller::GetDefaultFontWidth() const
836 if( NULL != mImpl->mFontDefaults )
838 return mImpl->mFontDefaults->mFontDescription.width;
841 return TextAbstraction::FontWidth::NORMAL;
844 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
846 if( NULL != mImpl->mEventData )
848 if( NULL == mImpl->mEventData->mPlaceholderFont )
850 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
853 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
854 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
856 mImpl->RequestRelayout();
860 bool Controller::IsPlaceholderTextFontWidthDefined() const
862 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
864 return mImpl->mEventData->mPlaceholderFont->widthDefined;
869 FontWidth Controller::GetPlaceholderTextFontWidth() const
871 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
873 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
876 return TextAbstraction::FontWidth::NORMAL;
879 void Controller::SetDefaultFontSlant( FontSlant slant )
881 if( NULL == mImpl->mFontDefaults )
883 mImpl->mFontDefaults = new FontDefaults();
886 mImpl->mFontDefaults->mFontDescription.slant = slant;
887 mImpl->mFontDefaults->slantDefined = true;
889 // Clear the font-specific data
892 mImpl->RequestRelayout();
895 bool Controller::IsDefaultFontSlantDefined() const
897 if( NULL != mImpl->mFontDefaults )
899 return mImpl->mFontDefaults->slantDefined;
904 FontSlant Controller::GetDefaultFontSlant() const
906 if( NULL != mImpl->mFontDefaults )
908 return mImpl->mFontDefaults->mFontDescription.slant;
911 return TextAbstraction::FontSlant::NORMAL;
914 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
916 if( NULL != mImpl->mEventData )
918 if( NULL == mImpl->mEventData->mPlaceholderFont )
920 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
923 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
924 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
926 mImpl->RequestRelayout();
930 bool Controller::IsPlaceholderTextFontSlantDefined() const
932 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
934 return mImpl->mEventData->mPlaceholderFont->slantDefined;
939 FontSlant Controller::GetPlaceholderTextFontSlant() const
941 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
943 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
946 return TextAbstraction::FontSlant::NORMAL;
949 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
951 if( NULL == mImpl->mFontDefaults )
953 mImpl->mFontDefaults = new FontDefaults();
960 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
961 mImpl->mFontDefaults->sizeDefined = true;
966 // Point size = Pixel size * 72.f / DPI
967 unsigned int horizontalDpi = 0u;
968 unsigned int verticalDpi = 0u;
969 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
970 fontClient.GetDpi( horizontalDpi, verticalDpi );
972 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
973 mImpl->mFontDefaults->sizeDefined = true;
978 // Clear the font-specific data
981 mImpl->RequestRelayout();
984 float Controller::GetDefaultFontSize( FontSizeType type ) const
987 if( NULL != mImpl->mFontDefaults )
993 value = mImpl->mFontDefaults->mDefaultPointSize;
998 // Pixel size = Point size * DPI / 72.f
999 unsigned int horizontalDpi = 0u;
1000 unsigned int verticalDpi = 0u;
1001 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1002 fontClient.GetDpi( horizontalDpi, verticalDpi );
1004 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1014 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1016 if( NULL != mImpl->mEventData )
1018 if( NULL == mImpl->mEventData->mPlaceholderFont )
1020 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1027 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1028 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1029 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1034 // Point size = Pixel size * 72.f / DPI
1035 unsigned int horizontalDpi = 0u;
1036 unsigned int verticalDpi = 0u;
1037 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1038 fontClient.GetDpi( horizontalDpi, verticalDpi );
1040 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1041 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1042 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1047 mImpl->RequestRelayout();
1051 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1054 if( NULL != mImpl->mEventData )
1060 if( NULL != mImpl->mEventData->mPlaceholderFont )
1062 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1066 // If the placeholder text font size is not set, then return the default font size.
1067 value = GetDefaultFontSize( POINT_SIZE );
1073 if( NULL != mImpl->mEventData->mPlaceholderFont )
1075 // Pixel size = Point size * DPI / 72.f
1076 unsigned int horizontalDpi = 0u;
1077 unsigned int verticalDpi = 0u;
1078 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1079 fontClient.GetDpi( horizontalDpi, verticalDpi );
1081 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1085 // If the placeholder text font size is not set, then return the default font size.
1086 value = GetDefaultFontSize( PIXEL_SIZE );
1097 void Controller::SetDefaultColor( const Vector4& color )
1099 mImpl->mTextColor = color;
1101 if( !mImpl->IsShowingPlaceholderText() )
1103 mImpl->mModel->mVisualModel->SetTextColor( color );
1105 mImpl->RequestRelayout();
1109 const Vector4& Controller::GetDefaultColor() const
1111 return mImpl->mTextColor;
1114 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1116 if( NULL != mImpl->mEventData )
1118 mImpl->mEventData->mPlaceholderTextColor = textColor;
1121 if( mImpl->IsShowingPlaceholderText() )
1123 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1124 mImpl->RequestRelayout();
1128 const Vector4& Controller::GetPlaceholderTextColor() const
1130 if( NULL != mImpl->mEventData )
1132 return mImpl->mEventData->mPlaceholderTextColor;
1135 return Color::BLACK;
1138 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1140 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1142 mImpl->RequestRelayout();
1145 const Vector2& Controller::GetShadowOffset() const
1147 return mImpl->mModel->mVisualModel->GetShadowOffset();
1150 void Controller::SetShadowColor( const Vector4& shadowColor )
1152 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1154 mImpl->RequestRelayout();
1157 const Vector4& Controller::GetShadowColor() const
1159 return mImpl->mModel->mVisualModel->GetShadowColor();
1162 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1164 if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1166 mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1168 mImpl->RequestRelayout();
1172 const float& Controller::GetShadowBlurRadius() const
1174 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1177 void Controller::SetUnderlineColor( const Vector4& color )
1179 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1181 mImpl->RequestRelayout();
1184 const Vector4& Controller::GetUnderlineColor() const
1186 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1189 void Controller::SetUnderlineEnabled( bool enabled )
1191 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1193 mImpl->RequestRelayout();
1196 bool Controller::IsUnderlineEnabled() const
1198 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1201 void Controller::SetUnderlineHeight( float height )
1203 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1205 mImpl->RequestRelayout();
1208 float Controller::GetUnderlineHeight() const
1210 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1213 void Controller::SetOutlineColor( const Vector4& color )
1215 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1217 mImpl->RequestRelayout();
1220 const Vector4& Controller::GetOutlineColor() const
1222 return mImpl->mModel->mVisualModel->GetOutlineColor();
1225 void Controller::SetOutlineWidth( unsigned int width )
1227 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1229 mImpl->RequestRelayout();
1232 unsigned int Controller::GetOutlineWidth() const
1234 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1237 void Controller::SetBackgroundColor( const Vector4& color )
1239 mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1241 mImpl->RequestRelayout();
1244 const Vector4& Controller::GetBackgroundColor() const
1246 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1249 void Controller::SetBackgroundEnabled( bool enabled )
1251 mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1253 mImpl->RequestRelayout();
1256 bool Controller::IsBackgroundEnabled() const
1258 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1261 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1263 if( NULL == mImpl->mEmbossDefaults )
1265 mImpl->mEmbossDefaults = new EmbossDefaults();
1268 mImpl->mEmbossDefaults->properties = embossProperties;
1271 const std::string& Controller::GetDefaultEmbossProperties() const
1273 if( NULL != mImpl->mEmbossDefaults )
1275 return mImpl->mEmbossDefaults->properties;
1278 return EMPTY_STRING;
1281 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1283 if( NULL == mImpl->mOutlineDefaults )
1285 mImpl->mOutlineDefaults = new OutlineDefaults();
1288 mImpl->mOutlineDefaults->properties = outlineProperties;
1291 const std::string& Controller::GetDefaultOutlineProperties() const
1293 if( NULL != mImpl->mOutlineDefaults )
1295 return mImpl->mOutlineDefaults->properties;
1298 return EMPTY_STRING;
1301 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1303 if( std::abs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000 )
1305 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1306 mImpl->mRecalculateNaturalSize = true;
1312 float Controller::GetDefaultLineSpacing() const
1314 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1317 void Controller::SetInputColor( const Vector4& color )
1319 if( NULL != mImpl->mEventData )
1321 mImpl->mEventData->mInputStyle.textColor = color;
1322 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1324 if( EventData::SELECTING == mImpl->mEventData->mState )
1326 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1328 // Get start and end position of selection
1329 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1330 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1332 // Add the color run.
1333 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1334 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1336 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1337 colorRun.color = color;
1338 colorRun.characterRun.characterIndex = startOfSelectedText;
1339 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1341 // Request to relayout.
1342 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1343 mImpl->RequestRelayout();
1345 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1346 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1347 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1352 const Vector4& Controller::GetInputColor() const
1354 if( NULL != mImpl->mEventData )
1356 return mImpl->mEventData->mInputStyle.textColor;
1359 // Return the default text's color if there is no EventData.
1360 return mImpl->mTextColor;
1364 void Controller::SetInputFontFamily( const std::string& fontFamily )
1366 if( NULL != mImpl->mEventData )
1368 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1369 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1371 if( EventData::SELECTING == mImpl->mEventData->mState )
1373 CharacterIndex startOfSelectedText = 0u;
1374 Length lengthOfSelectedText = 0u;
1375 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1376 mImpl->mModel->mLogicalModel,
1377 startOfSelectedText,
1378 lengthOfSelectedText );
1380 fontDescriptionRun.familyLength = fontFamily.size();
1381 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1382 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1383 fontDescriptionRun.familyDefined = true;
1385 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1387 // Request to relayout.
1388 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1393 UPDATE_LAYOUT_SIZE |
1396 mImpl->mRecalculateNaturalSize = true;
1397 mImpl->RequestRelayout();
1399 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1400 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1401 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1403 // As the font changes, recalculate the handle positions is needed.
1404 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1405 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1406 mImpl->mEventData->mUpdateHighlightBox = true;
1407 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1412 const std::string& Controller::GetInputFontFamily() const
1414 if( NULL != mImpl->mEventData )
1416 return mImpl->mEventData->mInputStyle.familyName;
1419 // Return the default font's family if there is no EventData.
1420 return GetDefaultFontFamily();
1423 void Controller::SetInputFontWeight( FontWeight weight )
1425 if( NULL != mImpl->mEventData )
1427 mImpl->mEventData->mInputStyle.weight = weight;
1428 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1430 if( EventData::SELECTING == mImpl->mEventData->mState )
1432 CharacterIndex startOfSelectedText = 0u;
1433 Length lengthOfSelectedText = 0u;
1434 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1435 mImpl->mModel->mLogicalModel,
1436 startOfSelectedText,
1437 lengthOfSelectedText );
1439 fontDescriptionRun.weight = weight;
1440 fontDescriptionRun.weightDefined = true;
1442 // Request to relayout.
1443 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1448 UPDATE_LAYOUT_SIZE |
1451 mImpl->mRecalculateNaturalSize = true;
1452 mImpl->RequestRelayout();
1454 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1455 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1456 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1458 // As the font might change, recalculate the handle positions is needed.
1459 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1460 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1461 mImpl->mEventData->mUpdateHighlightBox = true;
1462 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1467 bool Controller::IsInputFontWeightDefined() const
1469 bool defined = false;
1471 if( NULL != mImpl->mEventData )
1473 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1479 FontWeight Controller::GetInputFontWeight() const
1481 if( NULL != mImpl->mEventData )
1483 return mImpl->mEventData->mInputStyle.weight;
1486 return GetDefaultFontWeight();
1489 void Controller::SetInputFontWidth( FontWidth width )
1491 if( NULL != mImpl->mEventData )
1493 mImpl->mEventData->mInputStyle.width = width;
1494 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1496 if( EventData::SELECTING == mImpl->mEventData->mState )
1498 CharacterIndex startOfSelectedText = 0u;
1499 Length lengthOfSelectedText = 0u;
1500 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1501 mImpl->mModel->mLogicalModel,
1502 startOfSelectedText,
1503 lengthOfSelectedText );
1505 fontDescriptionRun.width = width;
1506 fontDescriptionRun.widthDefined = true;
1508 // Request to relayout.
1509 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1514 UPDATE_LAYOUT_SIZE |
1517 mImpl->mRecalculateNaturalSize = true;
1518 mImpl->RequestRelayout();
1520 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1521 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1522 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1524 // As the font might change, recalculate the handle positions is needed.
1525 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1526 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1527 mImpl->mEventData->mUpdateHighlightBox = true;
1528 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1533 bool Controller::IsInputFontWidthDefined() const
1535 bool defined = false;
1537 if( NULL != mImpl->mEventData )
1539 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1545 FontWidth Controller::GetInputFontWidth() const
1547 if( NULL != mImpl->mEventData )
1549 return mImpl->mEventData->mInputStyle.width;
1552 return GetDefaultFontWidth();
1555 void Controller::SetInputFontSlant( FontSlant slant )
1557 if( NULL != mImpl->mEventData )
1559 mImpl->mEventData->mInputStyle.slant = slant;
1560 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1562 if( EventData::SELECTING == mImpl->mEventData->mState )
1564 CharacterIndex startOfSelectedText = 0u;
1565 Length lengthOfSelectedText = 0u;
1566 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1567 mImpl->mModel->mLogicalModel,
1568 startOfSelectedText,
1569 lengthOfSelectedText );
1571 fontDescriptionRun.slant = slant;
1572 fontDescriptionRun.slantDefined = true;
1574 // Request to relayout.
1575 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1580 UPDATE_LAYOUT_SIZE |
1583 mImpl->mRecalculateNaturalSize = true;
1584 mImpl->RequestRelayout();
1586 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1587 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1588 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1590 // As the font might change, recalculate the handle positions is needed.
1591 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1592 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1593 mImpl->mEventData->mUpdateHighlightBox = true;
1594 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1599 bool Controller::IsInputFontSlantDefined() const
1601 bool defined = false;
1603 if( NULL != mImpl->mEventData )
1605 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1611 FontSlant Controller::GetInputFontSlant() const
1613 if( NULL != mImpl->mEventData )
1615 return mImpl->mEventData->mInputStyle.slant;
1618 return GetDefaultFontSlant();
1621 void Controller::SetInputFontPointSize( float size )
1623 if( NULL != mImpl->mEventData )
1625 mImpl->mEventData->mInputStyle.size = size;
1626 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1628 if( EventData::SELECTING == mImpl->mEventData->mState )
1630 CharacterIndex startOfSelectedText = 0u;
1631 Length lengthOfSelectedText = 0u;
1632 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1633 mImpl->mModel->mLogicalModel,
1634 startOfSelectedText,
1635 lengthOfSelectedText );
1637 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1638 fontDescriptionRun.sizeDefined = true;
1640 // Request to relayout.
1641 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1646 UPDATE_LAYOUT_SIZE |
1649 mImpl->mRecalculateNaturalSize = true;
1650 mImpl->RequestRelayout();
1652 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1653 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1654 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1656 // As the font might change, recalculate the handle positions is needed.
1657 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1658 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1659 mImpl->mEventData->mUpdateHighlightBox = true;
1660 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1665 float Controller::GetInputFontPointSize() const
1667 if( NULL != mImpl->mEventData )
1669 return mImpl->mEventData->mInputStyle.size;
1672 // Return the default font's point size if there is no EventData.
1673 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1676 void Controller::SetInputLineSpacing( float lineSpacing )
1678 if( NULL != mImpl->mEventData )
1680 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1681 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1685 float Controller::GetInputLineSpacing() const
1687 if( NULL != mImpl->mEventData )
1689 return mImpl->mEventData->mInputStyle.lineSpacing;
1695 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1697 if( NULL != mImpl->mEventData )
1699 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1703 const std::string& Controller::GetInputShadowProperties() const
1705 if( NULL != mImpl->mEventData )
1707 return mImpl->mEventData->mInputStyle.shadowProperties;
1710 return EMPTY_STRING;
1713 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1715 if( NULL != mImpl->mEventData )
1717 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1721 const std::string& Controller::GetInputUnderlineProperties() const
1723 if( NULL != mImpl->mEventData )
1725 return mImpl->mEventData->mInputStyle.underlineProperties;
1728 return EMPTY_STRING;
1731 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1733 if( NULL != mImpl->mEventData )
1735 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1739 const std::string& Controller::GetInputEmbossProperties() const
1741 if( NULL != mImpl->mEventData )
1743 return mImpl->mEventData->mInputStyle.embossProperties;
1746 return GetDefaultEmbossProperties();
1749 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1751 if( NULL != mImpl->mEventData )
1753 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1757 const std::string& Controller::GetInputOutlineProperties() const
1759 if( NULL != mImpl->mEventData )
1761 return mImpl->mEventData->mInputStyle.outlineProperties;
1764 return GetDefaultOutlineProperties();
1767 void Controller::SetInputModePassword( bool passwordInput )
1769 if( NULL != mImpl->mEventData )
1771 mImpl->mEventData->mPasswordInput = passwordInput;
1775 bool Controller::IsInputModePassword()
1777 if( NULL != mImpl->mEventData )
1779 return mImpl->mEventData->mPasswordInput;
1784 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1786 if( NULL != mImpl->mEventData )
1788 mImpl->mEventData->mDoubleTapAction = action;
1792 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1794 NoTextTap::Action action = NoTextTap::NO_ACTION;
1796 if( NULL != mImpl->mEventData )
1798 action = mImpl->mEventData->mDoubleTapAction;
1804 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1806 if( NULL != mImpl->mEventData )
1808 mImpl->mEventData->mLongPressAction = action;
1812 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1814 NoTextTap::Action action = NoTextTap::NO_ACTION;
1816 if( NULL != mImpl->mEventData )
1818 action = mImpl->mEventData->mLongPressAction;
1824 bool Controller::IsUnderlineSetByString()
1826 return mImpl->mUnderlineSetByString;
1829 void Controller::UnderlineSetByString( bool setByString )
1831 mImpl->mUnderlineSetByString = setByString;
1834 bool Controller::IsShadowSetByString()
1836 return mImpl->mShadowSetByString;
1839 void Controller::ShadowSetByString( bool setByString )
1841 mImpl->mShadowSetByString = setByString;
1844 bool Controller::IsOutlineSetByString()
1846 return mImpl->mOutlineSetByString;
1849 void Controller::OutlineSetByString( bool setByString )
1851 mImpl->mOutlineSetByString = setByString;
1854 bool Controller::IsFontStyleSetByString()
1856 return mImpl->mFontStyleSetByString;
1859 void Controller::FontStyleSetByString( bool setByString )
1861 mImpl->mFontStyleSetByString = setByString;
1864 // public : Queries & retrieves.
1866 Layout::Engine& Controller::GetLayoutEngine()
1868 return mImpl->mLayoutEngine;
1871 View& Controller::GetView()
1873 return mImpl->mView;
1876 Vector3 Controller::GetNaturalSize()
1878 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1879 Vector3 naturalSize;
1881 // Make sure the model is up-to-date before layouting
1882 ProcessModifyEvents();
1884 if( mImpl->mRecalculateNaturalSize )
1886 // Operations that can be done only once until the text changes.
1887 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1894 GET_GLYPH_METRICS );
1896 // Set the update info to relayout the whole text.
1897 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1898 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1900 // Make sure the model is up-to-date before layouting
1901 mImpl->UpdateModel( onlyOnceOperations );
1903 // Layout the text for the new width.
1904 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1906 // Store the actual control's size to restore later.
1907 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1909 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1910 static_cast<OperationsMask>( onlyOnceOperations |
1912 naturalSize.GetVectorXY() );
1914 // Do not do again the only once operations.
1915 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1917 // Do the size related operations again.
1918 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1921 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1923 // Stores the natural size to avoid recalculate it again
1924 // unless the text/style changes.
1925 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1927 mImpl->mRecalculateNaturalSize = false;
1929 // Clear the update info. This info will be set the next time the text is updated.
1930 mImpl->mTextUpdateInfo.Clear();
1931 mImpl->mTextUpdateInfo.mClearAll = true;
1933 // Restore the actual control's size.
1934 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1936 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1940 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1942 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1945 naturalSize.x = ConvertToEven( naturalSize.x );
1946 naturalSize.y = ConvertToEven( naturalSize.y );
1951 float Controller::GetHeightForWidth( float width )
1953 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1954 // Make sure the model is up-to-date before layouting
1955 ProcessModifyEvents();
1958 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1959 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1960 mImpl->mTextUpdateInfo.mClearAll )
1962 // Operations that can be done only once until the text changes.
1963 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1970 GET_GLYPH_METRICS );
1972 // Set the update info to relayout the whole text.
1973 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1974 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1976 // Make sure the model is up-to-date before layouting
1977 mImpl->UpdateModel( onlyOnceOperations );
1980 // Layout the text for the new width.
1981 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1983 // Store the actual control's width.
1984 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1986 DoRelayout( Size( width, MAX_FLOAT ),
1987 static_cast<OperationsMask>( onlyOnceOperations |
1991 // Do not do again the only once operations.
1992 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1994 // Do the size related operations again.
1995 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1999 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2001 // Clear the update info. This info will be set the next time the text is updated.
2002 mImpl->mTextUpdateInfo.Clear();
2003 mImpl->mTextUpdateInfo.mClearAll = true;
2005 // Restore the actual control's width.
2006 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2008 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2012 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2013 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2016 return layoutSize.height;
2019 int Controller::GetLineCount( float width )
2021 GetHeightForWidth( width );
2022 int numberofLines = mImpl->mModel->GetNumberOfLines();
2023 return numberofLines;
2026 const ModelInterface* const Controller::GetTextModel() const
2028 return mImpl->mModel.Get();
2031 float Controller::GetScrollAmountByUserInput()
2033 float scrollAmount = 0.0f;
2035 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2037 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
2038 mImpl->mEventData->mCheckScrollAmount = false;
2040 return scrollAmount;
2043 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2045 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2048 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2049 layoutHeight = layout.height;
2050 scrollPosition = mImpl->mModel->mScrollPosition.y;
2051 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2055 void Controller::SetHiddenInputOption(const Property::Map& options )
2057 if( NULL == mImpl->mHiddenInput )
2059 mImpl->mHiddenInput = new HiddenText( this );
2061 mImpl->mHiddenInput->SetProperties(options);
2064 void Controller::GetHiddenInputOption(Property::Map& options )
2066 if( NULL != mImpl->mHiddenInput )
2068 mImpl->mHiddenInput->GetProperties(options);
2072 void Controller::SetPlaceholderProperty( const Property::Map& map )
2074 const Property::Map::SizeType count = map.Count();
2076 for( Property::Map::SizeType position = 0; position < count; ++position )
2078 KeyValuePair keyValue = map.GetKeyValue( position );
2079 Property::Key& key = keyValue.first;
2080 Property::Value& value = keyValue.second;
2082 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
2084 std::string text = "";
2086 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2088 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2090 std::string text = "";
2092 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2094 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2097 value.Get( textColor );
2098 if( GetPlaceholderTextColor() != textColor )
2100 SetPlaceholderTextColor( textColor );
2103 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2105 std::string fontFamily = "";
2106 value.Get( fontFamily );
2107 SetPlaceholderFontFamily( fontFamily );
2109 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2111 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2113 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2116 value.Get( pointSize );
2117 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2119 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2122 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2125 value.Get( pixelSize );
2126 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2128 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2131 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2134 value.Get( ellipsis );
2135 SetPlaceholderTextElideEnabled( ellipsis );
2140 void Controller::GetPlaceholderProperty( Property::Map& map )
2142 if( NULL != mImpl->mEventData )
2144 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2146 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2148 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2150 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2153 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2154 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2156 Property::Value fontStyleMapGet;
2157 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2158 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2160 // Choose font size : POINT_SIZE or PIXEL_SIZE
2161 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2163 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2167 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2170 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2172 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2177 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2179 // Make sure the model is up-to-date before layouting
2180 ProcessModifyEvents();
2182 if ( mImpl->mUpdateTextDirection )
2184 // Operations that can be done only once until the text changes.
2185 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2192 GET_GLYPH_METRICS );
2194 // Set the update info to relayout the whole text.
2195 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2196 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2198 // Make sure the model is up-to-date before layouting
2199 mImpl->UpdateModel( onlyOnceOperations );
2201 Vector3 naturalSize;
2202 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2203 static_cast<OperationsMask>( onlyOnceOperations |
2204 LAYOUT | REORDER | UPDATE_DIRECTION ),
2205 naturalSize.GetVectorXY() );
2207 // Do not do again the only once operations.
2208 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2210 // Clear the update info. This info will be set the next time the text is updated.
2211 mImpl->mTextUpdateInfo.Clear();
2213 mImpl->mUpdateTextDirection = false;
2216 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2219 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2221 return mImpl->mModel->GetVerticalLineAlignment();
2224 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2226 mImpl->mModel->mVerticalLineAlignment = alignment;
2229 // public : Relayout.
2231 Controller::UpdateTextType Controller::Relayout( const Size& size )
2233 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2235 UpdateTextType updateTextType = NONE_UPDATED;
2237 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2239 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2241 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2242 updateTextType = MODEL_UPDATED;
2245 // Clear the update info. This info will be set the next time the text is updated.
2246 mImpl->mTextUpdateInfo.Clear();
2248 // Not worth to relayout if width or height is equal to zero.
2249 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2251 return updateTextType;
2254 // Whether a new size has been set.
2255 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2259 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2261 if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2262 ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2263 ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2265 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2268 // Layout operations that need to be done if the size changes.
2269 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2272 UPDATE_LAYOUT_SIZE |
2274 // Set the update info to relayout the whole text.
2275 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2276 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2278 // Store the size used to layout the text.
2279 mImpl->mModel->mVisualModel->mControlSize = size;
2282 // Whether there are modify events.
2283 if( 0u != mImpl->mModifyEvents.Count() )
2285 // Style operations that need to be done if the text is modified.
2286 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2290 // Set the update info to elide the text.
2291 if( mImpl->mModel->mElideEnabled ||
2292 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2294 // Update Text layout for applying elided
2295 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2298 UPDATE_LAYOUT_SIZE |
2300 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2301 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2304 // Make sure the model is up-to-date before layouting.
2305 ProcessModifyEvents();
2306 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2310 updated = DoRelayout( size,
2311 mImpl->mOperationsPending,
2312 layoutSize ) || updated;
2316 updateTextType = MODEL_UPDATED;
2319 // Do not re-do any operation until something changes.
2320 mImpl->mOperationsPending = NO_OPERATION;
2321 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2323 // Whether the text control is editable
2324 const bool isEditable = NULL != mImpl->mEventData;
2326 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2328 if( newSize && isEditable )
2330 offset = mImpl->mModel->mScrollPosition;
2333 if( !isEditable || !IsMultiLineEnabled() )
2335 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2336 CalculateVerticalOffset( size );
2343 // If there is a new size, the scroll position needs to be clamped.
2344 mImpl->ClampHorizontalScroll( layoutSize );
2346 // Update the decorator's positions is needed if there is a new size.
2347 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2350 // Move the cursor, grab handle etc.
2351 if( mImpl->ProcessInputEvents() )
2353 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2357 // Clear the update info. This info will be set the next time the text is updated.
2358 mImpl->mTextUpdateInfo.Clear();
2359 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2361 return updateTextType;
2364 void Controller::RequestRelayout()
2366 mImpl->RequestRelayout();
2369 // public : Input style change signals.
2371 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2373 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2376 void Controller::ProcessInputStyleChangedSignals()
2378 if( NULL == mImpl->mEventData )
2384 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2385 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2389 const InputStyle::Mask mask = *it;
2391 if( NULL != mImpl->mEditableControlInterface )
2393 // Emit the input style changed signal.
2394 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2398 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2401 // public : Text-input Event Queuing.
2403 void Controller::KeyboardFocusGainEvent()
2405 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2407 if( NULL != mImpl->mEventData )
2409 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2410 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2412 mImpl->ChangeState( EventData::EDITING );
2413 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2414 mImpl->mEventData->mUpdateInputStyle = true;
2416 mImpl->NotifyInputMethodContextMultiLineStatus();
2417 if( mImpl->IsShowingPlaceholderText() )
2419 // Show alternative placeholder-text when editing
2420 ShowPlaceholderText();
2423 mImpl->RequestRelayout();
2427 void Controller::KeyboardFocusLostEvent()
2429 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2431 if( NULL != mImpl->mEventData )
2433 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2435 mImpl->ChangeState( EventData::INACTIVE );
2437 if( !mImpl->IsShowingRealText() )
2439 // Revert to regular placeholder-text when not editing
2440 ShowPlaceholderText();
2444 mImpl->RequestRelayout();
2447 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2449 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2451 bool textChanged = false;
2452 bool relayoutNeeded = false;
2454 if( ( NULL != mImpl->mEventData ) &&
2455 ( keyEvent.state == KeyEvent::Down ) )
2457 int keyCode = keyEvent.keyCode;
2458 const std::string& keyString = keyEvent.keyPressed;
2459 const std::string keyName = keyEvent.keyPressedName;
2461 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2463 // Pre-process to separate modifying events from non-modifying input events.
2466 // In some platforms arrive key events with no key code.
2470 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
2475 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2476 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2477 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2478 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2480 // If don't have any text, do nothing.
2481 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2486 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2487 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2488 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2489 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2491 // Logic to determine whether this text control will lose focus or not.
2492 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2493 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2494 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2495 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2496 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2497 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2499 // Release the active highlight.
2500 if( mImpl->mEventData->mState == EventData::SELECTING )
2502 mImpl->ChangeState( EventData::EDITING );
2504 // Update selection position.
2505 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2506 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2507 mImpl->mEventData->mUpdateCursorPosition = true;
2508 mImpl->RequestRelayout();
2513 mImpl->mEventData->mCheckScrollAmount = true;
2514 Event event( Event::CURSOR_KEY_EVENT );
2515 event.p1.mInt = keyCode;
2516 event.p2.mBool = keyEvent.IsShiftModifier();
2517 mImpl->mEventData->mEventQueue.push_back( event );
2519 // Will request for relayout.
2520 relayoutNeeded = true;
2522 else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2524 // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2525 // If not handle it here, any selected text will be deleted
2530 else if ( keyEvent.IsCtrlModifier() )
2532 bool consumed = false;
2533 if (keyName == KEY_C_NAME)
2535 // Ctrl-C to copy the selected text
2536 TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2539 else if (keyName == KEY_V_NAME)
2541 // Ctrl-V to paste the copied text
2542 TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2545 else if (keyName == KEY_X_NAME)
2547 // Ctrl-X to cut the selected text
2548 TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2553 else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2554 ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2556 textChanged = DeleteEvent( keyCode );
2558 // Will request for relayout.
2559 relayoutNeeded = true;
2561 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2562 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2563 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2565 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2566 mImpl->ChangeState( EventData::INACTIVE );
2568 // Will request for relayout.
2569 relayoutNeeded = true;
2571 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2573 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2575 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the InputMethodContext?) when the predictive text is enabled
2576 // and a character is typed after the type of a upper case latin character.
2581 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2583 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2589 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2591 // InputMethodContext is no longer handling key-events
2592 mImpl->ClearPreEditFlag();
2594 InsertText( keyString, COMMIT );
2597 // Will request for relayout.
2598 relayoutNeeded = true;
2601 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2602 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2604 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2605 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2606 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2608 // Should not change the state if the key is the shift send by the InputMethodContext.
2609 // Otherwise, when the state is SELECTING the text controller can't send the right
2610 // surrounding info to the InputMethodContext.
2611 mImpl->ChangeState( EventData::EDITING );
2613 // Will request for relayout.
2614 relayoutNeeded = true;
2617 if( relayoutNeeded )
2619 mImpl->RequestRelayout();
2624 ( NULL != mImpl->mEditableControlInterface ) )
2626 // Do this last since it provides callbacks into application code
2627 mImpl->mEditableControlInterface->TextChanged();
2633 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2635 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2637 if( NULL != mImpl->mEventData )
2639 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2640 EventData::State state( mImpl->mEventData->mState );
2641 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2643 if( mImpl->IsClipboardVisible() )
2645 if( EventData::INACTIVE == state || EventData::EDITING == state)
2647 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2649 relayoutNeeded = true;
2651 else if( 1u == tapCount )
2653 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2655 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2658 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2660 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2661 relayoutNeeded = true;
2665 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2667 // Hide placeholder text
2671 if( EventData::INACTIVE == state )
2673 mImpl->ChangeState( EventData::EDITING );
2675 else if( !mImpl->IsClipboardEmpty() )
2677 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2679 relayoutNeeded = true;
2682 else if( 2u == tapCount )
2684 if( mImpl->mEventData->mSelectionEnabled &&
2685 mImpl->IsShowingRealText() )
2687 relayoutNeeded = true;
2688 mImpl->mEventData->mIsLeftHandleSelected = true;
2689 mImpl->mEventData->mIsRightHandleSelected = true;
2693 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2694 if( relayoutNeeded )
2696 Event event( Event::TAP_EVENT );
2697 event.p1.mUint = tapCount;
2698 event.p2.mFloat = x;
2699 event.p3.mFloat = y;
2700 mImpl->mEventData->mEventQueue.push_back( event );
2702 mImpl->RequestRelayout();
2706 // Reset keyboard as tap event has occurred.
2707 mImpl->ResetInputMethodContext();
2710 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2712 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2714 if( NULL != mImpl->mEventData )
2716 Event event( Event::PAN_EVENT );
2717 event.p1.mInt = state;
2718 event.p2.mFloat = displacement.x;
2719 event.p3.mFloat = displacement.y;
2720 mImpl->mEventData->mEventQueue.push_back( event );
2722 mImpl->RequestRelayout();
2726 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2728 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2730 if( ( state == Gesture::Started ) &&
2731 ( NULL != mImpl->mEventData ) )
2733 // The 1st long-press on inactive text-field is treated as tap
2734 if( EventData::INACTIVE == mImpl->mEventData->mState )
2736 mImpl->ChangeState( EventData::EDITING );
2738 Event event( Event::TAP_EVENT );
2740 event.p2.mFloat = x;
2741 event.p3.mFloat = y;
2742 mImpl->mEventData->mEventQueue.push_back( event );
2744 mImpl->RequestRelayout();
2746 else if( !mImpl->IsShowingRealText() )
2748 Event event( Event::LONG_PRESS_EVENT );
2749 event.p1.mInt = state;
2750 event.p2.mFloat = x;
2751 event.p3.mFloat = y;
2752 mImpl->mEventData->mEventQueue.push_back( event );
2753 mImpl->RequestRelayout();
2755 else if( !mImpl->IsClipboardVisible() )
2757 // Reset the InputMethodContext to commit the pre-edit before selecting the text.
2758 mImpl->ResetInputMethodContext();
2760 Event event( Event::LONG_PRESS_EVENT );
2761 event.p1.mInt = state;
2762 event.p2.mFloat = x;
2763 event.p3.mFloat = y;
2764 mImpl->mEventData->mEventQueue.push_back( event );
2765 mImpl->RequestRelayout();
2767 mImpl->mEventData->mIsLeftHandleSelected = true;
2768 mImpl->mEventData->mIsRightHandleSelected = true;
2773 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
2775 // Whether the text needs to be relaid-out.
2776 bool requestRelayout = false;
2778 // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
2779 bool retrieveText = false;
2780 bool retrieveCursor = false;
2782 switch( inputMethodContextEvent.eventName )
2784 case InputMethodContext::COMMIT:
2786 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
2787 requestRelayout = true;
2788 retrieveCursor = true;
2791 case InputMethodContext::PRE_EDIT:
2793 InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
2794 requestRelayout = true;
2795 retrieveCursor = true;
2798 case InputMethodContext::DELETE_SURROUNDING:
2800 const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
2801 inputMethodContextEvent.numberOfChars,
2802 DONT_UPDATE_INPUT_STYLE );
2806 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2807 !mImpl->IsPlaceholderAvailable() )
2809 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2813 ShowPlaceholderText();
2815 mImpl->mEventData->mUpdateCursorPosition = true;
2816 mImpl->mEventData->mScrollAfterDelete = true;
2818 requestRelayout = true;
2822 case InputMethodContext::GET_SURROUNDING:
2824 retrieveText = true;
2825 retrieveCursor = true;
2828 case InputMethodContext::PRIVATE_COMMAND:
2830 // PRIVATECOMMAND event is just for getting the private command message
2831 retrieveText = true;
2832 retrieveCursor = true;
2835 case InputMethodContext::VOID:
2842 if( requestRelayout )
2844 mImpl->mOperationsPending = ALL_OPERATIONS;
2845 mImpl->RequestRelayout();
2849 CharacterIndex cursorPosition = 0u;
2850 Length numberOfWhiteSpaces = 0u;
2852 if( retrieveCursor )
2854 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2856 cursorPosition = mImpl->GetLogicalCursorPosition();
2858 if( cursorPosition < numberOfWhiteSpaces )
2860 cursorPosition = 0u;
2864 cursorPosition -= numberOfWhiteSpaces;
2870 if( !mImpl->IsShowingPlaceholderText() )
2872 // Retrieves the normal text string.
2873 mImpl->GetText( numberOfWhiteSpaces, text );
2877 // When the current text is Placeholder Text, the surrounding text should be empty string.
2878 // It means DALi should send empty string ("") to IME.
2883 InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2885 if( requestRelayout &&
2886 ( NULL != mImpl->mEditableControlInterface ) )
2888 // Do this last since it provides callbacks into application code
2889 mImpl->mEditableControlInterface->TextChanged();
2892 return callbackData;
2895 void Controller::PasteClipboardItemEvent()
2897 // Retrieve the clipboard contents first
2898 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2899 std::string stringToPaste( notifier.GetContent() );
2901 // Commit the current pre-edit text; the contents of the clipboard should be appended
2902 mImpl->ResetInputMethodContext();
2904 // Temporary disable hiding clipboard
2905 mImpl->SetClipboardHideEnable( false );
2908 PasteText( stringToPaste );
2910 mImpl->SetClipboardHideEnable( true );
2913 // protected : Inherit from Text::Decorator::ControllerInterface.
2915 void Controller::GetTargetSize( Vector2& targetSize )
2917 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2920 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2922 if( NULL != mImpl->mEditableControlInterface )
2924 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2928 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2930 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2932 if( NULL != mImpl->mEventData )
2934 switch( handleType )
2938 Event event( Event::GRAB_HANDLE_EVENT );
2939 event.p1.mUint = state;
2940 event.p2.mFloat = x;
2941 event.p3.mFloat = y;
2943 mImpl->mEventData->mEventQueue.push_back( event );
2946 case LEFT_SELECTION_HANDLE:
2948 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2949 event.p1.mUint = state;
2950 event.p2.mFloat = x;
2951 event.p3.mFloat = y;
2953 mImpl->mEventData->mEventQueue.push_back( event );
2956 case RIGHT_SELECTION_HANDLE:
2958 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2959 event.p1.mUint = state;
2960 event.p2.mFloat = x;
2961 event.p3.mFloat = y;
2963 mImpl->mEventData->mEventQueue.push_back( event );
2966 case LEFT_SELECTION_HANDLE_MARKER:
2967 case RIGHT_SELECTION_HANDLE_MARKER:
2969 // Markers do not move the handles.
2972 case HANDLE_TYPE_COUNT:
2974 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2978 mImpl->RequestRelayout();
2982 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2984 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2986 if( NULL == mImpl->mEventData )
2993 case Toolkit::TextSelectionPopup::CUT:
2995 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2996 mImpl->mOperationsPending = ALL_OPERATIONS;
2998 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2999 !mImpl->IsPlaceholderAvailable() )
3001 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3005 ShowPlaceholderText();
3008 mImpl->mEventData->mUpdateCursorPosition = true;
3009 mImpl->mEventData->mScrollAfterDelete = true;
3011 mImpl->RequestRelayout();
3013 if( NULL != mImpl->mEditableControlInterface )
3015 mImpl->mEditableControlInterface->TextChanged();
3019 case Toolkit::TextSelectionPopup::COPY:
3021 mImpl->SendSelectionToClipboard( false ); // Text not modified
3023 mImpl->mEventData->mUpdateCursorPosition = true;
3025 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3028 case Toolkit::TextSelectionPopup::PASTE:
3030 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3033 case Toolkit::TextSelectionPopup::SELECT:
3035 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3037 if( mImpl->mEventData->mSelectionEnabled )
3039 // Creates a SELECT event.
3040 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3044 case Toolkit::TextSelectionPopup::SELECT_ALL:
3046 // Creates a SELECT_ALL event
3047 SelectEvent( 0.f, 0.f, true );
3050 case Toolkit::TextSelectionPopup::CLIPBOARD:
3052 mImpl->ShowClipboard();
3055 case Toolkit::TextSelectionPopup::NONE:
3063 void Controller::DisplayTimeExpired()
3065 mImpl->mEventData->mUpdateCursorPosition = true;
3066 // Apply modifications to the model
3067 mImpl->mOperationsPending = ALL_OPERATIONS;
3069 mImpl->RequestRelayout();
3072 // private : Update.
3074 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3076 bool removedPrevious = false;
3077 bool removedSelected = false;
3078 bool maxLengthReached = false;
3080 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3082 if( NULL == mImpl->mEventData )
3087 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3088 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3089 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3091 // TODO: At the moment the underline runs are only for pre-edit.
3092 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3094 // Remove the previous InputMethodContext pre-edit.
3095 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3097 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3098 mImpl->mEventData->mPreEditLength,
3099 DONT_UPDATE_INPUT_STYLE );
3101 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3102 mImpl->mEventData->mPreEditLength = 0u;
3106 // Remove the previous Selection.
3107 removedSelected = RemoveSelectedText();
3111 Vector<Character> utf32Characters;
3112 Length characterCount = 0u;
3116 // Convert text into UTF-32
3117 utf32Characters.Resize( text.size() );
3119 // This is a bit horrible but std::string returns a (signed) char*
3120 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3122 // Transform a text array encoded in utf8 into an array encoded in utf32.
3123 // It returns the actual number of characters.
3124 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3125 utf32Characters.Resize( characterCount );
3127 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3128 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3131 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3133 // The placeholder text is no longer needed
3134 if( mImpl->IsShowingPlaceholderText() )
3139 mImpl->ChangeState( EventData::EDITING );
3141 // Handle the InputMethodContext (predicitive text) state changes
3142 if( COMMIT == type )
3144 // InputMethodContext is no longer handling key-events
3145 mImpl->ClearPreEditFlag();
3149 if( !mImpl->mEventData->mPreEditFlag )
3151 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3153 // Record the start of the pre-edit text
3154 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3157 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3158 mImpl->mEventData->mPreEditFlag = true;
3160 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3163 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3165 // Restrict new text to fit within Maximum characters setting.
3166 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3167 maxLengthReached = ( characterCount > maxSizeOfNewText );
3169 // The cursor position.
3170 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3172 // Update the text's style.
3174 // Updates the text style runs by adding characters.
3175 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3177 // Get the character index from the cursor index.
3178 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3180 // Retrieve the text's style for the given index.
3182 mImpl->RetrieveDefaultInputStyle( style );
3183 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3185 // Whether to add a new text color run.
3186 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
3188 // Whether to add a new font run.
3189 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
3190 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
3191 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
3192 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
3193 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
3198 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3199 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3201 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3202 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3203 colorRun.characterRun.characterIndex = cursorIndex;
3204 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3207 if( addFontNameRun ||
3213 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3214 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3216 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3218 if( addFontNameRun )
3220 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3221 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3222 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3223 fontDescriptionRun.familyDefined = true;
3225 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3228 if( addFontWeightRun )
3230 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3231 fontDescriptionRun.weightDefined = true;
3234 if( addFontWidthRun )
3236 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3237 fontDescriptionRun.widthDefined = true;
3240 if( addFontSlantRun )
3242 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3243 fontDescriptionRun.slantDefined = true;
3246 if( addFontSizeRun )
3248 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3249 fontDescriptionRun.sizeDefined = true;
3252 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3253 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3256 // Insert at current cursor position.
3257 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3259 if( cursorIndex < numberOfCharactersInModel )
3261 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3265 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3268 // Mark the first paragraph to be updated.
3269 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3271 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3272 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3273 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3274 mImpl->mTextUpdateInfo.mClearAll = true;
3278 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3279 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3282 // Update the cursor index.
3283 cursorIndex += maxSizeOfNewText;
3285 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 );
3288 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3289 mImpl->IsPlaceholderAvailable() )
3291 // Show place-holder if empty after removing the pre-edit text
3292 ShowPlaceholderText();
3293 mImpl->mEventData->mUpdateCursorPosition = true;
3294 mImpl->ClearPreEditFlag();
3296 else if( removedPrevious ||
3298 ( 0 != utf32Characters.Count() ) )
3300 // Queue an inserted event
3301 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3303 mImpl->mEventData->mUpdateCursorPosition = true;
3304 if( removedSelected )
3306 mImpl->mEventData->mScrollAfterDelete = true;
3310 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3314 if( maxLengthReached )
3316 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3318 mImpl->ResetInputMethodContext();
3320 if( NULL != mImpl->mEditableControlInterface )
3322 // Do this last since it provides callbacks into application code
3323 mImpl->mEditableControlInterface->MaxLengthReached();
3328 void Controller::PasteText( const std::string& stringToPaste )
3330 InsertText( stringToPaste, Text::Controller::COMMIT );
3331 mImpl->ChangeState( EventData::EDITING );
3332 mImpl->RequestRelayout();
3334 if( NULL != mImpl->mEditableControlInterface )
3336 // Do this last since it provides callbacks into application code
3337 mImpl->mEditableControlInterface->TextChanged();
3341 bool Controller::RemoveText( int cursorOffset,
3342 int numberOfCharacters,
3343 UpdateInputStyleType type )
3345 bool removed = false;
3347 if( NULL == mImpl->mEventData )
3352 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3353 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3355 if( !mImpl->IsShowingPlaceholderText() )
3357 // Delete at current cursor position
3358 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3359 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3361 CharacterIndex cursorIndex = 0;
3363 // Validate the cursor position & number of characters
3364 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3366 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3369 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3371 numberOfCharacters = currentText.Count() - cursorIndex;
3374 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.
3375 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3377 // Mark the paragraphs to be updated.
3378 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3380 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3381 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3382 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3383 mImpl->mTextUpdateInfo.mClearAll = true;
3387 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3388 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3391 // Update the input style and remove the text's style before removing the text.
3393 if( UPDATE_INPUT_STYLE == type )
3395 // Keep a copy of the current input style.
3396 InputStyle currentInputStyle;
3397 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3399 // Set first the default input style.
3400 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3402 // Update the input style.
3403 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3405 // Compare if the input style has changed.
3406 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3408 if( hasInputStyleChanged )
3410 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3411 // Queue the input style changed signal.
3412 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3416 // Updates the text style runs by removing characters. Runs with no characters are removed.
3417 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3419 // Remove the characters.
3420 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3421 Vector<Character>::Iterator last = first + numberOfCharacters;
3423 currentText.Erase( first, last );
3425 // Cursor position retreat
3426 oldCursorIndex = cursorIndex;
3428 mImpl->mEventData->mScrollAfterDelete = true;
3430 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3438 bool Controller::RemoveSelectedText()
3440 bool textRemoved( false );
3442 if( EventData::SELECTING == mImpl->mEventData->mState )
3444 std::string removedString;
3445 mImpl->RetrieveSelection( removedString, true );
3447 if( !removedString.empty() )
3450 mImpl->ChangeState( EventData::EDITING );
3457 // private : Relayout.
3459 bool Controller::DoRelayout( const Size& size,
3460 OperationsMask operationsRequired,
3463 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3464 bool viewUpdated( false );
3466 // Calculate the operations to be done.
3467 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3469 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3470 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3472 // Get the current layout size.
3473 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3475 if( NO_OPERATION != ( LAYOUT & operations ) )
3477 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3479 // Some vectors with data needed to layout and reorder may be void
3480 // after the first time the text has been laid out.
3481 // Fill the vectors again.
3483 // Calculate the number of glyphs to layout.
3484 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3485 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3486 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3487 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3489 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3490 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3492 // Make sure the index is not out of bound
3493 if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3494 requestedNumberOfCharacters > charactersToGlyph.Count() ||
3495 ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3497 std::string currentText;
3498 GetText( currentText );
3500 DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3501 DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3502 DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3507 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3508 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3510 if( 0u == totalNumberOfGlyphs )
3512 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3514 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3517 // Nothing else to do if there is no glyphs.
3518 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3522 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3523 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3524 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3525 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3526 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3527 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3528 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3529 const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3531 // Set the layout parameters.
3532 Layout::Parameters layoutParameters( size,
3534 lineBreakInfo.Begin(),
3535 wordBreakInfo.Begin(),
3536 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3538 glyphsToCharactersMap.Begin(),
3539 charactersPerGlyph.Begin(),
3540 charactersToGlyphBuffer,
3541 glyphsPerCharacterBuffer,
3542 totalNumberOfGlyphs,
3543 mImpl->mModel->mHorizontalAlignment,
3544 mImpl->mModel->mLineWrapMode,
3546 mImpl->mModel->mIgnoreSpacesAfterText );
3548 // Resize the vector of positions to have the same size than the vector of glyphs.
3549 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3550 glyphPositions.Resize( totalNumberOfGlyphs );
3552 // Whether the last character is a new paragraph character.
3553 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3554 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3556 // The initial glyph and the number of glyphs to layout.
3557 layoutParameters.startGlyphIndex = startGlyphIndex;
3558 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3559 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3560 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3562 // Update the ellipsis
3563 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3565 if( NULL != mImpl->mEventData )
3567 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3569 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3571 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3573 // Disable ellipsis when editing
3574 elideTextEnabled = false;
3577 // Reset the scroll position in inactive state
3578 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3580 ResetScrollPosition();
3584 // Update the visual model.
3586 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3588 mImpl->mModel->mVisualModel->mLines,
3592 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3596 layoutSize = newLayoutSize;
3598 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3600 mImpl->mIsTextDirectionRTL = false;
3603 // Reorder the lines
3604 if( NO_OPERATION != ( REORDER & operations ) )
3606 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3607 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3609 // Check first if there are paragraphs with bidirectional info.
3610 if( 0u != bidirectionalInfo.Count() )
3613 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3615 // Reorder the lines.
3616 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3617 ReorderLines( bidirectionalInfo,
3619 requestedNumberOfCharacters,
3620 mImpl->mModel->mVisualModel->mLines,
3621 bidirectionalLineInfo );
3623 // Set the bidirectional info per line into the layout parameters.
3624 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3625 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3627 // Re-layout the text. Reorder those lines with right to left characters.
3628 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3630 requestedNumberOfCharacters,
3633 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3635 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3638 mImpl->mIsTextDirectionRTL = firstline->direction;
3644 // Sets the layout size.
3645 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3647 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3652 if( NO_OPERATION != ( ALIGN & operations ) )
3654 // The laid-out lines.
3655 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3657 // Need to align with the control's size as the text may contain lines
3658 // starting either with left to right text or right to left.
3659 mImpl->mLayoutEngine.Align( size,
3661 requestedNumberOfCharacters,
3662 mImpl->mModel->mHorizontalAlignment,
3664 mImpl->mModel->mAlignmentOffset );
3668 #if defined(DEBUG_ENABLED)
3669 std::string currentText;
3670 GetText( currentText );
3671 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
3673 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3677 void Controller::CalculateVerticalOffset( const Size& controlSize )
3679 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3681 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3683 // Get the line height of the default font.
3684 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3687 switch( mImpl->mModel->mVerticalAlignment )
3689 case VerticalAlignment::TOP:
3691 mImpl->mModel->mScrollPosition.y = 0.f;
3694 case VerticalAlignment::CENTER:
3696 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3699 case VerticalAlignment::BOTTOM:
3701 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3707 // private : Events.
3709 void Controller::ProcessModifyEvents()
3711 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3713 if( 0u == events.Count() )
3719 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3720 endIt = events.End();
3724 const ModifyEvent& event = *it;
3726 if( ModifyEvent::TEXT_REPLACED == event.type )
3728 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3729 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3731 TextReplacedEvent();
3733 else if( ModifyEvent::TEXT_INSERTED == event.type )
3735 TextInsertedEvent();
3737 else if( ModifyEvent::TEXT_DELETED == event.type )
3739 // Placeholder-text cannot be deleted
3740 if( !mImpl->IsShowingPlaceholderText() )
3747 if( NULL != mImpl->mEventData )
3749 // When the text is being modified, delay cursor blinking
3750 mImpl->mEventData->mDecorator->DelayCursorBlink();
3752 // Update selection position after modifying the text
3753 mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3754 mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
3757 // Discard temporary text
3761 void Controller::TextReplacedEvent()
3763 // The natural size needs to be re-calculated.
3764 mImpl->mRecalculateNaturalSize = true;
3766 // The text direction needs to be updated.
3767 mImpl->mUpdateTextDirection = true;
3769 // Apply modifications to the model
3770 mImpl->mOperationsPending = ALL_OPERATIONS;
3773 void Controller::TextInsertedEvent()
3775 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3777 if( NULL == mImpl->mEventData )
3782 mImpl->mEventData->mCheckScrollAmount = true;
3784 // The natural size needs to be re-calculated.
3785 mImpl->mRecalculateNaturalSize = true;
3787 // The text direction needs to be updated.
3788 mImpl->mUpdateTextDirection = true;
3790 // Apply modifications to the model; TODO - Optimize this
3791 mImpl->mOperationsPending = ALL_OPERATIONS;
3794 void Controller::TextDeletedEvent()
3796 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3798 if( NULL == mImpl->mEventData )
3803 mImpl->mEventData->mCheckScrollAmount = true;
3805 // The natural size needs to be re-calculated.
3806 mImpl->mRecalculateNaturalSize = true;
3808 // The text direction needs to be updated.
3809 mImpl->mUpdateTextDirection = true;
3811 // Apply modifications to the model; TODO - Optimize this
3812 mImpl->mOperationsPending = ALL_OPERATIONS;
3815 void Controller::SelectEvent( float x, float y, bool selectAll )
3817 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3819 if( NULL != mImpl->mEventData )
3823 Event event( Event::SELECT_ALL );
3824 mImpl->mEventData->mEventQueue.push_back( event );
3828 Event event( Event::SELECT );
3829 event.p2.mFloat = x;
3830 event.p3.mFloat = y;
3831 mImpl->mEventData->mEventQueue.push_back( event );
3834 mImpl->mEventData->mCheckScrollAmount = true;
3835 mImpl->mEventData->mIsLeftHandleSelected = true;
3836 mImpl->mEventData->mIsRightHandleSelected = true;
3837 mImpl->RequestRelayout();
3841 bool Controller::DeleteEvent( int keyCode )
3843 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
3845 bool removed = false;
3847 if( NULL == mImpl->mEventData )
3852 // InputMethodContext is no longer handling key-events
3853 mImpl->ClearPreEditFlag();
3855 if( EventData::SELECTING == mImpl->mEventData->mState )
3857 removed = RemoveSelectedText();
3859 else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
3861 // Remove the character before the current cursor position
3862 removed = RemoveText( -1,
3864 UPDATE_INPUT_STYLE );
3866 else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
3868 // Remove the character after the current cursor position
3869 removed = RemoveText( 0,
3871 UPDATE_INPUT_STYLE );
3876 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3877 !mImpl->IsPlaceholderAvailable() )
3879 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3883 ShowPlaceholderText();
3885 mImpl->mEventData->mUpdateCursorPosition = true;
3886 mImpl->mEventData->mScrollAfterDelete = true;
3892 // private : Helpers.
3894 void Controller::ResetText()
3897 mImpl->mModel->mLogicalModel->mText.Clear();
3899 // We have cleared everything including the placeholder-text
3900 mImpl->PlaceholderCleared();
3902 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3903 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3904 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3906 // Clear any previous text.
3907 mImpl->mTextUpdateInfo.mClearAll = true;
3909 // The natural size needs to be re-calculated.
3910 mImpl->mRecalculateNaturalSize = true;
3912 // The text direction needs to be updated.
3913 mImpl->mUpdateTextDirection = true;
3915 // Apply modifications to the model
3916 mImpl->mOperationsPending = ALL_OPERATIONS;
3919 void Controller::ShowPlaceholderText()
3921 if( mImpl->IsPlaceholderAvailable() )
3923 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3925 if( NULL == mImpl->mEventData )
3930 mImpl->mEventData->mIsShowingPlaceholderText = true;
3932 // Disable handles when showing place-holder text
3933 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3934 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3935 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3937 const char* text( NULL );
3940 // TODO - Switch Placeholder text when changing state
3941 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3942 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3944 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3945 size = mImpl->mEventData->mPlaceholderTextActive.size();
3949 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3950 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3953 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3954 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3956 // Reset model for showing placeholder.
3957 mImpl->mModel->mLogicalModel->mText.Clear();
3958 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3960 // Convert text into UTF-32
3961 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3962 utf32Characters.Resize( size );
3964 // This is a bit horrible but std::string returns a (signed) char*
3965 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3967 // Transform a text array encoded in utf8 into an array encoded in utf32.
3968 // It returns the actual number of characters.
3969 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3970 utf32Characters.Resize( characterCount );
3972 // The characters to be added.
3973 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3975 // Reset the cursor position
3976 mImpl->mEventData->mPrimaryCursorPosition = 0;
3978 // The natural size needs to be re-calculated.
3979 mImpl->mRecalculateNaturalSize = true;
3981 // The text direction needs to be updated.
3982 mImpl->mUpdateTextDirection = true;
3984 // Apply modifications to the model
3985 mImpl->mOperationsPending = ALL_OPERATIONS;
3987 // Update the rest of the model during size negotiation
3988 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3992 void Controller::ClearFontData()
3994 if( mImpl->mFontDefaults )
3996 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3999 // Set flags to update the model.
4000 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4001 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4002 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4004 mImpl->mTextUpdateInfo.mClearAll = true;
4005 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4006 mImpl->mRecalculateNaturalSize = true;
4008 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4014 UPDATE_LAYOUT_SIZE |
4019 void Controller::ClearStyleData()
4021 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4022 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4025 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4027 // Reset the cursor position
4028 if( NULL != mImpl->mEventData )
4030 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4032 // Update the cursor if it's in editing mode.
4033 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
4035 mImpl->mEventData->mUpdateCursorPosition = true;
4040 void Controller::ResetScrollPosition()
4042 if( NULL != mImpl->mEventData )
4044 // Reset the scroll position.
4045 mImpl->mModel->mScrollPosition = Vector2::ZERO;
4046 mImpl->mEventData->mScrollAfterUpdatePosition = true;
4050 void Controller::SetControlInterface( ControlInterface* controlInterface )
4052 mImpl->mControlInterface = controlInterface;
4055 bool Controller::ShouldClearFocusOnEscape() const
4057 return mImpl->mShouldClearFocusOnEscape;
4060 // private : Private contructors & copy operator.
4062 Controller::Controller()
4065 mImpl = new Controller::Impl( NULL, NULL );
4068 Controller::Controller( ControlInterface* controlInterface )
4070 mImpl = new Controller::Impl( controlInterface, NULL );
4073 Controller::Controller( ControlInterface* controlInterface,
4074 EditableControlInterface* editableControlInterface )
4076 mImpl = new Controller::Impl( controlInterface,
4077 editableControlInterface );
4080 // The copy constructor and operator are left unimplemented.
4082 // protected : Destructor.
4084 Controller::~Controller()
4091 } // namespace Toolkit