2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
30 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
31 #include <dali-toolkit/internal/text/bidirectional-support.h>
32 #include <dali-toolkit/internal/text/character-set-conversion.h>
33 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
34 #include <dali-toolkit/internal/text/markup-processor.h>
35 #include <dali-toolkit/internal/text/multi-language-support.h>
36 #include <dali-toolkit/internal/text/text-controller-impl.h>
37 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
38 #include <dali-toolkit/internal/text/text-font-style.h>
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
47 const float MAX_FLOAT = std::numeric_limits<float>::max();
49 const std::string EMPTY_STRING("");
51 const char * const PLACEHOLDER_TEXT = "text";
52 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
53 const char * const PLACEHOLDER_COLOR = "color";
54 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
55 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
56 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
57 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
58 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
60 float ConvertToEven( float value )
62 int intValue(static_cast<int>( value ));
63 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
78 * @brief Adds a new font description run for the selected text.
80 * The new font parameters are added after the call to this method.
82 * @param[in] eventData The event data pointer.
83 * @param[in] logicalModel The logical model where to add the new font description run.
84 * @param[out] startOfSelectedText Index to the first selected character.
85 * @param[out] lengthOfSelectedText Number of selected characters.
87 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
88 LogicalModelPtr logicalModel,
89 CharacterIndex& startOfSelectedText,
90 Length& lengthOfSelectedText )
92 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
94 // Get start and end position of selection
95 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
96 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
99 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
100 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
102 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
104 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
105 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
107 // Recalculate the selection highlight as the metrics may have changed.
108 eventData->mUpdateLeftSelectionPosition = true;
109 eventData->mUpdateRightSelectionPosition = true;
110 eventData->mUpdateHighlightBox = true;
112 return fontDescriptionRun;
115 // public : Constructor.
117 ControllerPtr Controller::New()
119 return ControllerPtr( new Controller() );
122 ControllerPtr Controller::New( ControlInterface* controlInterface )
124 return ControllerPtr( new Controller( controlInterface ) );
127 ControllerPtr Controller::New( ControlInterface* controlInterface,
128 EditableControlInterface* editableControlInterface )
130 return ControllerPtr( new Controller( controlInterface,
131 editableControlInterface ) );
134 // public : Configure the text controller.
136 void Controller::EnableTextInput( DecoratorPtr decorator )
140 delete mImpl->mEventData;
141 mImpl->mEventData = NULL;
143 // Nothing else to do.
147 if( NULL == mImpl->mEventData )
149 mImpl->mEventData = new EventData( decorator );
153 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
155 // Metrics for bitmap & vector based glyphs are different
156 mImpl->mMetrics->SetGlyphType( glyphType );
158 // Clear the font-specific data
161 mImpl->RequestRelayout();
164 void Controller::SetMarkupProcessorEnabled( bool enable )
166 mImpl->mMarkupProcessorEnabled = enable;
169 bool Controller::IsMarkupProcessorEnabled() const
171 return mImpl->mMarkupProcessorEnabled;
174 void Controller::SetAutoScrollEnabled( bool enable )
176 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 );
178 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
182 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
183 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
193 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
194 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
201 mImpl->mIsAutoScrollEnabled = enable;
202 mImpl->RequestRelayout();
206 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
207 mImpl->mIsAutoScrollEnabled = false;
211 bool Controller::IsAutoScrollEnabled() const
213 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
215 return mImpl->mIsAutoScrollEnabled;
218 CharacterDirection Controller::GetAutoScrollDirection() const
220 return mImpl->mAutoScrollDirectionRTL;
223 float Controller::GetAutoScrollLineAlignment() const
227 if( mImpl->mModel->mVisualModel &&
228 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
230 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
236 void Controller::SetHorizontalScrollEnabled( bool enable )
238 if( ( NULL != mImpl->mEventData ) &&
239 mImpl->mEventData->mDecorator )
241 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
244 bool Controller::IsHorizontalScrollEnabled() const
246 if( ( NULL != mImpl->mEventData ) &&
247 mImpl->mEventData->mDecorator )
249 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
255 void Controller::SetVerticalScrollEnabled( bool enable )
257 if( ( NULL != mImpl->mEventData ) &&
258 mImpl->mEventData->mDecorator )
260 if( mImpl->mEventData->mDecorator )
262 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
267 bool Controller::IsVerticalScrollEnabled() const
269 if( ( NULL != mImpl->mEventData ) &&
270 mImpl->mEventData->mDecorator )
272 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
278 void Controller::SetSmoothHandlePanEnabled( bool enable )
280 if( ( NULL != mImpl->mEventData ) &&
281 mImpl->mEventData->mDecorator )
283 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
287 bool Controller::IsSmoothHandlePanEnabled() const
289 if( ( NULL != mImpl->mEventData ) &&
290 mImpl->mEventData->mDecorator )
292 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
298 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
300 mImpl->mMaximumNumberOfCharacters = maxCharacters;
303 int Controller::GetMaximumNumberOfCharacters()
305 return mImpl->mMaximumNumberOfCharacters;
308 void Controller::SetEnableCursorBlink( bool enable )
310 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
312 if( NULL != mImpl->mEventData )
314 mImpl->mEventData->mCursorBlinkEnabled = enable;
317 mImpl->mEventData->mDecorator )
319 mImpl->mEventData->mDecorator->StopCursorBlink();
324 bool Controller::GetEnableCursorBlink() const
326 if( NULL != mImpl->mEventData )
328 return mImpl->mEventData->mCursorBlinkEnabled;
334 void Controller::SetMultiLineEnabled( bool enable )
336 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
338 if( layout != mImpl->mLayoutEngine.GetLayout() )
340 // Set the layout type.
341 mImpl->mLayoutEngine.SetLayout( layout );
343 // Set the flags to redo the layout operations
344 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
349 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
351 mImpl->RequestRelayout();
355 bool Controller::IsMultiLineEnabled() const
357 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
360 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
362 if( alignment != mImpl->mModel->mHorizontalAlignment )
364 // Set the alignment.
365 mImpl->mModel->mHorizontalAlignment = alignment;
367 // Set the flag to redo the alignment operation.
368 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
370 mImpl->RequestRelayout();
374 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
376 return mImpl->mModel->mHorizontalAlignment;
379 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
381 if( alignment != mImpl->mModel->mVerticalAlignment )
383 // Set the alignment.
384 mImpl->mModel->mVerticalAlignment = alignment;
386 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
388 mImpl->RequestRelayout();
392 VerticalAlignment::Type Controller::GetVerticalAlignment() const
394 return mImpl->mModel->mVerticalAlignment;
397 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
399 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
401 // Set the text wrap mode.
402 mImpl->mModel->mLineWrapMode = lineWrapMode;
405 // Update Text layout for applying wrap mode
406 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
411 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
412 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
413 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
416 mImpl->RequestRelayout();
420 Text::LineWrap::Mode Controller::GetLineWrapMode() const
422 return mImpl->mModel->mLineWrapMode;
425 void Controller::SetTextElideEnabled( bool enabled )
427 mImpl->mModel->mElideEnabled = enabled;
430 bool Controller::IsTextElideEnabled() const
432 return mImpl->mModel->mElideEnabled;
435 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
437 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
438 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
440 // Update placeholder if there is no text
441 if( mImpl->IsShowingPlaceholderText() ||
442 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
444 ShowPlaceholderText();
448 bool Controller::IsPlaceholderTextElideEnabled() const
450 return mImpl->mEventData->mIsPlaceholderElideEnabled;
453 void Controller::SetSelectionEnabled( bool enabled )
455 mImpl->mEventData->mSelectionEnabled = enabled;
458 bool Controller::IsSelectionEnabled() const
460 return mImpl->mEventData->mSelectionEnabled;
465 void Controller::SetText( const std::string& text )
467 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
469 // Reset keyboard as text changed
470 mImpl->ResetImfManager();
472 // Remove the previously set text and style.
478 CharacterIndex lastCursorIndex = 0u;
480 if( NULL != mImpl->mEventData )
482 // If popup shown then hide it by switching to Editing state
483 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
484 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
485 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
486 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
488 mImpl->ChangeState( EventData::EDITING );
494 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
496 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
497 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
499 Length textSize = 0u;
500 const uint8_t* utf8 = NULL;
501 if( mImpl->mMarkupProcessorEnabled )
503 ProcessMarkupString( text, markupProcessData );
504 textSize = markupProcessData.markupProcessedText.size();
506 // This is a bit horrible but std::string returns a (signed) char*
507 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
511 textSize = text.size();
513 // This is a bit horrible but std::string returns a (signed) char*
514 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
517 // Convert text into UTF-32
518 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
519 utf32Characters.Resize( textSize );
521 // Transform a text array encoded in utf8 into an array encoded in utf32.
522 // It returns the actual number of characters.
523 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
524 utf32Characters.Resize( characterCount );
526 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
527 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
529 // The characters to be added.
530 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
532 // To reset the cursor position
533 lastCursorIndex = characterCount;
535 // Update the rest of the model during size negotiation
536 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
538 // The natural size needs to be re-calculated.
539 mImpl->mRecalculateNaturalSize = true;
541 // Apply modifications to the model
542 mImpl->mOperationsPending = ALL_OPERATIONS;
546 ShowPlaceholderText();
549 // Resets the cursor position.
550 ResetCursorPosition( lastCursorIndex );
552 // Scrolls the text to make the cursor visible.
553 ResetScrollPosition();
555 mImpl->RequestRelayout();
557 if( NULL != mImpl->mEventData )
559 // Cancel previously queued events
560 mImpl->mEventData->mEventQueue.clear();
563 // Do this last since it provides callbacks into application code.
564 if( NULL != mImpl->mEditableControlInterface )
566 mImpl->mEditableControlInterface->TextChanged();
570 void Controller::GetText( std::string& text ) const
572 if( !mImpl->IsShowingPlaceholderText() )
574 // Retrieves the text string.
575 mImpl->GetText( 0u, text );
579 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
583 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
585 if( NULL != mImpl->mEventData )
587 if( PLACEHOLDER_TYPE_INACTIVE == type )
589 mImpl->mEventData->mPlaceholderTextInactive = text;
593 mImpl->mEventData->mPlaceholderTextActive = text;
596 // Update placeholder if there is no text
597 if( mImpl->IsShowingPlaceholderText() ||
598 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
600 ShowPlaceholderText();
605 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
607 if( NULL != mImpl->mEventData )
609 if( PLACEHOLDER_TYPE_INACTIVE == type )
611 text = mImpl->mEventData->mPlaceholderTextInactive;
615 text = mImpl->mEventData->mPlaceholderTextActive;
620 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
622 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
624 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
626 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
627 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
631 mImpl->RequestRelayout();
635 // public : Default style & Input style
637 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
639 if( NULL == mImpl->mFontDefaults )
641 mImpl->mFontDefaults = new FontDefaults();
644 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
645 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
646 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
648 // Clear the font-specific data
651 mImpl->RequestRelayout();
654 const std::string& Controller::GetDefaultFontFamily() const
656 if( NULL != mImpl->mFontDefaults )
658 return mImpl->mFontDefaults->mFontDescription.family;
664 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
666 if( NULL != mImpl->mEventData )
668 if( NULL == mImpl->mEventData->mPlaceholderFont )
670 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
673 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
674 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
675 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
677 mImpl->RequestRelayout();
681 const std::string& Controller::GetPlaceholderFontFamily() const
683 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
685 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
691 void Controller::SetDefaultFontWeight( FontWeight weight )
693 if( NULL == mImpl->mFontDefaults )
695 mImpl->mFontDefaults = new FontDefaults();
698 mImpl->mFontDefaults->mFontDescription.weight = weight;
699 mImpl->mFontDefaults->weightDefined = true;
701 // Clear the font-specific data
704 mImpl->RequestRelayout();
707 bool Controller::IsDefaultFontWeightDefined() const
709 if( NULL != mImpl->mFontDefaults )
711 return mImpl->mFontDefaults->weightDefined;
717 FontWeight Controller::GetDefaultFontWeight() const
719 if( NULL != mImpl->mFontDefaults )
721 return mImpl->mFontDefaults->mFontDescription.weight;
724 return TextAbstraction::FontWeight::NORMAL;
727 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
729 if( NULL != mImpl->mEventData )
731 if( NULL == mImpl->mEventData->mPlaceholderFont )
733 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
736 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
737 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
739 mImpl->RequestRelayout();
743 bool Controller::IsPlaceholderTextFontWeightDefined() const
745 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
747 return mImpl->mEventData->mPlaceholderFont->weightDefined;
752 FontWeight Controller::GetPlaceholderTextFontWeight() const
754 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
756 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
759 return TextAbstraction::FontWeight::NORMAL;
762 void Controller::SetDefaultFontWidth( FontWidth width )
764 if( NULL == mImpl->mFontDefaults )
766 mImpl->mFontDefaults = new FontDefaults();
769 mImpl->mFontDefaults->mFontDescription.width = width;
770 mImpl->mFontDefaults->widthDefined = true;
772 // Clear the font-specific data
775 mImpl->RequestRelayout();
778 bool Controller::IsDefaultFontWidthDefined() const
780 if( NULL != mImpl->mFontDefaults )
782 return mImpl->mFontDefaults->widthDefined;
788 FontWidth Controller::GetDefaultFontWidth() const
790 if( NULL != mImpl->mFontDefaults )
792 return mImpl->mFontDefaults->mFontDescription.width;
795 return TextAbstraction::FontWidth::NORMAL;
798 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
800 if( NULL != mImpl->mEventData )
802 if( NULL == mImpl->mEventData->mPlaceholderFont )
804 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
807 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
808 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
810 mImpl->RequestRelayout();
814 bool Controller::IsPlaceholderTextFontWidthDefined() const
816 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
818 return mImpl->mEventData->mPlaceholderFont->widthDefined;
823 FontWidth Controller::GetPlaceholderTextFontWidth() const
825 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
827 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
830 return TextAbstraction::FontWidth::NORMAL;
833 void Controller::SetDefaultFontSlant( FontSlant slant )
835 if( NULL == mImpl->mFontDefaults )
837 mImpl->mFontDefaults = new FontDefaults();
840 mImpl->mFontDefaults->mFontDescription.slant = slant;
841 mImpl->mFontDefaults->slantDefined = true;
843 // Clear the font-specific data
846 mImpl->RequestRelayout();
849 bool Controller::IsDefaultFontSlantDefined() const
851 if( NULL != mImpl->mFontDefaults )
853 return mImpl->mFontDefaults->slantDefined;
858 FontSlant Controller::GetDefaultFontSlant() const
860 if( NULL != mImpl->mFontDefaults )
862 return mImpl->mFontDefaults->mFontDescription.slant;
865 return TextAbstraction::FontSlant::NORMAL;
868 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
870 if( NULL != mImpl->mEventData )
872 if( NULL == mImpl->mEventData->mPlaceholderFont )
874 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
877 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
878 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
880 mImpl->RequestRelayout();
884 bool Controller::IsPlaceholderTextFontSlantDefined() const
886 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
888 return mImpl->mEventData->mPlaceholderFont->slantDefined;
893 FontSlant Controller::GetPlaceholderTextFontSlant() const
895 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
897 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
900 return TextAbstraction::FontSlant::NORMAL;
903 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
905 if( NULL == mImpl->mFontDefaults )
907 mImpl->mFontDefaults = new FontDefaults();
914 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
915 mImpl->mFontDefaults->sizeDefined = true;
920 // Point size = Pixel size * 72.f / DPI
921 unsigned int horizontalDpi = 0u;
922 unsigned int verticalDpi = 0u;
923 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
924 fontClient.GetDpi( horizontalDpi, verticalDpi );
926 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
927 mImpl->mFontDefaults->sizeDefined = true;
932 // Clear the font-specific data
935 mImpl->RequestRelayout();
938 float Controller::GetDefaultFontSize( FontSizeType type ) const
941 if( NULL != mImpl->mFontDefaults )
947 value = mImpl->mFontDefaults->mDefaultPointSize;
952 // Pixel size = Point size * DPI / 72.f
953 unsigned int horizontalDpi = 0u;
954 unsigned int verticalDpi = 0u;
955 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
956 fontClient.GetDpi( horizontalDpi, verticalDpi );
958 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
968 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
970 if( NULL != mImpl->mEventData )
972 if( NULL == mImpl->mEventData->mPlaceholderFont )
974 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
981 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
982 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
983 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
988 // Point size = Pixel size * 72.f / DPI
989 unsigned int horizontalDpi = 0u;
990 unsigned int verticalDpi = 0u;
991 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
992 fontClient.GetDpi( horizontalDpi, verticalDpi );
994 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
995 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
996 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1001 mImpl->RequestRelayout();
1005 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1008 if( NULL != mImpl->mEventData )
1014 if( NULL != mImpl->mEventData->mPlaceholderFont )
1016 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1020 // If the placeholder text font size is not set, then return the default font size.
1021 value = GetDefaultFontSize( POINT_SIZE );
1027 if( NULL != mImpl->mEventData->mPlaceholderFont )
1029 // Pixel size = Point size * DPI / 72.f
1030 unsigned int horizontalDpi = 0u;
1031 unsigned int verticalDpi = 0u;
1032 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1033 fontClient.GetDpi( horizontalDpi, verticalDpi );
1035 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1039 // If the placeholder text font size is not set, then return the default font size.
1040 value = GetDefaultFontSize( PIXEL_SIZE );
1051 void Controller::SetDefaultColor( const Vector4& color )
1053 mImpl->mTextColor = color;
1055 if( !mImpl->IsShowingPlaceholderText() )
1057 mImpl->mModel->mVisualModel->SetTextColor( color );
1059 mImpl->RequestRelayout();
1063 const Vector4& Controller::GetDefaultColor() const
1065 return mImpl->mTextColor;
1068 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1070 if( NULL != mImpl->mEventData )
1072 mImpl->mEventData->mPlaceholderTextColor = textColor;
1075 if( mImpl->IsShowingPlaceholderText() )
1077 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1078 mImpl->RequestRelayout();
1082 const Vector4& Controller::GetPlaceholderTextColor() const
1084 if( NULL != mImpl->mEventData )
1086 return mImpl->mEventData->mPlaceholderTextColor;
1089 return Color::BLACK;
1092 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1094 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1096 mImpl->RequestRelayout();
1099 const Vector2& Controller::GetShadowOffset() const
1101 return mImpl->mModel->mVisualModel->GetShadowOffset();
1104 void Controller::SetShadowColor( const Vector4& shadowColor )
1106 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1108 mImpl->RequestRelayout();
1111 const Vector4& Controller::GetShadowColor() const
1113 return mImpl->mModel->mVisualModel->GetShadowColor();
1116 void Controller::SetUnderlineColor( const Vector4& color )
1118 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1120 mImpl->RequestRelayout();
1123 const Vector4& Controller::GetUnderlineColor() const
1125 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1128 void Controller::SetUnderlineEnabled( bool enabled )
1130 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1132 mImpl->RequestRelayout();
1135 bool Controller::IsUnderlineEnabled() const
1137 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1140 void Controller::SetUnderlineHeight( float height )
1142 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1144 mImpl->RequestRelayout();
1147 float Controller::GetUnderlineHeight() const
1149 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1152 void Controller::SetOutlineColor( const Vector4& color )
1154 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1156 mImpl->RequestRelayout();
1159 const Vector4& Controller::GetOutlineColor() const
1161 return mImpl->mModel->mVisualModel->GetOutlineColor();
1164 void Controller::SetOutlineWidth( float width )
1166 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1168 mImpl->RequestRelayout();
1171 float Controller::GetOutlineWidth() const
1173 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1176 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1178 if( NULL == mImpl->mEmbossDefaults )
1180 mImpl->mEmbossDefaults = new EmbossDefaults();
1183 mImpl->mEmbossDefaults->properties = embossProperties;
1186 const std::string& Controller::GetDefaultEmbossProperties() const
1188 if( NULL != mImpl->mEmbossDefaults )
1190 return mImpl->mEmbossDefaults->properties;
1193 return EMPTY_STRING;
1196 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1198 if( NULL == mImpl->mOutlineDefaults )
1200 mImpl->mOutlineDefaults = new OutlineDefaults();
1203 mImpl->mOutlineDefaults->properties = outlineProperties;
1206 const std::string& Controller::GetDefaultOutlineProperties() const
1208 if( NULL != mImpl->mOutlineDefaults )
1210 return mImpl->mOutlineDefaults->properties;
1213 return EMPTY_STRING;
1216 void Controller::SetDefaultLineSpacing( float lineSpacing )
1218 //TODO finish implementation
1219 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1222 float Controller::GetDefaultLineSpacing() const
1224 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1227 void Controller::SetInputColor( const Vector4& color )
1229 if( NULL != mImpl->mEventData )
1231 mImpl->mEventData->mInputStyle.textColor = color;
1232 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1234 if( EventData::SELECTING == mImpl->mEventData->mState )
1236 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1238 // Get start and end position of selection
1239 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1240 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1242 // Add the color run.
1243 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1244 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1246 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1247 colorRun.color = color;
1248 colorRun.characterRun.characterIndex = startOfSelectedText;
1249 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1251 // Request to relayout.
1252 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1253 mImpl->RequestRelayout();
1255 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1256 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1257 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1262 const Vector4& Controller::GetInputColor() const
1264 if( NULL != mImpl->mEventData )
1266 return mImpl->mEventData->mInputStyle.textColor;
1269 // Return the default text's color if there is no EventData.
1270 return mImpl->mTextColor;
1274 void Controller::SetInputFontFamily( const std::string& fontFamily )
1276 if( NULL != mImpl->mEventData )
1278 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1279 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1281 if( EventData::SELECTING == mImpl->mEventData->mState )
1283 CharacterIndex startOfSelectedText = 0u;
1284 Length lengthOfSelectedText = 0u;
1285 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1286 mImpl->mModel->mLogicalModel,
1287 startOfSelectedText,
1288 lengthOfSelectedText );
1290 fontDescriptionRun.familyLength = fontFamily.size();
1291 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1292 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1293 fontDescriptionRun.familyDefined = true;
1295 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1297 // Request to relayout.
1298 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1303 UPDATE_LAYOUT_SIZE |
1306 mImpl->mRecalculateNaturalSize = true;
1307 mImpl->RequestRelayout();
1309 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1310 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1311 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1313 // As the font changes, recalculate the handle positions is needed.
1314 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1315 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1316 mImpl->mEventData->mUpdateHighlightBox = true;
1317 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1322 const std::string& Controller::GetInputFontFamily() const
1324 if( NULL != mImpl->mEventData )
1326 return mImpl->mEventData->mInputStyle.familyName;
1329 // Return the default font's family if there is no EventData.
1330 return GetDefaultFontFamily();
1333 void Controller::SetInputFontWeight( FontWeight weight )
1335 if( NULL != mImpl->mEventData )
1337 mImpl->mEventData->mInputStyle.weight = weight;
1338 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1340 if( EventData::SELECTING == mImpl->mEventData->mState )
1342 CharacterIndex startOfSelectedText = 0u;
1343 Length lengthOfSelectedText = 0u;
1344 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1345 mImpl->mModel->mLogicalModel,
1346 startOfSelectedText,
1347 lengthOfSelectedText );
1349 fontDescriptionRun.weight = weight;
1350 fontDescriptionRun.weightDefined = true;
1352 // Request to relayout.
1353 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1358 UPDATE_LAYOUT_SIZE |
1361 mImpl->mRecalculateNaturalSize = true;
1362 mImpl->RequestRelayout();
1364 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1365 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1366 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1368 // As the font might change, recalculate the handle positions is needed.
1369 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1370 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1371 mImpl->mEventData->mUpdateHighlightBox = true;
1372 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1377 bool Controller::IsInputFontWeightDefined() const
1379 bool defined = false;
1381 if( NULL != mImpl->mEventData )
1383 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1389 FontWeight Controller::GetInputFontWeight() const
1391 if( NULL != mImpl->mEventData )
1393 return mImpl->mEventData->mInputStyle.weight;
1396 return GetDefaultFontWeight();
1399 void Controller::SetInputFontWidth( FontWidth width )
1401 if( NULL != mImpl->mEventData )
1403 mImpl->mEventData->mInputStyle.width = width;
1404 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1406 if( EventData::SELECTING == mImpl->mEventData->mState )
1408 CharacterIndex startOfSelectedText = 0u;
1409 Length lengthOfSelectedText = 0u;
1410 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1411 mImpl->mModel->mLogicalModel,
1412 startOfSelectedText,
1413 lengthOfSelectedText );
1415 fontDescriptionRun.width = width;
1416 fontDescriptionRun.widthDefined = true;
1418 // Request to relayout.
1419 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1424 UPDATE_LAYOUT_SIZE |
1427 mImpl->mRecalculateNaturalSize = true;
1428 mImpl->RequestRelayout();
1430 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1431 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1432 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1434 // As the font might change, recalculate the handle positions is needed.
1435 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1436 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1437 mImpl->mEventData->mUpdateHighlightBox = true;
1438 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1443 bool Controller::IsInputFontWidthDefined() const
1445 bool defined = false;
1447 if( NULL != mImpl->mEventData )
1449 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1455 FontWidth Controller::GetInputFontWidth() const
1457 if( NULL != mImpl->mEventData )
1459 return mImpl->mEventData->mInputStyle.width;
1462 return GetDefaultFontWidth();
1465 void Controller::SetInputFontSlant( FontSlant slant )
1467 if( NULL != mImpl->mEventData )
1469 mImpl->mEventData->mInputStyle.slant = slant;
1470 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1472 if( EventData::SELECTING == mImpl->mEventData->mState )
1474 CharacterIndex startOfSelectedText = 0u;
1475 Length lengthOfSelectedText = 0u;
1476 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1477 mImpl->mModel->mLogicalModel,
1478 startOfSelectedText,
1479 lengthOfSelectedText );
1481 fontDescriptionRun.slant = slant;
1482 fontDescriptionRun.slantDefined = true;
1484 // Request to relayout.
1485 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1490 UPDATE_LAYOUT_SIZE |
1493 mImpl->mRecalculateNaturalSize = true;
1494 mImpl->RequestRelayout();
1496 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1497 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1498 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1500 // As the font might change, recalculate the handle positions is needed.
1501 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1502 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1503 mImpl->mEventData->mUpdateHighlightBox = true;
1504 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1509 bool Controller::IsInputFontSlantDefined() const
1511 bool defined = false;
1513 if( NULL != mImpl->mEventData )
1515 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1521 FontSlant Controller::GetInputFontSlant() const
1523 if( NULL != mImpl->mEventData )
1525 return mImpl->mEventData->mInputStyle.slant;
1528 return GetDefaultFontSlant();
1531 void Controller::SetInputFontPointSize( float size )
1533 if( NULL != mImpl->mEventData )
1535 mImpl->mEventData->mInputStyle.size = size;
1536 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1538 if( EventData::SELECTING == mImpl->mEventData->mState )
1540 CharacterIndex startOfSelectedText = 0u;
1541 Length lengthOfSelectedText = 0u;
1542 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1543 mImpl->mModel->mLogicalModel,
1544 startOfSelectedText,
1545 lengthOfSelectedText );
1547 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1548 fontDescriptionRun.sizeDefined = true;
1550 // Request to relayout.
1551 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1556 UPDATE_LAYOUT_SIZE |
1559 mImpl->mRecalculateNaturalSize = true;
1560 mImpl->RequestRelayout();
1562 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1563 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1564 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1566 // As the font might change, recalculate the handle positions is needed.
1567 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1568 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1569 mImpl->mEventData->mUpdateHighlightBox = true;
1570 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1575 float Controller::GetInputFontPointSize() const
1577 if( NULL != mImpl->mEventData )
1579 return mImpl->mEventData->mInputStyle.size;
1582 // Return the default font's point size if there is no EventData.
1583 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1586 void Controller::SetInputLineSpacing( float lineSpacing )
1588 if( NULL != mImpl->mEventData )
1590 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1591 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1595 float Controller::GetInputLineSpacing() const
1597 if( NULL != mImpl->mEventData )
1599 return mImpl->mEventData->mInputStyle.lineSpacing;
1605 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1607 if( NULL != mImpl->mEventData )
1609 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1613 const std::string& Controller::GetInputShadowProperties() const
1615 if( NULL != mImpl->mEventData )
1617 return mImpl->mEventData->mInputStyle.shadowProperties;
1620 return EMPTY_STRING;
1623 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1625 if( NULL != mImpl->mEventData )
1627 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1631 const std::string& Controller::GetInputUnderlineProperties() const
1633 if( NULL != mImpl->mEventData )
1635 return mImpl->mEventData->mInputStyle.underlineProperties;
1638 return EMPTY_STRING;
1641 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1643 if( NULL != mImpl->mEventData )
1645 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1649 const std::string& Controller::GetInputEmbossProperties() const
1651 if( NULL != mImpl->mEventData )
1653 return mImpl->mEventData->mInputStyle.embossProperties;
1656 return GetDefaultEmbossProperties();
1659 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1661 if( NULL != mImpl->mEventData )
1663 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1667 const std::string& Controller::GetInputOutlineProperties() const
1669 if( NULL != mImpl->mEventData )
1671 return mImpl->mEventData->mInputStyle.outlineProperties;
1674 return GetDefaultOutlineProperties();
1677 void Controller::SetInputModePassword( bool passwordInput )
1679 if( NULL != mImpl->mEventData )
1681 mImpl->mEventData->mPasswordInput = passwordInput;
1685 bool Controller::IsInputModePassword()
1687 if( NULL != mImpl->mEventData )
1689 return mImpl->mEventData->mPasswordInput;
1694 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1696 if( NULL != mImpl->mEventData )
1698 mImpl->mEventData->mDoubleTapAction = action;
1702 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1704 NoTextTap::Action action = NoTextTap::NO_ACTION;
1706 if( NULL != mImpl->mEventData )
1708 action = mImpl->mEventData->mDoubleTapAction;
1714 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1716 if( NULL != mImpl->mEventData )
1718 mImpl->mEventData->mLongPressAction = action;
1722 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1724 NoTextTap::Action action = NoTextTap::NO_ACTION;
1726 if( NULL != mImpl->mEventData )
1728 action = mImpl->mEventData->mLongPressAction;
1734 bool Controller::IsUnderlineSetByString()
1736 return mImpl->mUnderlineSetByString;
1739 void Controller::UnderlineSetByString( bool setByString )
1741 mImpl->mUnderlineSetByString = setByString;
1744 bool Controller::IsShadowSetByString()
1746 return mImpl->mShadowSetByString;
1749 void Controller::ShadowSetByString( bool setByString )
1751 mImpl->mShadowSetByString = setByString;
1754 bool Controller::IsOutlineSetByString()
1756 return mImpl->mOutlineSetByString;
1759 void Controller::OutlineSetByString( bool setByString )
1761 mImpl->mOutlineSetByString = setByString;
1764 bool Controller::IsFontStyleSetByString()
1766 return mImpl->mFontStyleSetByString;
1769 void Controller::FontStyleSetByString( bool setByString )
1771 mImpl->mFontStyleSetByString = setByString;
1774 // public : Queries & retrieves.
1776 Layout::Engine& Controller::GetLayoutEngine()
1778 return mImpl->mLayoutEngine;
1781 View& Controller::GetView()
1783 return mImpl->mView;
1786 Vector3 Controller::GetNaturalSize()
1788 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1789 Vector3 naturalSize;
1791 // Make sure the model is up-to-date before layouting
1792 ProcessModifyEvents();
1794 if( mImpl->mRecalculateNaturalSize )
1796 // Operations that can be done only once until the text changes.
1797 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1804 GET_GLYPH_METRICS );
1806 // Set the update info to relayout the whole text.
1807 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1808 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1810 // Make sure the model is up-to-date before layouting
1811 mImpl->UpdateModel( onlyOnceOperations );
1813 // Layout the text for the new width.
1814 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1816 // Store the actual control's size to restore later.
1817 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1819 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1820 static_cast<OperationsMask>( onlyOnceOperations |
1822 naturalSize.GetVectorXY() );
1824 // Do not do again the only once operations.
1825 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1827 // Do the size related operations again.
1828 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1831 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1833 // Stores the natural size to avoid recalculate it again
1834 // unless the text/style changes.
1835 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1837 mImpl->mRecalculateNaturalSize = false;
1839 // Clear the update info. This info will be set the next time the text is updated.
1840 mImpl->mTextUpdateInfo.Clear();
1842 // Restore the actual control's size.
1843 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1845 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1849 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1851 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1854 naturalSize.x = ConvertToEven( naturalSize.x );
1855 naturalSize.y = ConvertToEven( naturalSize.y );
1860 float Controller::GetHeightForWidth( float width )
1862 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1863 // Make sure the model is up-to-date before layouting
1864 ProcessModifyEvents();
1867 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1868 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1869 mImpl->mTextUpdateInfo.mClearAll )
1871 // Operations that can be done only once until the text changes.
1872 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1879 GET_GLYPH_METRICS );
1881 // Set the update info to relayout the whole text.
1882 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1883 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1885 // Make sure the model is up-to-date before layouting
1886 mImpl->UpdateModel( onlyOnceOperations );
1889 // Layout the text for the new width.
1890 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1892 // Store the actual control's width.
1893 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1895 DoRelayout( Size( width, MAX_FLOAT ),
1896 static_cast<OperationsMask>( onlyOnceOperations |
1900 // Do not do again the only once operations.
1901 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1903 // Do the size related operations again.
1904 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1908 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1910 // Clear the update info. This info will be set the next time the text is updated.
1911 mImpl->mTextUpdateInfo.Clear();
1913 // Restore the actual control's width.
1914 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1916 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1920 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1921 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1924 return layoutSize.height;
1927 int Controller::GetLineCount( float width )
1929 GetHeightForWidth( width );
1930 int numberofLines = mImpl->mModel->GetNumberOfLines();
1931 return numberofLines;
1934 const ModelInterface* const Controller::GetTextModel() const
1936 return mImpl->mModel.Get();
1939 float Controller::GetScrollAmountByUserInput()
1941 float scrollAmount = 0.0f;
1943 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1945 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1946 mImpl->mEventData->mCheckScrollAmount = false;
1948 return scrollAmount;
1951 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1953 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1956 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1957 layoutHeight = layout.height;
1958 scrollPosition = mImpl->mModel->mScrollPosition.y;
1959 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1963 void Controller::SetHiddenInputOption(const Property::Map& options )
1965 if( NULL == mImpl->mHiddenInput )
1967 mImpl->mHiddenInput = new HiddenText( this );
1969 mImpl->mHiddenInput->SetProperties(options);
1972 void Controller::GetHiddenInputOption(Property::Map& options )
1974 if( NULL != mImpl->mHiddenInput )
1976 mImpl->mHiddenInput->GetProperties(options);
1980 void Controller::SetPlaceholderProperty( const Property::Map& map )
1982 const Property::Map::SizeType count = map.Count();
1984 for( Property::Map::SizeType position = 0; position < count; ++position )
1986 KeyValuePair keyValue = map.GetKeyValue( position );
1987 Property::Key& key = keyValue.first;
1988 Property::Value& value = keyValue.second;
1990 if( key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT )
1992 std::string text = "";
1994 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
1996 else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
1998 std::string text = "";
2000 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2002 else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2005 value.Get( textColor );
2006 if( GetPlaceholderTextColor() != textColor )
2008 SetPlaceholderTextColor( textColor );
2011 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2013 std::string fontFamily = "";
2014 value.Get( fontFamily );
2015 SetPlaceholderFontFamily( fontFamily );
2017 else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2019 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2021 else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2024 value.Get( pointSize );
2025 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2027 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2030 else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2033 value.Get( pixelSize );
2034 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2036 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2039 else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2042 value.Get( ellipsis );
2043 SetPlaceholderTextElideEnabled( ellipsis );
2048 void Controller::GetPlaceholderProperty( Property::Map& map )
2050 if( NULL != mImpl->mEventData )
2052 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2054 map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2056 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2058 map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2061 map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2062 map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2064 Property::Value fontStyleMapGet;
2065 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2066 map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2068 // Choose font size : POINT_SIZE or PIXEL_SIZE
2069 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2071 map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2075 map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2078 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2080 map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2085 // public : Relayout.
2087 Controller::UpdateTextType Controller::Relayout( const Size& size )
2089 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2091 UpdateTextType updateTextType = NONE_UPDATED;
2093 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2095 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2097 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2098 updateTextType = MODEL_UPDATED;
2101 // Clear the update info. This info will be set the next time the text is updated.
2102 mImpl->mTextUpdateInfo.Clear();
2104 // Not worth to relayout if width or height is equal to zero.
2105 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2107 return updateTextType;
2110 // Whether a new size has been set.
2111 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2115 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2117 // Layout operations that need to be done if the size changes.
2118 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2121 UPDATE_LAYOUT_SIZE |
2123 // Set the update info to relayout the whole text.
2124 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2125 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2127 // Store the size used to layout the text.
2128 mImpl->mModel->mVisualModel->mControlSize = size;
2131 // Whether there are modify events.
2132 if( 0u != mImpl->mModifyEvents.Count() )
2134 // Style operations that need to be done if the text is modified.
2135 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2139 // Set the update info to elide the text.
2140 if( mImpl->mModel->mElideEnabled ||
2141 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2143 // Update Text layout for applying elided
2144 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2147 UPDATE_LAYOUT_SIZE |
2149 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2150 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2153 // Make sure the model is up-to-date before layouting.
2154 ProcessModifyEvents();
2155 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2159 updated = DoRelayout( size,
2160 mImpl->mOperationsPending,
2161 layoutSize ) || updated;
2165 updateTextType = MODEL_UPDATED;
2168 // Do not re-do any operation until something changes.
2169 mImpl->mOperationsPending = NO_OPERATION;
2170 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2172 // Whether the text control is editable
2173 const bool isEditable = NULL != mImpl->mEventData;
2175 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2177 if( newSize && isEditable )
2179 offset = mImpl->mModel->mScrollPosition;
2182 if( !isEditable || !IsMultiLineEnabled() )
2184 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2185 CalculateVerticalOffset( size );
2192 // If there is a new size, the scroll position needs to be clamped.
2193 mImpl->ClampHorizontalScroll( layoutSize );
2195 // Update the decorator's positions is needed if there is a new size.
2196 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2199 // Move the cursor, grab handle etc.
2200 if( mImpl->ProcessInputEvents() )
2202 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2206 // Clear the update info. This info will be set the next time the text is updated.
2207 mImpl->mTextUpdateInfo.Clear();
2208 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2210 return updateTextType;
2213 void Controller::RequestRelayout()
2215 mImpl->RequestRelayout();
2218 // public : Input style change signals.
2220 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2222 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2225 void Controller::ProcessInputStyleChangedSignals()
2227 if( NULL == mImpl->mEventData )
2233 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2234 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2238 const InputStyle::Mask mask = *it;
2240 if( NULL != mImpl->mEditableControlInterface )
2242 // Emit the input style changed signal.
2243 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2247 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2250 // public : Text-input Event Queuing.
2252 void Controller::KeyboardFocusGainEvent()
2254 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2256 if( NULL != mImpl->mEventData )
2258 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2259 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2261 mImpl->ChangeState( EventData::EDITING );
2262 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2263 mImpl->mEventData->mUpdateInputStyle = true;
2265 mImpl->NotifyImfMultiLineStatus();
2266 if( mImpl->IsShowingPlaceholderText() )
2268 // Show alternative placeholder-text when editing
2269 ShowPlaceholderText();
2272 mImpl->RequestRelayout();
2276 void Controller::KeyboardFocusLostEvent()
2278 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2280 if( NULL != mImpl->mEventData )
2282 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2284 mImpl->ChangeState( EventData::INACTIVE );
2286 if( !mImpl->IsShowingRealText() )
2288 // Revert to regular placeholder-text when not editing
2289 ShowPlaceholderText();
2293 mImpl->RequestRelayout();
2296 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2298 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2300 bool textChanged = false;
2301 bool relayoutNeeded = false;
2303 if( ( NULL != mImpl->mEventData ) &&
2304 ( keyEvent.state == KeyEvent::Down ) )
2306 int keyCode = keyEvent.keyCode;
2307 const std::string& keyString = keyEvent.keyPressed;
2309 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2311 // Pre-process to separate modifying events from non-modifying input events.
2314 // In some platforms arrive key events with no key code.
2318 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode )
2323 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2324 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2325 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2326 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2328 // If don't have any text, do nothing.
2329 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2334 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2335 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2336 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2337 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2339 // Logic to determine whether this text control will lose focus or not.
2340 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2341 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2342 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2343 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2344 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2345 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2350 mImpl->mEventData->mCheckScrollAmount = true;
2351 Event event( Event::CURSOR_KEY_EVENT );
2352 event.p1.mInt = keyCode;
2353 mImpl->mEventData->mEventQueue.push_back( event );
2355 // Will request for relayout.
2356 relayoutNeeded = true;
2358 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
2360 textChanged = BackspaceKeyEvent();
2362 // Will request for relayout.
2363 relayoutNeeded = true;
2365 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2366 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2367 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2369 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2370 mImpl->ChangeState( EventData::INACTIVE );
2372 // Will request for relayout.
2373 relayoutNeeded = true;
2375 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2377 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2379 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2380 // and a character is typed after the type of a upper case latin character.
2385 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2387 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2393 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2395 // IMF manager is no longer handling key-events
2396 mImpl->ClearPreEditFlag();
2398 InsertText( keyString, COMMIT );
2401 // Will request for relayout.
2402 relayoutNeeded = true;
2405 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2406 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2408 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2409 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2410 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2412 // Should not change the state if the key is the shift send by the imf manager.
2413 // Otherwise, when the state is SELECTING the text controller can't send the right
2414 // surrounding info to the imf.
2415 mImpl->ChangeState( EventData::EDITING );
2417 // Will request for relayout.
2418 relayoutNeeded = true;
2421 if( relayoutNeeded )
2423 mImpl->RequestRelayout();
2428 ( NULL != mImpl->mEditableControlInterface ) )
2430 // Do this last since it provides callbacks into application code
2431 mImpl->mEditableControlInterface->TextChanged();
2437 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2439 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2441 if( NULL != mImpl->mEventData )
2443 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2444 EventData::State state( mImpl->mEventData->mState );
2445 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2447 if( mImpl->IsClipboardVisible() )
2449 if( EventData::INACTIVE == state || EventData::EDITING == state)
2451 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2453 relayoutNeeded = true;
2455 else if( 1u == tapCount )
2457 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2459 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2462 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2464 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2465 relayoutNeeded = true;
2469 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2471 // Hide placeholder text
2475 if( EventData::INACTIVE == state )
2477 mImpl->ChangeState( EventData::EDITING );
2479 else if( !mImpl->IsClipboardEmpty() )
2481 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2483 relayoutNeeded = true;
2486 else if( 2u == tapCount )
2488 if( mImpl->mEventData->mSelectionEnabled &&
2489 mImpl->IsShowingRealText() )
2491 relayoutNeeded = true;
2492 mImpl->mEventData->mIsLeftHandleSelected = true;
2493 mImpl->mEventData->mIsRightHandleSelected = true;
2497 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2498 if( relayoutNeeded )
2500 Event event( Event::TAP_EVENT );
2501 event.p1.mUint = tapCount;
2502 event.p2.mFloat = x;
2503 event.p3.mFloat = y;
2504 mImpl->mEventData->mEventQueue.push_back( event );
2506 mImpl->RequestRelayout();
2510 // Reset keyboard as tap event has occurred.
2511 mImpl->ResetImfManager();
2514 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2516 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2518 if( NULL != mImpl->mEventData )
2520 Event event( Event::PAN_EVENT );
2521 event.p1.mInt = state;
2522 event.p2.mFloat = displacement.x;
2523 event.p3.mFloat = displacement.y;
2524 mImpl->mEventData->mEventQueue.push_back( event );
2526 mImpl->RequestRelayout();
2530 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2532 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2534 if( ( state == Gesture::Started ) &&
2535 ( NULL != mImpl->mEventData ) )
2537 // The 1st long-press on inactive text-field is treated as tap
2538 if( EventData::INACTIVE == mImpl->mEventData->mState )
2540 mImpl->ChangeState( EventData::EDITING );
2542 Event event( Event::TAP_EVENT );
2544 event.p2.mFloat = x;
2545 event.p3.mFloat = y;
2546 mImpl->mEventData->mEventQueue.push_back( event );
2548 mImpl->RequestRelayout();
2550 else if( !mImpl->IsShowingRealText() )
2552 Event event( Event::LONG_PRESS_EVENT );
2553 event.p1.mInt = state;
2554 event.p2.mFloat = x;
2555 event.p3.mFloat = y;
2556 mImpl->mEventData->mEventQueue.push_back( event );
2557 mImpl->RequestRelayout();
2559 else if( !mImpl->IsClipboardVisible() )
2561 // Reset the imf manager to commit the pre-edit before selecting the text.
2562 mImpl->ResetImfManager();
2564 Event event( Event::LONG_PRESS_EVENT );
2565 event.p1.mInt = state;
2566 event.p2.mFloat = x;
2567 event.p3.mFloat = y;
2568 mImpl->mEventData->mEventQueue.push_back( event );
2569 mImpl->RequestRelayout();
2571 mImpl->mEventData->mIsLeftHandleSelected = true;
2572 mImpl->mEventData->mIsRightHandleSelected = true;
2577 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2579 // Whether the text needs to be relaid-out.
2580 bool requestRelayout = false;
2582 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2583 bool retrieveText = false;
2584 bool retrieveCursor = false;
2586 switch( imfEvent.eventName )
2588 case ImfManager::COMMIT:
2590 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2591 requestRelayout = true;
2592 retrieveCursor = true;
2595 case ImfManager::PREEDIT:
2597 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2598 requestRelayout = true;
2599 retrieveCursor = true;
2602 case ImfManager::DELETESURROUNDING:
2604 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2605 imfEvent.numberOfChars,
2606 DONT_UPDATE_INPUT_STYLE );
2610 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2611 !mImpl->IsPlaceholderAvailable() )
2613 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2617 ShowPlaceholderText();
2619 mImpl->mEventData->mUpdateCursorPosition = true;
2620 mImpl->mEventData->mScrollAfterDelete = true;
2622 requestRelayout = true;
2626 case ImfManager::GETSURROUNDING:
2628 retrieveText = true;
2629 retrieveCursor = true;
2632 case ImfManager::PRIVATECOMMAND:
2634 // PRIVATECOMMAND event is just for getting the private command message
2635 retrieveText = true;
2636 retrieveCursor = true;
2639 case ImfManager::VOID:
2646 if( requestRelayout )
2648 mImpl->mOperationsPending = ALL_OPERATIONS;
2649 mImpl->RequestRelayout();
2653 CharacterIndex cursorPosition = 0u;
2654 Length numberOfWhiteSpaces = 0u;
2656 if( retrieveCursor )
2658 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2660 cursorPosition = mImpl->GetLogicalCursorPosition();
2662 if( cursorPosition < numberOfWhiteSpaces )
2664 cursorPosition = 0u;
2668 cursorPosition -= numberOfWhiteSpaces;
2674 mImpl->GetText( numberOfWhiteSpaces, text );
2677 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2679 if( requestRelayout &&
2680 ( NULL != mImpl->mEditableControlInterface ) )
2682 // Do this last since it provides callbacks into application code
2683 mImpl->mEditableControlInterface->TextChanged();
2686 return callbackData;
2689 void Controller::PasteClipboardItemEvent()
2691 // Retrieve the clipboard contents first
2692 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2693 std::string stringToPaste( notifier.GetContent() );
2695 // Commit the current pre-edit text; the contents of the clipboard should be appended
2696 mImpl->ResetImfManager();
2698 // Temporary disable hiding clipboard
2699 mImpl->SetClipboardHideEnable( false );
2702 PasteText( stringToPaste );
2704 mImpl->SetClipboardHideEnable( true );
2707 // protected : Inherit from Text::Decorator::ControllerInterface.
2709 void Controller::GetTargetSize( Vector2& targetSize )
2711 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2714 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2716 if( NULL != mImpl->mEditableControlInterface )
2718 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2722 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2724 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2726 if( NULL != mImpl->mEventData )
2728 switch( handleType )
2732 Event event( Event::GRAB_HANDLE_EVENT );
2733 event.p1.mUint = state;
2734 event.p2.mFloat = x;
2735 event.p3.mFloat = y;
2737 mImpl->mEventData->mEventQueue.push_back( event );
2740 case LEFT_SELECTION_HANDLE:
2742 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2743 event.p1.mUint = state;
2744 event.p2.mFloat = x;
2745 event.p3.mFloat = y;
2747 mImpl->mEventData->mEventQueue.push_back( event );
2750 case RIGHT_SELECTION_HANDLE:
2752 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2753 event.p1.mUint = state;
2754 event.p2.mFloat = x;
2755 event.p3.mFloat = y;
2757 mImpl->mEventData->mEventQueue.push_back( event );
2760 case LEFT_SELECTION_HANDLE_MARKER:
2761 case RIGHT_SELECTION_HANDLE_MARKER:
2763 // Markers do not move the handles.
2766 case HANDLE_TYPE_COUNT:
2768 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2772 mImpl->RequestRelayout();
2776 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2778 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2780 if( NULL == mImpl->mEventData )
2787 case Toolkit::TextSelectionPopup::CUT:
2789 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2790 mImpl->mOperationsPending = ALL_OPERATIONS;
2792 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2793 !mImpl->IsPlaceholderAvailable() )
2795 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2799 ShowPlaceholderText();
2802 mImpl->mEventData->mUpdateCursorPosition = true;
2803 mImpl->mEventData->mScrollAfterDelete = true;
2805 mImpl->RequestRelayout();
2807 if( NULL != mImpl->mEditableControlInterface )
2809 mImpl->mEditableControlInterface->TextChanged();
2813 case Toolkit::TextSelectionPopup::COPY:
2815 mImpl->SendSelectionToClipboard( false ); // Text not modified
2817 mImpl->mEventData->mUpdateCursorPosition = true;
2819 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2822 case Toolkit::TextSelectionPopup::PASTE:
2824 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2827 case Toolkit::TextSelectionPopup::SELECT:
2829 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2831 if( mImpl->mEventData->mSelectionEnabled )
2833 // Creates a SELECT event.
2834 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2838 case Toolkit::TextSelectionPopup::SELECT_ALL:
2840 // Creates a SELECT_ALL event
2841 SelectEvent( 0.f, 0.f, true );
2844 case Toolkit::TextSelectionPopup::CLIPBOARD:
2846 mImpl->ShowClipboard();
2849 case Toolkit::TextSelectionPopup::NONE:
2857 void Controller::DisplayTimeExpired()
2859 mImpl->mEventData->mUpdateCursorPosition = true;
2860 // Apply modifications to the model
2861 mImpl->mOperationsPending = ALL_OPERATIONS;
2863 mImpl->RequestRelayout();
2866 // private : Update.
2868 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2870 bool removedPrevious = false;
2871 bool removedSelected = false;
2872 bool maxLengthReached = false;
2874 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2876 if( NULL == mImpl->mEventData )
2881 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2882 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2883 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2885 // TODO: At the moment the underline runs are only for pre-edit.
2886 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2888 // Remove the previous IMF pre-edit.
2889 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2891 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2892 mImpl->mEventData->mPreEditLength,
2893 DONT_UPDATE_INPUT_STYLE );
2895 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2896 mImpl->mEventData->mPreEditLength = 0u;
2900 // Remove the previous Selection.
2901 removedSelected = RemoveSelectedText();
2905 Vector<Character> utf32Characters;
2906 Length characterCount = 0u;
2910 // Convert text into UTF-32
2911 utf32Characters.Resize( text.size() );
2913 // This is a bit horrible but std::string returns a (signed) char*
2914 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2916 // Transform a text array encoded in utf8 into an array encoded in utf32.
2917 // It returns the actual number of characters.
2918 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2919 utf32Characters.Resize( characterCount );
2921 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2922 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2925 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2927 // The placeholder text is no longer needed
2928 if( mImpl->IsShowingPlaceholderText() )
2933 mImpl->ChangeState( EventData::EDITING );
2935 // Handle the IMF (predicitive text) state changes
2936 if( COMMIT == type )
2938 // IMF manager is no longer handling key-events
2939 mImpl->ClearPreEditFlag();
2943 if( !mImpl->mEventData->mPreEditFlag )
2945 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2947 // Record the start of the pre-edit text
2948 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2951 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2952 mImpl->mEventData->mPreEditFlag = true;
2954 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2957 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2959 // Restrict new text to fit within Maximum characters setting.
2960 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2961 maxLengthReached = ( characterCount > maxSizeOfNewText );
2963 // The cursor position.
2964 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2966 // Update the text's style.
2968 // Updates the text style runs by adding characters.
2969 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2971 // Get the character index from the cursor index.
2972 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2974 // Retrieve the text's style for the given index.
2976 mImpl->RetrieveDefaultInputStyle( style );
2977 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2979 // Whether to add a new text color run.
2980 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2982 // Whether to add a new font run.
2983 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2984 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2985 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2986 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2987 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2992 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2993 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2995 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2996 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2997 colorRun.characterRun.characterIndex = cursorIndex;
2998 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3001 if( addFontNameRun ||
3007 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3008 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3010 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3012 if( addFontNameRun )
3014 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3015 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3016 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3017 fontDescriptionRun.familyDefined = true;
3019 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3022 if( addFontWeightRun )
3024 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3025 fontDescriptionRun.weightDefined = true;
3028 if( addFontWidthRun )
3030 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3031 fontDescriptionRun.widthDefined = true;
3034 if( addFontSlantRun )
3036 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3037 fontDescriptionRun.slantDefined = true;
3040 if( addFontSizeRun )
3042 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3043 fontDescriptionRun.sizeDefined = true;
3046 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3047 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3050 // Insert at current cursor position.
3051 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3053 if( cursorIndex < numberOfCharactersInModel )
3055 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3059 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3062 // Mark the first paragraph to be updated.
3063 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3065 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3066 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3067 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3068 mImpl->mTextUpdateInfo.mClearAll = true;
3072 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3073 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3076 // Update the cursor index.
3077 cursorIndex += maxSizeOfNewText;
3079 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 );
3082 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3083 mImpl->IsPlaceholderAvailable() )
3085 // Show place-holder if empty after removing the pre-edit text
3086 ShowPlaceholderText();
3087 mImpl->mEventData->mUpdateCursorPosition = true;
3088 mImpl->ClearPreEditFlag();
3090 else if( removedPrevious ||
3092 ( 0 != utf32Characters.Count() ) )
3094 // Queue an inserted event
3095 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3097 mImpl->mEventData->mUpdateCursorPosition = true;
3098 if( removedSelected )
3100 mImpl->mEventData->mScrollAfterDelete = true;
3104 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3108 if( maxLengthReached )
3110 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3112 mImpl->ResetImfManager();
3114 if( NULL != mImpl->mEditableControlInterface )
3116 // Do this last since it provides callbacks into application code
3117 mImpl->mEditableControlInterface->MaxLengthReached();
3122 void Controller::PasteText( const std::string& stringToPaste )
3124 InsertText( stringToPaste, Text::Controller::COMMIT );
3125 mImpl->ChangeState( EventData::EDITING );
3126 mImpl->RequestRelayout();
3128 if( NULL != mImpl->mEditableControlInterface )
3130 // Do this last since it provides callbacks into application code
3131 mImpl->mEditableControlInterface->TextChanged();
3135 bool Controller::RemoveText( int cursorOffset,
3136 int numberOfCharacters,
3137 UpdateInputStyleType type )
3139 bool removed = false;
3141 if( NULL == mImpl->mEventData )
3146 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3147 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3149 if( !mImpl->IsShowingPlaceholderText() )
3151 // Delete at current cursor position
3152 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3153 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3155 CharacterIndex cursorIndex = 0;
3157 // Validate the cursor position & number of characters
3158 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3160 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3163 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3165 numberOfCharacters = currentText.Count() - cursorIndex;
3168 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.
3169 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3171 // Mark the paragraphs to be updated.
3172 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3174 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3175 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3176 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3177 mImpl->mTextUpdateInfo.mClearAll = true;
3181 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3182 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3185 // Update the input style and remove the text's style before removing the text.
3187 if( UPDATE_INPUT_STYLE == type )
3189 // Keep a copy of the current input style.
3190 InputStyle currentInputStyle;
3191 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3193 // Set first the default input style.
3194 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3196 // Update the input style.
3197 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3199 // Compare if the input style has changed.
3200 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3202 if( hasInputStyleChanged )
3204 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3205 // Queue the input style changed signal.
3206 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3210 // Updates the text style runs by removing characters. Runs with no characters are removed.
3211 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3213 // Remove the characters.
3214 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3215 Vector<Character>::Iterator last = first + numberOfCharacters;
3217 currentText.Erase( first, last );
3219 // Cursor position retreat
3220 oldCursorIndex = cursorIndex;
3222 mImpl->mEventData->mScrollAfterDelete = true;
3224 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3232 bool Controller::RemoveSelectedText()
3234 bool textRemoved( false );
3236 if( EventData::SELECTING == mImpl->mEventData->mState )
3238 std::string removedString;
3239 mImpl->RetrieveSelection( removedString, true );
3241 if( !removedString.empty() )
3244 mImpl->ChangeState( EventData::EDITING );
3251 // private : Relayout.
3253 bool Controller::DoRelayout( const Size& size,
3254 OperationsMask operationsRequired,
3257 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3258 bool viewUpdated( false );
3260 // Calculate the operations to be done.
3261 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3263 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3264 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3266 // Get the current layout size.
3267 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3269 if( NO_OPERATION != ( LAYOUT & operations ) )
3271 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3273 // Some vectors with data needed to layout and reorder may be void
3274 // after the first time the text has been laid out.
3275 // Fill the vectors again.
3277 // Calculate the number of glyphs to layout.
3278 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3279 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3280 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3281 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3283 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3284 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3285 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3286 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3288 if( 0u == totalNumberOfGlyphs )
3290 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3292 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3295 // Nothing else to do if there is no glyphs.
3296 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3300 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3301 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3302 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3303 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3304 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3305 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3306 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3308 // Set the layout parameters.
3309 Layout::Parameters layoutParameters( size,
3311 lineBreakInfo.Begin(),
3312 wordBreakInfo.Begin(),
3313 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3315 glyphsToCharactersMap.Begin(),
3316 charactersPerGlyph.Begin(),
3317 charactersToGlyphBuffer,
3318 glyphsPerCharacterBuffer,
3319 totalNumberOfGlyphs,
3320 mImpl->mModel->mHorizontalAlignment,
3321 mImpl->mModel->mLineWrapMode );
3323 // Resize the vector of positions to have the same size than the vector of glyphs.
3324 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3325 glyphPositions.Resize( totalNumberOfGlyphs );
3327 // Whether the last character is a new paragraph character.
3328 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3329 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3331 // The initial glyph and the number of glyphs to layout.
3332 layoutParameters.startGlyphIndex = startGlyphIndex;
3333 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3334 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3335 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3337 // Update the ellipsis
3338 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3340 if( NULL != mImpl->mEventData )
3342 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3344 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3346 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3348 // Disable ellipsis when editing
3349 elideTextEnabled = false;
3352 // Reset the scroll position in inactive state
3353 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3355 ResetScrollPosition();
3359 // Update the visual model.
3361 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3363 mImpl->mModel->mVisualModel->mLines,
3367 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3371 layoutSize = newLayoutSize;
3373 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3375 mImpl->mAutoScrollDirectionRTL = false;
3378 // Reorder the lines
3379 if( NO_OPERATION != ( REORDER & operations ) )
3381 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3382 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3384 // Check first if there are paragraphs with bidirectional info.
3385 if( 0u != bidirectionalInfo.Count() )
3388 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3390 // Reorder the lines.
3391 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3392 ReorderLines( bidirectionalInfo,
3394 requestedNumberOfCharacters,
3395 mImpl->mModel->mVisualModel->mLines,
3396 bidirectionalLineInfo );
3398 // Set the bidirectional info per line into the layout parameters.
3399 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3400 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3402 // Re-layout the text. Reorder those lines with right to left characters.
3403 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3405 requestedNumberOfCharacters,
3408 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3410 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3413 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3419 // Sets the layout size.
3420 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3422 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3427 if( NO_OPERATION != ( ALIGN & operations ) )
3429 // The laid-out lines.
3430 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3432 // Need to align with the control's size as the text may contain lines
3433 // starting either with left to right text or right to left.
3434 mImpl->mLayoutEngine.Align( size,
3436 requestedNumberOfCharacters,
3437 mImpl->mModel->mHorizontalAlignment,
3439 mImpl->mModel->mAlignmentOffset );
3443 #if defined(DEBUG_ENABLED)
3444 std::string currentText;
3445 GetText( currentText );
3446 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3448 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3452 void Controller::CalculateVerticalOffset( const Size& controlSize )
3454 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3456 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3458 // Get the line height of the default font.
3459 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3462 switch( mImpl->mModel->mVerticalAlignment )
3464 case VerticalAlignment::TOP:
3466 mImpl->mModel->mScrollPosition.y = 0.f;
3469 case VerticalAlignment::CENTER:
3471 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3474 case VerticalAlignment::BOTTOM:
3476 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3482 // private : Events.
3484 void Controller::ProcessModifyEvents()
3486 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3488 if( 0u == events.Count() )
3494 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3495 endIt = events.End();
3499 const ModifyEvent& event = *it;
3501 if( ModifyEvent::TEXT_REPLACED == event.type )
3503 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3504 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3506 TextReplacedEvent();
3508 else if( ModifyEvent::TEXT_INSERTED == event.type )
3510 TextInsertedEvent();
3512 else if( ModifyEvent::TEXT_DELETED == event.type )
3514 // Placeholder-text cannot be deleted
3515 if( !mImpl->IsShowingPlaceholderText() )
3522 if( NULL != mImpl->mEventData )
3524 // When the text is being modified, delay cursor blinking
3525 mImpl->mEventData->mDecorator->DelayCursorBlink();
3528 // Discard temporary text
3532 void Controller::TextReplacedEvent()
3534 // The natural size needs to be re-calculated.
3535 mImpl->mRecalculateNaturalSize = true;
3537 // Apply modifications to the model
3538 mImpl->mOperationsPending = ALL_OPERATIONS;
3541 void Controller::TextInsertedEvent()
3543 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3545 if( NULL == mImpl->mEventData )
3550 mImpl->mEventData->mCheckScrollAmount = true;
3552 // The natural size needs to be re-calculated.
3553 mImpl->mRecalculateNaturalSize = true;
3555 // Apply modifications to the model; TODO - Optimize this
3556 mImpl->mOperationsPending = ALL_OPERATIONS;
3559 void Controller::TextDeletedEvent()
3561 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3563 if( NULL == mImpl->mEventData )
3568 mImpl->mEventData->mCheckScrollAmount = true;
3570 // The natural size needs to be re-calculated.
3571 mImpl->mRecalculateNaturalSize = true;
3573 // Apply modifications to the model; TODO - Optimize this
3574 mImpl->mOperationsPending = ALL_OPERATIONS;
3577 void Controller::SelectEvent( float x, float y, bool selectAll )
3579 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3581 if( NULL != mImpl->mEventData )
3585 Event event( Event::SELECT_ALL );
3586 mImpl->mEventData->mEventQueue.push_back( event );
3590 Event event( Event::SELECT );
3591 event.p2.mFloat = x;
3592 event.p3.mFloat = y;
3593 mImpl->mEventData->mEventQueue.push_back( event );
3596 mImpl->mEventData->mCheckScrollAmount = true;
3597 mImpl->mEventData->mIsLeftHandleSelected = true;
3598 mImpl->mEventData->mIsRightHandleSelected = true;
3599 mImpl->RequestRelayout();
3603 bool Controller::BackspaceKeyEvent()
3605 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3607 bool removed = false;
3609 if( NULL == mImpl->mEventData )
3614 // IMF manager is no longer handling key-events
3615 mImpl->ClearPreEditFlag();
3617 if( EventData::SELECTING == mImpl->mEventData->mState )
3619 removed = RemoveSelectedText();
3621 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3623 // Remove the character before the current cursor position
3624 removed = RemoveText( -1,
3626 UPDATE_INPUT_STYLE );
3631 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3632 !mImpl->IsPlaceholderAvailable() )
3634 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3638 ShowPlaceholderText();
3640 mImpl->mEventData->mUpdateCursorPosition = true;
3641 mImpl->mEventData->mScrollAfterDelete = true;
3647 // private : Helpers.
3649 void Controller::ResetText()
3652 mImpl->mModel->mLogicalModel->mText.Clear();
3654 // We have cleared everything including the placeholder-text
3655 mImpl->PlaceholderCleared();
3657 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3658 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3659 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3661 // Clear any previous text.
3662 mImpl->mTextUpdateInfo.mClearAll = true;
3664 // The natural size needs to be re-calculated.
3665 mImpl->mRecalculateNaturalSize = true;
3667 // Apply modifications to the model
3668 mImpl->mOperationsPending = ALL_OPERATIONS;
3671 void Controller::ShowPlaceholderText()
3673 if( mImpl->IsPlaceholderAvailable() )
3675 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3677 if( NULL == mImpl->mEventData )
3682 mImpl->mEventData->mIsShowingPlaceholderText = true;
3684 // Disable handles when showing place-holder text
3685 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3686 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3687 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3689 const char* text( NULL );
3692 // TODO - Switch Placeholder text when changing state
3693 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3694 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3696 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3697 size = mImpl->mEventData->mPlaceholderTextActive.size();
3701 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3702 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3705 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3706 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3708 // Reset model for showing placeholder.
3709 mImpl->mModel->mLogicalModel->mText.Clear();
3710 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3712 // Convert text into UTF-32
3713 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3714 utf32Characters.Resize( size );
3716 // This is a bit horrible but std::string returns a (signed) char*
3717 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3719 // Transform a text array encoded in utf8 into an array encoded in utf32.
3720 // It returns the actual number of characters.
3721 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3722 utf32Characters.Resize( characterCount );
3724 // The characters to be added.
3725 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3727 // Reset the cursor position
3728 mImpl->mEventData->mPrimaryCursorPosition = 0;
3730 // The natural size needs to be re-calculated.
3731 mImpl->mRecalculateNaturalSize = true;
3733 // Apply modifications to the model
3734 mImpl->mOperationsPending = ALL_OPERATIONS;
3736 // Update the rest of the model during size negotiation
3737 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3741 void Controller::ClearFontData()
3743 if( mImpl->mFontDefaults )
3745 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3748 // Set flags to update the model.
3749 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3750 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3751 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3753 mImpl->mTextUpdateInfo.mClearAll = true;
3754 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3755 mImpl->mRecalculateNaturalSize = true;
3757 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3762 UPDATE_LAYOUT_SIZE |
3767 void Controller::ClearStyleData()
3769 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3770 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3773 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3775 // Reset the cursor position
3776 if( NULL != mImpl->mEventData )
3778 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3780 // Update the cursor if it's in editing mode.
3781 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3783 mImpl->mEventData->mUpdateCursorPosition = true;
3788 void Controller::ResetScrollPosition()
3790 if( NULL != mImpl->mEventData )
3792 // Reset the scroll position.
3793 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3794 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3798 void Controller::SetControlInterface( ControlInterface* controlInterface )
3800 mImpl->mControlInterface = controlInterface;
3803 bool Controller::ShouldClearFocusOnEscape() const
3805 return mImpl->mShouldClearFocusOnEscape;
3808 // private : Private contructors & copy operator.
3810 Controller::Controller()
3813 mImpl = new Controller::Impl( NULL, NULL );
3816 Controller::Controller( ControlInterface* controlInterface )
3818 mImpl = new Controller::Impl( controlInterface, NULL );
3821 Controller::Controller( ControlInterface* controlInterface,
3822 EditableControlInterface* editableControlInterface )
3824 mImpl = new Controller::Impl( controlInterface,
3825 editableControlInterface );
3828 // The copy constructor and operator are left unimplemented.
3830 // protected : Destructor.
3832 Controller::~Controller()
3839 } // namespace Toolkit