2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
30 #include <dali-toolkit/internal/text/bidirectional-support.h>
31 #include <dali-toolkit/internal/text/character-set-conversion.h>
32 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
33 #include <dali-toolkit/internal/text/markup-processor.h>
34 #include <dali-toolkit/internal/text/multi-language-support.h>
35 #include <dali-toolkit/internal/text/text-controller-impl.h>
36 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
37 #include <dali-toolkit/internal/text/text-font-style.h>
42 #if defined(DEBUG_ENABLED)
43 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
46 const float MAX_FLOAT = std::numeric_limits<float>::max();
48 const std::string EMPTY_STRING("");
50 const char * const PLACEHOLDER_TEXT = "placeholderText";
51 const char * const PLACEHOLDER_TEXT_FOCUSED = "placeholderTextFocused";
52 const char * const PLACEHOLDER_COLOR = "placeholderColor";
53 const char * const PLACEHOLDER_FONT_FAMILY = "placeholderFontFamily";
54 const char * const PLACEHOLDER_FONT_STYLE = "placeholderFontStyle";
55 const char * const PLACEHOLDER_POINT_SIZE = "placeholderPointSize";
56 const char * const PLACEHOLDER_PIXEL_SIZE = "placeholderPixelSize";
57 const char * const PLACEHOLDER_ELLIPSIS = "placeholderEllipsis";
59 float ConvertToEven( float value )
61 int intValue(static_cast<int>( value ));
62 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
77 * @brief Adds a new font description run for the selected text.
79 * The new font parameters are added after the call to this method.
81 * @param[in] eventData The event data pointer.
82 * @param[in] logicalModel The logical model where to add the new font description run.
83 * @param[out] startOfSelectedText Index to the first selected character.
84 * @param[out] lengthOfSelectedText Number of selected characters.
86 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
87 LogicalModelPtr logicalModel,
88 CharacterIndex& startOfSelectedText,
89 Length& lengthOfSelectedText )
91 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
93 // Get start and end position of selection
94 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
95 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
98 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
99 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
101 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
103 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
104 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
106 // Recalculate the selection highlight as the metrics may have changed.
107 eventData->mUpdateLeftSelectionPosition = true;
108 eventData->mUpdateRightSelectionPosition = true;
109 eventData->mUpdateHighlightBox = true;
111 return fontDescriptionRun;
114 // public : Constructor.
116 ControllerPtr Controller::New()
118 return ControllerPtr( new Controller() );
121 ControllerPtr Controller::New( ControlInterface* controlInterface )
123 return ControllerPtr( new Controller( controlInterface ) );
126 ControllerPtr Controller::New( ControlInterface* controlInterface,
127 EditableControlInterface* editableControlInterface )
129 return ControllerPtr( new Controller( controlInterface,
130 editableControlInterface ) );
133 // public : Configure the text controller.
135 void Controller::EnableTextInput( DecoratorPtr decorator )
139 delete mImpl->mEventData;
140 mImpl->mEventData = NULL;
142 // Nothing else to do.
146 if( NULL == mImpl->mEventData )
148 mImpl->mEventData = new EventData( decorator );
152 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
154 // Metrics for bitmap & vector based glyphs are different
155 mImpl->mMetrics->SetGlyphType( glyphType );
157 // Clear the font-specific data
160 mImpl->RequestRelayout();
163 void Controller::SetMarkupProcessorEnabled( bool enable )
165 mImpl->mMarkupProcessorEnabled = enable;
168 bool Controller::IsMarkupProcessorEnabled() const
170 return mImpl->mMarkupProcessorEnabled;
173 void Controller::SetAutoScrollEnabled( bool enable )
175 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 );
177 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
181 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
182 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
192 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
193 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
200 mImpl->mIsAutoScrollEnabled = enable;
201 mImpl->RequestRelayout();
205 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
206 mImpl->mIsAutoScrollEnabled = false;
210 bool Controller::IsAutoScrollEnabled() const
212 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
214 return mImpl->mIsAutoScrollEnabled;
217 CharacterDirection Controller::GetAutoScrollDirection() const
219 return mImpl->mAutoScrollDirectionRTL;
222 float Controller::GetAutoScrollLineAlignment() const
226 if( mImpl->mModel->mVisualModel &&
227 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
229 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
235 void Controller::SetHorizontalScrollEnabled( bool enable )
237 if( ( NULL != mImpl->mEventData ) &&
238 mImpl->mEventData->mDecorator )
240 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
243 bool Controller::IsHorizontalScrollEnabled() const
245 if( ( NULL != mImpl->mEventData ) &&
246 mImpl->mEventData->mDecorator )
248 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
254 void Controller::SetVerticalScrollEnabled( bool enable )
256 if( ( NULL != mImpl->mEventData ) &&
257 mImpl->mEventData->mDecorator )
259 if( mImpl->mEventData->mDecorator )
261 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
266 bool Controller::IsVerticalScrollEnabled() const
268 if( ( NULL != mImpl->mEventData ) &&
269 mImpl->mEventData->mDecorator )
271 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
277 void Controller::SetSmoothHandlePanEnabled( bool enable )
279 if( ( NULL != mImpl->mEventData ) &&
280 mImpl->mEventData->mDecorator )
282 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
286 bool Controller::IsSmoothHandlePanEnabled() const
288 if( ( NULL != mImpl->mEventData ) &&
289 mImpl->mEventData->mDecorator )
291 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
297 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
299 mImpl->mMaximumNumberOfCharacters = maxCharacters;
302 int Controller::GetMaximumNumberOfCharacters()
304 return mImpl->mMaximumNumberOfCharacters;
307 void Controller::SetEnableCursorBlink( bool enable )
309 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
311 if( NULL != mImpl->mEventData )
313 mImpl->mEventData->mCursorBlinkEnabled = enable;
316 mImpl->mEventData->mDecorator )
318 mImpl->mEventData->mDecorator->StopCursorBlink();
323 bool Controller::GetEnableCursorBlink() const
325 if( NULL != mImpl->mEventData )
327 return mImpl->mEventData->mCursorBlinkEnabled;
333 void Controller::SetMultiLineEnabled( bool enable )
335 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
337 if( layout != mImpl->mLayoutEngine.GetLayout() )
339 // Set the layout type.
340 mImpl->mLayoutEngine.SetLayout( layout );
342 // Set the flags to redo the layout operations
343 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
348 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
350 mImpl->RequestRelayout();
354 bool Controller::IsMultiLineEnabled() const
356 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
359 void Controller::SetHorizontalAlignment( Layout::HorizontalAlignment alignment )
361 if( alignment != mImpl->mModel->mHorizontalAlignment )
363 // Set the alignment.
364 mImpl->mModel->mHorizontalAlignment = alignment;
366 // Set the flag to redo the alignment operation.
367 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
369 mImpl->RequestRelayout();
373 Layout::HorizontalAlignment Controller::GetHorizontalAlignment() const
375 return mImpl->mModel->mHorizontalAlignment;
378 void Controller::SetVerticalAlignment( Layout::VerticalAlignment alignment )
380 if( alignment != mImpl->mModel->mVerticalAlignment )
382 // Set the alignment.
383 mImpl->mModel->mVerticalAlignment = alignment;
385 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
387 mImpl->RequestRelayout();
391 Layout::VerticalAlignment Controller::GetVerticalAlignment() const
393 return mImpl->mModel->mVerticalAlignment;
396 void Controller::SetLineWrapMode( Layout::LineWrap::Mode lineWrapMode )
398 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
400 // Set the text wrap mode.
401 mImpl->mModel->mLineWrapMode = lineWrapMode;
404 // Update Text layout for applying wrap mode
405 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
410 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
411 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
412 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
415 mImpl->RequestRelayout();
419 Layout::LineWrap::Mode Controller::GetLineWrapMode() const
421 return mImpl->mModel->mLineWrapMode;
424 void Controller::SetTextElideEnabled( bool enabled )
426 mImpl->mModel->mElideEnabled = enabled;
429 bool Controller::IsTextElideEnabled() const
431 return mImpl->mModel->mElideEnabled;
434 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
436 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
437 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
439 // Update placeholder if there is no text
440 if( mImpl->IsShowingPlaceholderText() ||
441 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
443 ShowPlaceholderText();
447 bool Controller::IsPlaceholderTextElideEnabled() const
449 return mImpl->mEventData->mIsPlaceholderElideEnabled;
452 void Controller::SetSelectionEnabled( bool enabled )
454 mImpl->mEventData->mSelectionEnabled = enabled;
457 bool Controller::IsSelectionEnabled() const
459 return mImpl->mEventData->mSelectionEnabled;
464 void Controller::SetText( const std::string& text )
466 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
468 // Reset keyboard as text changed
469 mImpl->ResetImfManager();
471 // Remove the previously set text and style.
477 CharacterIndex lastCursorIndex = 0u;
479 if( NULL != mImpl->mEventData )
481 // If popup shown then hide it by switching to Editing state
482 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
483 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
484 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
485 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
487 mImpl->ChangeState( EventData::EDITING );
493 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
495 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
496 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
498 Length textSize = 0u;
499 const uint8_t* utf8 = NULL;
500 if( mImpl->mMarkupProcessorEnabled )
502 ProcessMarkupString( text, markupProcessData );
503 textSize = markupProcessData.markupProcessedText.size();
505 // This is a bit horrible but std::string returns a (signed) char*
506 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
510 textSize = text.size();
512 // This is a bit horrible but std::string returns a (signed) char*
513 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
516 // Convert text into UTF-32
517 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
518 utf32Characters.Resize( textSize );
520 // Transform a text array encoded in utf8 into an array encoded in utf32.
521 // It returns the actual number of characters.
522 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
523 utf32Characters.Resize( characterCount );
525 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
526 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
528 // The characters to be added.
529 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
531 // To reset the cursor position
532 lastCursorIndex = characterCount;
534 // Update the rest of the model during size negotiation
535 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
537 // The natural size needs to be re-calculated.
538 mImpl->mRecalculateNaturalSize = true;
540 // Apply modifications to the model
541 mImpl->mOperationsPending = ALL_OPERATIONS;
545 ShowPlaceholderText();
548 // Resets the cursor position.
549 ResetCursorPosition( lastCursorIndex );
551 // Scrolls the text to make the cursor visible.
552 ResetScrollPosition();
554 mImpl->RequestRelayout();
556 if( NULL != mImpl->mEventData )
558 // Cancel previously queued events
559 mImpl->mEventData->mEventQueue.clear();
562 // Do this last since it provides callbacks into application code.
563 if( NULL != mImpl->mEditableControlInterface )
565 mImpl->mEditableControlInterface->TextChanged();
569 void Controller::GetText( std::string& text ) const
571 if( !mImpl->IsShowingPlaceholderText() )
573 // Retrieves the text string.
574 mImpl->GetText( 0u, text );
578 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
582 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
584 if( NULL != mImpl->mEventData )
586 if( PLACEHOLDER_TYPE_INACTIVE == type )
588 mImpl->mEventData->mPlaceholderTextInactive = text;
592 mImpl->mEventData->mPlaceholderTextActive = text;
595 // Update placeholder if there is no text
596 if( mImpl->IsShowingPlaceholderText() ||
597 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
599 ShowPlaceholderText();
604 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
606 if( NULL != mImpl->mEventData )
608 if( PLACEHOLDER_TYPE_INACTIVE == type )
610 text = mImpl->mEventData->mPlaceholderTextInactive;
614 text = mImpl->mEventData->mPlaceholderTextActive;
619 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
621 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
623 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
625 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
626 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
630 mImpl->RequestRelayout();
634 // public : Default style & Input style
636 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
638 if( NULL == mImpl->mFontDefaults )
640 mImpl->mFontDefaults = new FontDefaults();
643 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
644 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
645 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
647 // Clear the font-specific data
650 mImpl->RequestRelayout();
653 const std::string& Controller::GetDefaultFontFamily() const
655 if( NULL != mImpl->mFontDefaults )
657 return mImpl->mFontDefaults->mFontDescription.family;
663 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
665 if( NULL != mImpl->mEventData )
667 if( NULL == mImpl->mEventData->mPlaceholderFont )
669 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
672 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
673 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
674 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
676 mImpl->RequestRelayout();
680 const std::string& Controller::GetPlaceholderFontFamily() const
682 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
684 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
690 void Controller::SetDefaultFontWeight( FontWeight weight )
692 if( NULL == mImpl->mFontDefaults )
694 mImpl->mFontDefaults = new FontDefaults();
697 mImpl->mFontDefaults->mFontDescription.weight = weight;
698 mImpl->mFontDefaults->weightDefined = true;
700 // Clear the font-specific data
703 mImpl->RequestRelayout();
706 bool Controller::IsDefaultFontWeightDefined() const
708 if( NULL != mImpl->mFontDefaults )
710 return mImpl->mFontDefaults->weightDefined;
716 FontWeight Controller::GetDefaultFontWeight() const
718 if( NULL != mImpl->mFontDefaults )
720 return mImpl->mFontDefaults->mFontDescription.weight;
723 return TextAbstraction::FontWeight::NORMAL;
726 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
728 if( NULL != mImpl->mEventData )
730 if( NULL == mImpl->mEventData->mPlaceholderFont )
732 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
735 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
736 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
738 mImpl->RequestRelayout();
742 bool Controller::IsPlaceholderTextFontWeightDefined() const
744 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
746 return mImpl->mEventData->mPlaceholderFont->weightDefined;
751 FontWeight Controller::GetPlaceholderTextFontWeight() const
753 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
755 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
758 return TextAbstraction::FontWeight::NORMAL;
761 void Controller::SetDefaultFontWidth( FontWidth width )
763 if( NULL == mImpl->mFontDefaults )
765 mImpl->mFontDefaults = new FontDefaults();
768 mImpl->mFontDefaults->mFontDescription.width = width;
769 mImpl->mFontDefaults->widthDefined = true;
771 // Clear the font-specific data
774 mImpl->RequestRelayout();
777 bool Controller::IsDefaultFontWidthDefined() const
779 if( NULL != mImpl->mFontDefaults )
781 return mImpl->mFontDefaults->widthDefined;
787 FontWidth Controller::GetDefaultFontWidth() const
789 if( NULL != mImpl->mFontDefaults )
791 return mImpl->mFontDefaults->mFontDescription.width;
794 return TextAbstraction::FontWidth::NORMAL;
797 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
799 if( NULL != mImpl->mEventData )
801 if( NULL == mImpl->mEventData->mPlaceholderFont )
803 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
806 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
807 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
809 mImpl->RequestRelayout();
813 bool Controller::IsPlaceholderTextFontWidthDefined() const
815 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
817 return mImpl->mEventData->mPlaceholderFont->widthDefined;
822 FontWidth Controller::GetPlaceholderTextFontWidth() const
824 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
826 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
829 return TextAbstraction::FontWidth::NORMAL;
832 void Controller::SetDefaultFontSlant( FontSlant slant )
834 if( NULL == mImpl->mFontDefaults )
836 mImpl->mFontDefaults = new FontDefaults();
839 mImpl->mFontDefaults->mFontDescription.slant = slant;
840 mImpl->mFontDefaults->slantDefined = true;
842 // Clear the font-specific data
845 mImpl->RequestRelayout();
848 bool Controller::IsDefaultFontSlantDefined() const
850 if( NULL != mImpl->mFontDefaults )
852 return mImpl->mFontDefaults->slantDefined;
857 FontSlant Controller::GetDefaultFontSlant() const
859 if( NULL != mImpl->mFontDefaults )
861 return mImpl->mFontDefaults->mFontDescription.slant;
864 return TextAbstraction::FontSlant::NORMAL;
867 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
869 if( NULL != mImpl->mEventData )
871 if( NULL == mImpl->mEventData->mPlaceholderFont )
873 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
876 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
877 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
879 mImpl->RequestRelayout();
883 bool Controller::IsPlaceholderTextFontSlantDefined() const
885 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
887 return mImpl->mEventData->mPlaceholderFont->slantDefined;
892 FontSlant Controller::GetPlaceholderTextFontSlant() const
894 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
896 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
899 return TextAbstraction::FontSlant::NORMAL;
902 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
904 if( NULL == mImpl->mFontDefaults )
906 mImpl->mFontDefaults = new FontDefaults();
913 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
914 mImpl->mFontDefaults->sizeDefined = true;
919 // Point size = Pixel size * 72.f / DPI
920 unsigned int horizontalDpi = 0u;
921 unsigned int verticalDpi = 0u;
922 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
923 fontClient.GetDpi( horizontalDpi, verticalDpi );
925 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
926 mImpl->mFontDefaults->sizeDefined = true;
931 // Clear the font-specific data
934 mImpl->RequestRelayout();
937 float Controller::GetDefaultFontSize( FontSizeType type ) const
940 if( NULL != mImpl->mFontDefaults )
946 value = mImpl->mFontDefaults->mDefaultPointSize;
951 // Pixel size = Point size * DPI / 72.f
952 unsigned int horizontalDpi = 0u;
953 unsigned int verticalDpi = 0u;
954 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
955 fontClient.GetDpi( horizontalDpi, verticalDpi );
957 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
967 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
969 if( NULL != mImpl->mEventData )
971 if( NULL == mImpl->mEventData->mPlaceholderFont )
973 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
980 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
981 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
982 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
987 // Point size = Pixel size * 72.f / DPI
988 unsigned int horizontalDpi = 0u;
989 unsigned int verticalDpi = 0u;
990 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
991 fontClient.GetDpi( horizontalDpi, verticalDpi );
993 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
994 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
995 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1000 mImpl->RequestRelayout();
1004 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1007 if( NULL != mImpl->mEventData )
1013 if( NULL != mImpl->mEventData->mPlaceholderFont )
1015 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1019 // If the placeholder text font size is not set, then return the default font size.
1020 value = GetDefaultFontSize( POINT_SIZE );
1026 if( NULL != mImpl->mEventData->mPlaceholderFont )
1028 // Pixel size = Point size * DPI / 72.f
1029 unsigned int horizontalDpi = 0u;
1030 unsigned int verticalDpi = 0u;
1031 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1032 fontClient.GetDpi( horizontalDpi, verticalDpi );
1034 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1038 // If the placeholder text font size is not set, then return the default font size.
1039 value = GetDefaultFontSize( PIXEL_SIZE );
1050 void Controller::SetDefaultColor( const Vector4& color )
1052 mImpl->mTextColor = color;
1054 if( !mImpl->IsShowingPlaceholderText() )
1056 mImpl->mModel->mVisualModel->SetTextColor( color );
1058 mImpl->RequestRelayout();
1062 const Vector4& Controller::GetDefaultColor() const
1064 return mImpl->mTextColor;
1067 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1069 if( NULL != mImpl->mEventData )
1071 mImpl->mEventData->mPlaceholderTextColor = textColor;
1074 if( mImpl->IsShowingPlaceholderText() )
1076 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1077 mImpl->RequestRelayout();
1081 const Vector4& Controller::GetPlaceholderTextColor() const
1083 if( NULL != mImpl->mEventData )
1085 return mImpl->mEventData->mPlaceholderTextColor;
1088 return Color::BLACK;
1091 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1093 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1095 mImpl->RequestRelayout();
1098 const Vector2& Controller::GetShadowOffset() const
1100 return mImpl->mModel->mVisualModel->GetShadowOffset();
1103 void Controller::SetShadowColor( const Vector4& shadowColor )
1105 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1107 mImpl->RequestRelayout();
1110 const Vector4& Controller::GetShadowColor() const
1112 return mImpl->mModel->mVisualModel->GetShadowColor();
1115 void Controller::SetUnderlineColor( const Vector4& color )
1117 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1119 mImpl->RequestRelayout();
1122 const Vector4& Controller::GetUnderlineColor() const
1124 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1127 void Controller::SetUnderlineEnabled( bool enabled )
1129 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1131 mImpl->RequestRelayout();
1134 bool Controller::IsUnderlineEnabled() const
1136 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1139 void Controller::SetUnderlineHeight( float height )
1141 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1143 mImpl->RequestRelayout();
1146 float Controller::GetUnderlineHeight() const
1148 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1151 void Controller::SetOutlineColor( const Vector4& color )
1153 mImpl->mModel->mVisualModel->SetOutlineColor( color );
1155 mImpl->RequestRelayout();
1158 const Vector4& Controller::GetOutlineColor() const
1160 return mImpl->mModel->mVisualModel->GetOutlineColor();
1163 void Controller::SetOutlineWidth( float width )
1165 mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1167 mImpl->RequestRelayout();
1170 float Controller::GetOutlineWidth() const
1172 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1175 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1177 if( NULL == mImpl->mEmbossDefaults )
1179 mImpl->mEmbossDefaults = new EmbossDefaults();
1182 mImpl->mEmbossDefaults->properties = embossProperties;
1185 const std::string& Controller::GetDefaultEmbossProperties() const
1187 if( NULL != mImpl->mEmbossDefaults )
1189 return mImpl->mEmbossDefaults->properties;
1192 return EMPTY_STRING;
1195 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1197 if( NULL == mImpl->mOutlineDefaults )
1199 mImpl->mOutlineDefaults = new OutlineDefaults();
1202 mImpl->mOutlineDefaults->properties = outlineProperties;
1205 const std::string& Controller::GetDefaultOutlineProperties() const
1207 if( NULL != mImpl->mOutlineDefaults )
1209 return mImpl->mOutlineDefaults->properties;
1212 return EMPTY_STRING;
1215 void Controller::SetDefaultLineSpacing( float lineSpacing )
1217 //TODO finish implementation
1218 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1221 float Controller::GetDefaultLineSpacing() const
1223 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1226 void Controller::SetInputColor( const Vector4& color )
1228 if( NULL != mImpl->mEventData )
1230 mImpl->mEventData->mInputStyle.textColor = color;
1231 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1233 if( EventData::SELECTING == mImpl->mEventData->mState )
1235 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1237 // Get start and end position of selection
1238 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1239 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1241 // Add the color run.
1242 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1243 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1245 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1246 colorRun.color = color;
1247 colorRun.characterRun.characterIndex = startOfSelectedText;
1248 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1250 // Request to relayout.
1251 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1252 mImpl->RequestRelayout();
1254 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1255 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1256 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1261 const Vector4& Controller::GetInputColor() const
1263 if( NULL != mImpl->mEventData )
1265 return mImpl->mEventData->mInputStyle.textColor;
1268 // Return the default text's color if there is no EventData.
1269 return mImpl->mTextColor;
1273 void Controller::SetInputFontFamily( const std::string& fontFamily )
1275 if( NULL != mImpl->mEventData )
1277 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1278 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1280 if( EventData::SELECTING == mImpl->mEventData->mState )
1282 CharacterIndex startOfSelectedText = 0u;
1283 Length lengthOfSelectedText = 0u;
1284 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1285 mImpl->mModel->mLogicalModel,
1286 startOfSelectedText,
1287 lengthOfSelectedText );
1289 fontDescriptionRun.familyLength = fontFamily.size();
1290 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1291 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1292 fontDescriptionRun.familyDefined = true;
1294 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1296 // Request to relayout.
1297 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1302 UPDATE_LAYOUT_SIZE |
1305 mImpl->mRecalculateNaturalSize = true;
1306 mImpl->RequestRelayout();
1308 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1309 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1310 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1312 // As the font changes, recalculate the handle positions is needed.
1313 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1314 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1315 mImpl->mEventData->mUpdateHighlightBox = true;
1316 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1321 const std::string& Controller::GetInputFontFamily() const
1323 if( NULL != mImpl->mEventData )
1325 return mImpl->mEventData->mInputStyle.familyName;
1328 // Return the default font's family if there is no EventData.
1329 return GetDefaultFontFamily();
1332 void Controller::SetInputFontWeight( FontWeight weight )
1334 if( NULL != mImpl->mEventData )
1336 mImpl->mEventData->mInputStyle.weight = weight;
1337 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1339 if( EventData::SELECTING == mImpl->mEventData->mState )
1341 CharacterIndex startOfSelectedText = 0u;
1342 Length lengthOfSelectedText = 0u;
1343 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1344 mImpl->mModel->mLogicalModel,
1345 startOfSelectedText,
1346 lengthOfSelectedText );
1348 fontDescriptionRun.weight = weight;
1349 fontDescriptionRun.weightDefined = true;
1351 // Request to relayout.
1352 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1357 UPDATE_LAYOUT_SIZE |
1360 mImpl->mRecalculateNaturalSize = true;
1361 mImpl->RequestRelayout();
1363 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1364 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1365 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1367 // As the font might change, recalculate the handle positions is needed.
1368 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1369 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1370 mImpl->mEventData->mUpdateHighlightBox = true;
1371 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1376 bool Controller::IsInputFontWeightDefined() const
1378 bool defined = false;
1380 if( NULL != mImpl->mEventData )
1382 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1388 FontWeight Controller::GetInputFontWeight() const
1390 if( NULL != mImpl->mEventData )
1392 return mImpl->mEventData->mInputStyle.weight;
1395 return GetDefaultFontWeight();
1398 void Controller::SetInputFontWidth( FontWidth width )
1400 if( NULL != mImpl->mEventData )
1402 mImpl->mEventData->mInputStyle.width = width;
1403 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1405 if( EventData::SELECTING == mImpl->mEventData->mState )
1407 CharacterIndex startOfSelectedText = 0u;
1408 Length lengthOfSelectedText = 0u;
1409 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1410 mImpl->mModel->mLogicalModel,
1411 startOfSelectedText,
1412 lengthOfSelectedText );
1414 fontDescriptionRun.width = width;
1415 fontDescriptionRun.widthDefined = true;
1417 // Request to relayout.
1418 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1423 UPDATE_LAYOUT_SIZE |
1426 mImpl->mRecalculateNaturalSize = true;
1427 mImpl->RequestRelayout();
1429 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1430 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1431 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1433 // As the font might change, recalculate the handle positions is needed.
1434 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1435 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1436 mImpl->mEventData->mUpdateHighlightBox = true;
1437 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1442 bool Controller::IsInputFontWidthDefined() const
1444 bool defined = false;
1446 if( NULL != mImpl->mEventData )
1448 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1454 FontWidth Controller::GetInputFontWidth() const
1456 if( NULL != mImpl->mEventData )
1458 return mImpl->mEventData->mInputStyle.width;
1461 return GetDefaultFontWidth();
1464 void Controller::SetInputFontSlant( FontSlant slant )
1466 if( NULL != mImpl->mEventData )
1468 mImpl->mEventData->mInputStyle.slant = slant;
1469 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1471 if( EventData::SELECTING == mImpl->mEventData->mState )
1473 CharacterIndex startOfSelectedText = 0u;
1474 Length lengthOfSelectedText = 0u;
1475 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1476 mImpl->mModel->mLogicalModel,
1477 startOfSelectedText,
1478 lengthOfSelectedText );
1480 fontDescriptionRun.slant = slant;
1481 fontDescriptionRun.slantDefined = true;
1483 // Request to relayout.
1484 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1489 UPDATE_LAYOUT_SIZE |
1492 mImpl->mRecalculateNaturalSize = true;
1493 mImpl->RequestRelayout();
1495 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1496 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1497 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1499 // As the font might change, recalculate the handle positions is needed.
1500 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1501 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1502 mImpl->mEventData->mUpdateHighlightBox = true;
1503 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1508 bool Controller::IsInputFontSlantDefined() const
1510 bool defined = false;
1512 if( NULL != mImpl->mEventData )
1514 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1520 FontSlant Controller::GetInputFontSlant() const
1522 if( NULL != mImpl->mEventData )
1524 return mImpl->mEventData->mInputStyle.slant;
1527 return GetDefaultFontSlant();
1530 void Controller::SetInputFontPointSize( float size )
1532 if( NULL != mImpl->mEventData )
1534 mImpl->mEventData->mInputStyle.size = size;
1535 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1537 if( EventData::SELECTING == mImpl->mEventData->mState )
1539 CharacterIndex startOfSelectedText = 0u;
1540 Length lengthOfSelectedText = 0u;
1541 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1542 mImpl->mModel->mLogicalModel,
1543 startOfSelectedText,
1544 lengthOfSelectedText );
1546 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1547 fontDescriptionRun.sizeDefined = true;
1549 // Request to relayout.
1550 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1555 UPDATE_LAYOUT_SIZE |
1558 mImpl->mRecalculateNaturalSize = true;
1559 mImpl->RequestRelayout();
1561 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1562 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1563 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1565 // As the font might change, recalculate the handle positions is needed.
1566 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1567 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1568 mImpl->mEventData->mUpdateHighlightBox = true;
1569 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1574 float Controller::GetInputFontPointSize() const
1576 if( NULL != mImpl->mEventData )
1578 return mImpl->mEventData->mInputStyle.size;
1581 // Return the default font's point size if there is no EventData.
1582 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1585 void Controller::SetInputLineSpacing( float lineSpacing )
1587 if( NULL != mImpl->mEventData )
1589 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1590 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1594 float Controller::GetInputLineSpacing() const
1596 if( NULL != mImpl->mEventData )
1598 return mImpl->mEventData->mInputStyle.lineSpacing;
1604 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1606 if( NULL != mImpl->mEventData )
1608 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1612 const std::string& Controller::GetInputShadowProperties() const
1614 if( NULL != mImpl->mEventData )
1616 return mImpl->mEventData->mInputStyle.shadowProperties;
1619 return EMPTY_STRING;
1622 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1624 if( NULL != mImpl->mEventData )
1626 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1630 const std::string& Controller::GetInputUnderlineProperties() const
1632 if( NULL != mImpl->mEventData )
1634 return mImpl->mEventData->mInputStyle.underlineProperties;
1637 return EMPTY_STRING;
1640 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1642 if( NULL != mImpl->mEventData )
1644 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1648 const std::string& Controller::GetInputEmbossProperties() const
1650 if( NULL != mImpl->mEventData )
1652 return mImpl->mEventData->mInputStyle.embossProperties;
1655 return GetDefaultEmbossProperties();
1658 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1660 if( NULL != mImpl->mEventData )
1662 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1666 const std::string& Controller::GetInputOutlineProperties() const
1668 if( NULL != mImpl->mEventData )
1670 return mImpl->mEventData->mInputStyle.outlineProperties;
1673 return GetDefaultOutlineProperties();
1676 void Controller::SetInputModePassword( bool passwordInput )
1678 if( NULL != mImpl->mEventData )
1680 mImpl->mEventData->mPasswordInput = passwordInput;
1684 bool Controller::IsInputModePassword()
1686 if( NULL != mImpl->mEventData )
1688 return mImpl->mEventData->mPasswordInput;
1693 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1695 if( NULL != mImpl->mEventData )
1697 mImpl->mEventData->mDoubleTapAction = action;
1701 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1703 NoTextTap::Action action = NoTextTap::NO_ACTION;
1705 if( NULL != mImpl->mEventData )
1707 action = mImpl->mEventData->mDoubleTapAction;
1713 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1715 if( NULL != mImpl->mEventData )
1717 mImpl->mEventData->mLongPressAction = action;
1721 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1723 NoTextTap::Action action = NoTextTap::NO_ACTION;
1725 if( NULL != mImpl->mEventData )
1727 action = mImpl->mEventData->mLongPressAction;
1733 bool Controller::IsUnderlineSetByString()
1735 return mImpl->mUnderlineSetByString;
1738 void Controller::UnderlineSetByString( bool setByString )
1740 mImpl->mUnderlineSetByString = setByString;
1743 bool Controller::IsShadowSetByString()
1745 return mImpl->mShadowSetByString;
1748 void Controller::ShadowSetByString( bool setByString )
1750 mImpl->mShadowSetByString = setByString;
1753 bool Controller::IsOutlineSetByString()
1755 return mImpl->mOutlineSetByString;
1758 void Controller::OutlineSetByString( bool setByString )
1760 mImpl->mOutlineSetByString = setByString;
1763 bool Controller::IsFontStyleSetByString()
1765 return mImpl->mFontStyleSetByString;
1768 void Controller::FontStyleSetByString( bool setByString )
1770 mImpl->mFontStyleSetByString = setByString;
1773 // public : Queries & retrieves.
1775 Layout::Engine& Controller::GetLayoutEngine()
1777 return mImpl->mLayoutEngine;
1780 View& Controller::GetView()
1782 return mImpl->mView;
1785 Vector3 Controller::GetNaturalSize()
1787 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1788 Vector3 naturalSize;
1790 // Make sure the model is up-to-date before layouting
1791 ProcessModifyEvents();
1793 if( mImpl->mRecalculateNaturalSize )
1795 // Operations that can be done only once until the text changes.
1796 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1803 GET_GLYPH_METRICS );
1805 // Set the update info to relayout the whole text.
1806 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1807 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1809 // Make sure the model is up-to-date before layouting
1810 mImpl->UpdateModel( onlyOnceOperations );
1812 // Layout the text for the new width.
1813 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1815 // Store the actual control's size to restore later.
1816 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1818 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1819 static_cast<OperationsMask>( onlyOnceOperations |
1821 naturalSize.GetVectorXY() );
1823 // Do not do again the only once operations.
1824 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1826 // Do the size related operations again.
1827 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1830 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1832 // Stores the natural size to avoid recalculate it again
1833 // unless the text/style changes.
1834 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1836 mImpl->mRecalculateNaturalSize = false;
1838 // Clear the update info. This info will be set the next time the text is updated.
1839 mImpl->mTextUpdateInfo.Clear();
1841 // Restore the actual control's size.
1842 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1844 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1848 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1850 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1853 naturalSize.x = ConvertToEven( naturalSize.x );
1854 naturalSize.y = ConvertToEven( naturalSize.y );
1859 float Controller::GetHeightForWidth( float width )
1861 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1862 // Make sure the model is up-to-date before layouting
1863 ProcessModifyEvents();
1866 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1867 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1868 mImpl->mTextUpdateInfo.mClearAll )
1870 // Operations that can be done only once until the text changes.
1871 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1878 GET_GLYPH_METRICS );
1880 // Set the update info to relayout the whole text.
1881 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1882 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1884 // Make sure the model is up-to-date before layouting
1885 mImpl->UpdateModel( onlyOnceOperations );
1888 // Layout the text for the new width.
1889 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1891 // Store the actual control's width.
1892 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1894 DoRelayout( Size( width, MAX_FLOAT ),
1895 static_cast<OperationsMask>( onlyOnceOperations |
1899 // Do not do again the only once operations.
1900 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1902 // Do the size related operations again.
1903 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1907 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1909 // Clear the update info. This info will be set the next time the text is updated.
1910 mImpl->mTextUpdateInfo.Clear();
1912 // Restore the actual control's width.
1913 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1915 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1919 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1920 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1923 return layoutSize.height;
1926 int Controller::GetLineCount( float width )
1928 GetHeightForWidth( width );
1929 int numberofLines = mImpl->mModel->GetNumberOfLines();
1930 return numberofLines;
1933 const ModelInterface* const Controller::GetTextModel() const
1935 return mImpl->mModel.Get();
1938 float Controller::GetScrollAmountByUserInput()
1940 float scrollAmount = 0.0f;
1942 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1944 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1945 mImpl->mEventData->mCheckScrollAmount = false;
1947 return scrollAmount;
1950 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1952 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1955 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1956 layoutHeight = layout.height;
1957 scrollPosition = mImpl->mModel->mScrollPosition.y;
1958 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1962 void Controller::SetHiddenInputOption(const Property::Map& options )
1964 if( NULL == mImpl->mHiddenInput )
1966 mImpl->mHiddenInput = new HiddenText( this );
1968 mImpl->mHiddenInput->SetProperties(options);
1971 void Controller::GetHiddenInputOption(Property::Map& options )
1973 if( NULL != mImpl->mHiddenInput )
1975 mImpl->mHiddenInput->GetProperties(options);
1979 void Controller::SetPlaceholderProperty( const Property::Map& map )
1981 const Property::Map::SizeType count = map.Count();
1983 for( Property::Map::SizeType position = 0; position < count; ++position )
1985 KeyValuePair keyValue = map.GetKeyValue( position );
1986 Property::Key& key = keyValue.first;
1987 Property::Value& value = keyValue.second;
1989 if( key == PLACEHOLDER_TEXT )
1991 std::string text = "";
1993 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
1995 else if( key == PLACEHOLDER_TEXT_FOCUSED )
1997 std::string text = "";
1999 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2001 else if( key == PLACEHOLDER_COLOR )
2004 value.Get( textColor );
2005 if( GetPlaceholderTextColor() != textColor )
2007 SetPlaceholderTextColor( textColor );
2010 else if( key == PLACEHOLDER_FONT_FAMILY )
2012 std::string fontFamily = "";
2013 value.Get( fontFamily );
2014 SetPlaceholderFontFamily( fontFamily );
2016 else if( key == PLACEHOLDER_FONT_STYLE )
2018 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2020 else if( key == PLACEHOLDER_POINT_SIZE )
2023 value.Get( pointSize );
2024 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2026 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2029 else if( key == PLACEHOLDER_PIXEL_SIZE )
2032 value.Get( pixelSize );
2033 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2035 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2038 else if( key == PLACEHOLDER_ELLIPSIS )
2041 value.Get( ellipsis );
2042 SetPlaceholderTextElideEnabled( ellipsis );
2047 void Controller::GetPlaceholderProperty( Property::Map& map )
2049 if( NULL != mImpl->mEventData )
2051 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2053 map[ PLACEHOLDER_TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2055 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2057 map[ PLACEHOLDER_TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2060 map[ PLACEHOLDER_COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2061 map[ PLACEHOLDER_FONT_FAMILY ] = GetPlaceholderFontFamily();
2063 Property::Value fontStyleMapGet;
2064 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2065 map[ PLACEHOLDER_FONT_STYLE ] = fontStyleMapGet;
2067 // Choose font size : POINT_SIZE or PIXEL_SIZE
2068 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2070 map[ PLACEHOLDER_POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2074 map[ PLACEHOLDER_PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2077 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2079 map[ PLACEHOLDER_ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2084 // public : Relayout.
2086 Controller::UpdateTextType Controller::Relayout( const Size& size )
2088 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2090 UpdateTextType updateTextType = NONE_UPDATED;
2092 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2094 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2096 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2097 updateTextType = MODEL_UPDATED;
2100 // Clear the update info. This info will be set the next time the text is updated.
2101 mImpl->mTextUpdateInfo.Clear();
2103 // Not worth to relayout if width or height is equal to zero.
2104 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2106 return updateTextType;
2109 // Whether a new size has been set.
2110 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2114 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2116 // Layout operations that need to be done if the size changes.
2117 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2120 UPDATE_LAYOUT_SIZE |
2122 // Set the update info to relayout the whole text.
2123 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2124 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2126 // Store the size used to layout the text.
2127 mImpl->mModel->mVisualModel->mControlSize = size;
2130 // Whether there are modify events.
2131 if( 0u != mImpl->mModifyEvents.Count() )
2133 // Style operations that need to be done if the text is modified.
2134 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2138 // Set the update info to elide the text.
2139 if( mImpl->mModel->mElideEnabled ||
2140 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2142 // Update Text layout for applying elided
2143 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2146 UPDATE_LAYOUT_SIZE |
2148 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2149 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2152 // Make sure the model is up-to-date before layouting.
2153 ProcessModifyEvents();
2154 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2158 updated = DoRelayout( size,
2159 mImpl->mOperationsPending,
2160 layoutSize ) || updated;
2164 updateTextType = MODEL_UPDATED;
2167 // Do not re-do any operation until something changes.
2168 mImpl->mOperationsPending = NO_OPERATION;
2169 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2171 // Whether the text control is editable
2172 const bool isEditable = NULL != mImpl->mEventData;
2174 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2176 if( newSize && isEditable )
2178 offset = mImpl->mModel->mScrollPosition;
2181 if( !isEditable || !IsMultiLineEnabled() )
2183 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2184 CalculateVerticalOffset( size );
2191 // If there is a new size, the scroll position needs to be clamped.
2192 mImpl->ClampHorizontalScroll( layoutSize );
2194 // Update the decorator's positions is needed if there is a new size.
2195 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2198 // Move the cursor, grab handle etc.
2199 if( mImpl->ProcessInputEvents() )
2201 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2205 // Clear the update info. This info will be set the next time the text is updated.
2206 mImpl->mTextUpdateInfo.Clear();
2207 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2209 return updateTextType;
2212 void Controller::RequestRelayout()
2214 mImpl->RequestRelayout();
2217 // public : Input style change signals.
2219 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2221 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2224 void Controller::ProcessInputStyleChangedSignals()
2226 if( NULL == mImpl->mEventData )
2232 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2233 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2237 const InputStyle::Mask mask = *it;
2239 if( NULL != mImpl->mEditableControlInterface )
2241 // Emit the input style changed signal.
2242 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2246 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2249 // public : Text-input Event Queuing.
2251 void Controller::KeyboardFocusGainEvent()
2253 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2255 if( NULL != mImpl->mEventData )
2257 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2258 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2260 mImpl->ChangeState( EventData::EDITING );
2261 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2262 mImpl->mEventData->mUpdateInputStyle = true;
2264 mImpl->NotifyImfMultiLineStatus();
2265 if( mImpl->IsShowingPlaceholderText() )
2267 // Show alternative placeholder-text when editing
2268 ShowPlaceholderText();
2271 mImpl->RequestRelayout();
2275 void Controller::KeyboardFocusLostEvent()
2277 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2279 if( NULL != mImpl->mEventData )
2281 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2283 mImpl->ChangeState( EventData::INACTIVE );
2285 if( !mImpl->IsShowingRealText() )
2287 // Revert to regular placeholder-text when not editing
2288 ShowPlaceholderText();
2292 mImpl->RequestRelayout();
2295 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2297 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2299 bool textChanged = false;
2300 bool relayoutNeeded = false;
2302 if( ( NULL != mImpl->mEventData ) &&
2303 ( keyEvent.state == KeyEvent::Down ) )
2305 int keyCode = keyEvent.keyCode;
2306 const std::string& keyString = keyEvent.keyPressed;
2308 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2310 // Pre-process to separate modifying events from non-modifying input events.
2313 // In some platforms arrive key events with no key code.
2317 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode )
2322 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2323 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2324 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2325 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2327 // If don't have any text, do nothing.
2328 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2333 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2334 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2335 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2336 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2338 // Logic to determine whether this text control will lose focus or not.
2339 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2340 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2341 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2342 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2343 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2344 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2349 mImpl->mEventData->mCheckScrollAmount = true;
2350 Event event( Event::CURSOR_KEY_EVENT );
2351 event.p1.mInt = keyCode;
2352 mImpl->mEventData->mEventQueue.push_back( event );
2354 // Will request for relayout.
2355 relayoutNeeded = true;
2357 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
2359 textChanged = BackspaceKeyEvent();
2361 // Will request for relayout.
2362 relayoutNeeded = true;
2364 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2365 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2366 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2368 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2369 mImpl->ChangeState( EventData::INACTIVE );
2371 // Will request for relayout.
2372 relayoutNeeded = true;
2374 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2376 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2378 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2379 // and a character is typed after the type of a upper case latin character.
2384 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2386 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2392 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2394 // IMF manager is no longer handling key-events
2395 mImpl->ClearPreEditFlag();
2397 InsertText( keyString, COMMIT );
2400 // Will request for relayout.
2401 relayoutNeeded = true;
2404 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2405 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2407 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2408 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2409 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2411 // Should not change the state if the key is the shift send by the imf manager.
2412 // Otherwise, when the state is SELECTING the text controller can't send the right
2413 // surrounding info to the imf.
2414 mImpl->ChangeState( EventData::EDITING );
2416 // Will request for relayout.
2417 relayoutNeeded = true;
2420 if( relayoutNeeded )
2422 mImpl->RequestRelayout();
2427 ( NULL != mImpl->mEditableControlInterface ) )
2429 // Do this last since it provides callbacks into application code
2430 mImpl->mEditableControlInterface->TextChanged();
2436 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2438 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2440 if( NULL != mImpl->mEventData )
2442 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2443 EventData::State state( mImpl->mEventData->mState );
2444 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2446 if( mImpl->IsClipboardVisible() )
2448 if( EventData::INACTIVE == state || EventData::EDITING == state)
2450 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2452 relayoutNeeded = true;
2454 else if( 1u == tapCount )
2456 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2458 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2461 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2463 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2464 relayoutNeeded = true;
2468 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2470 // Hide placeholder text
2474 if( EventData::INACTIVE == state )
2476 mImpl->ChangeState( EventData::EDITING );
2478 else if( !mImpl->IsClipboardEmpty() )
2480 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2482 relayoutNeeded = true;
2485 else if( 2u == tapCount )
2487 if( mImpl->mEventData->mSelectionEnabled &&
2488 mImpl->IsShowingRealText() )
2490 relayoutNeeded = true;
2491 mImpl->mEventData->mIsLeftHandleSelected = true;
2492 mImpl->mEventData->mIsRightHandleSelected = true;
2496 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2497 if( relayoutNeeded )
2499 Event event( Event::TAP_EVENT );
2500 event.p1.mUint = tapCount;
2501 event.p2.mFloat = x;
2502 event.p3.mFloat = y;
2503 mImpl->mEventData->mEventQueue.push_back( event );
2505 mImpl->RequestRelayout();
2509 // Reset keyboard as tap event has occurred.
2510 mImpl->ResetImfManager();
2513 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2515 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2517 if( NULL != mImpl->mEventData )
2519 Event event( Event::PAN_EVENT );
2520 event.p1.mInt = state;
2521 event.p2.mFloat = displacement.x;
2522 event.p3.mFloat = displacement.y;
2523 mImpl->mEventData->mEventQueue.push_back( event );
2525 mImpl->RequestRelayout();
2529 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2531 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2533 if( ( state == Gesture::Started ) &&
2534 ( NULL != mImpl->mEventData ) )
2536 // The 1st long-press on inactive text-field is treated as tap
2537 if( EventData::INACTIVE == mImpl->mEventData->mState )
2539 mImpl->ChangeState( EventData::EDITING );
2541 Event event( Event::TAP_EVENT );
2543 event.p2.mFloat = x;
2544 event.p3.mFloat = y;
2545 mImpl->mEventData->mEventQueue.push_back( event );
2547 mImpl->RequestRelayout();
2549 else if( !mImpl->IsShowingRealText() )
2551 Event event( Event::LONG_PRESS_EVENT );
2552 event.p1.mInt = state;
2553 event.p2.mFloat = x;
2554 event.p3.mFloat = y;
2555 mImpl->mEventData->mEventQueue.push_back( event );
2556 mImpl->RequestRelayout();
2558 else if( !mImpl->IsClipboardVisible() )
2560 // Reset the imf manager to commit the pre-edit before selecting the text.
2561 mImpl->ResetImfManager();
2563 Event event( Event::LONG_PRESS_EVENT );
2564 event.p1.mInt = state;
2565 event.p2.mFloat = x;
2566 event.p3.mFloat = y;
2567 mImpl->mEventData->mEventQueue.push_back( event );
2568 mImpl->RequestRelayout();
2570 mImpl->mEventData->mIsLeftHandleSelected = true;
2571 mImpl->mEventData->mIsRightHandleSelected = true;
2576 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2578 // Whether the text needs to be relaid-out.
2579 bool requestRelayout = false;
2581 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2582 bool retrieveText = false;
2583 bool retrieveCursor = false;
2585 switch( imfEvent.eventName )
2587 case ImfManager::COMMIT:
2589 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2590 requestRelayout = true;
2591 retrieveCursor = true;
2594 case ImfManager::PREEDIT:
2596 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2597 requestRelayout = true;
2598 retrieveCursor = true;
2601 case ImfManager::DELETESURROUNDING:
2603 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2604 imfEvent.numberOfChars,
2605 DONT_UPDATE_INPUT_STYLE );
2609 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2610 !mImpl->IsPlaceholderAvailable() )
2612 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2616 ShowPlaceholderText();
2618 mImpl->mEventData->mUpdateCursorPosition = true;
2619 mImpl->mEventData->mScrollAfterDelete = true;
2621 requestRelayout = true;
2625 case ImfManager::GETSURROUNDING:
2627 retrieveText = true;
2628 retrieveCursor = true;
2631 case ImfManager::PRIVATECOMMAND:
2633 // PRIVATECOMMAND event is just for getting the private command message
2634 retrieveText = true;
2635 retrieveCursor = true;
2638 case ImfManager::VOID:
2645 if( requestRelayout )
2647 mImpl->mOperationsPending = ALL_OPERATIONS;
2648 mImpl->RequestRelayout();
2652 CharacterIndex cursorPosition = 0u;
2653 Length numberOfWhiteSpaces = 0u;
2655 if( retrieveCursor )
2657 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2659 cursorPosition = mImpl->GetLogicalCursorPosition();
2661 if( cursorPosition < numberOfWhiteSpaces )
2663 cursorPosition = 0u;
2667 cursorPosition -= numberOfWhiteSpaces;
2673 mImpl->GetText( numberOfWhiteSpaces, text );
2676 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2678 if( requestRelayout &&
2679 ( NULL != mImpl->mEditableControlInterface ) )
2681 // Do this last since it provides callbacks into application code
2682 mImpl->mEditableControlInterface->TextChanged();
2685 return callbackData;
2688 void Controller::PasteClipboardItemEvent()
2690 // Retrieve the clipboard contents first
2691 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2692 std::string stringToPaste( notifier.GetContent() );
2694 // Commit the current pre-edit text; the contents of the clipboard should be appended
2695 mImpl->ResetImfManager();
2697 // Temporary disable hiding clipboard
2698 mImpl->SetClipboardHideEnable( false );
2701 PasteText( stringToPaste );
2703 mImpl->SetClipboardHideEnable( true );
2706 // protected : Inherit from Text::Decorator::ControllerInterface.
2708 void Controller::GetTargetSize( Vector2& targetSize )
2710 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2713 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2715 if( NULL != mImpl->mEditableControlInterface )
2717 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2721 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2723 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2725 if( NULL != mImpl->mEventData )
2727 switch( handleType )
2731 Event event( Event::GRAB_HANDLE_EVENT );
2732 event.p1.mUint = state;
2733 event.p2.mFloat = x;
2734 event.p3.mFloat = y;
2736 mImpl->mEventData->mEventQueue.push_back( event );
2739 case LEFT_SELECTION_HANDLE:
2741 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2742 event.p1.mUint = state;
2743 event.p2.mFloat = x;
2744 event.p3.mFloat = y;
2746 mImpl->mEventData->mEventQueue.push_back( event );
2749 case RIGHT_SELECTION_HANDLE:
2751 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2752 event.p1.mUint = state;
2753 event.p2.mFloat = x;
2754 event.p3.mFloat = y;
2756 mImpl->mEventData->mEventQueue.push_back( event );
2759 case LEFT_SELECTION_HANDLE_MARKER:
2760 case RIGHT_SELECTION_HANDLE_MARKER:
2762 // Markers do not move the handles.
2765 case HANDLE_TYPE_COUNT:
2767 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2771 mImpl->RequestRelayout();
2775 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2777 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2779 if( NULL == mImpl->mEventData )
2786 case Toolkit::TextSelectionPopup::CUT:
2788 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2789 mImpl->mOperationsPending = ALL_OPERATIONS;
2791 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2792 !mImpl->IsPlaceholderAvailable() )
2794 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2798 ShowPlaceholderText();
2801 mImpl->mEventData->mUpdateCursorPosition = true;
2802 mImpl->mEventData->mScrollAfterDelete = true;
2804 mImpl->RequestRelayout();
2806 if( NULL != mImpl->mEditableControlInterface )
2808 mImpl->mEditableControlInterface->TextChanged();
2812 case Toolkit::TextSelectionPopup::COPY:
2814 mImpl->SendSelectionToClipboard( false ); // Text not modified
2816 mImpl->mEventData->mUpdateCursorPosition = true;
2818 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2821 case Toolkit::TextSelectionPopup::PASTE:
2823 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2826 case Toolkit::TextSelectionPopup::SELECT:
2828 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2830 if( mImpl->mEventData->mSelectionEnabled )
2832 // Creates a SELECT event.
2833 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2837 case Toolkit::TextSelectionPopup::SELECT_ALL:
2839 // Creates a SELECT_ALL event
2840 SelectEvent( 0.f, 0.f, true );
2843 case Toolkit::TextSelectionPopup::CLIPBOARD:
2845 mImpl->ShowClipboard();
2848 case Toolkit::TextSelectionPopup::NONE:
2856 void Controller::DisplayTimeExpired()
2858 mImpl->mEventData->mUpdateCursorPosition = true;
2859 // Apply modifications to the model
2860 mImpl->mOperationsPending = ALL_OPERATIONS;
2862 mImpl->RequestRelayout();
2865 // private : Update.
2867 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2869 bool removedPrevious = false;
2870 bool removedSelected = false;
2871 bool maxLengthReached = false;
2873 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2875 if( NULL == mImpl->mEventData )
2880 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2881 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2882 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2884 // TODO: At the moment the underline runs are only for pre-edit.
2885 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2887 // Remove the previous IMF pre-edit.
2888 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2890 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2891 mImpl->mEventData->mPreEditLength,
2892 DONT_UPDATE_INPUT_STYLE );
2894 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2895 mImpl->mEventData->mPreEditLength = 0u;
2899 // Remove the previous Selection.
2900 removedSelected = RemoveSelectedText();
2904 Vector<Character> utf32Characters;
2905 Length characterCount = 0u;
2909 // Convert text into UTF-32
2910 utf32Characters.Resize( text.size() );
2912 // This is a bit horrible but std::string returns a (signed) char*
2913 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2915 // Transform a text array encoded in utf8 into an array encoded in utf32.
2916 // It returns the actual number of characters.
2917 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2918 utf32Characters.Resize( characterCount );
2920 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2921 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2924 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2926 // The placeholder text is no longer needed
2927 if( mImpl->IsShowingPlaceholderText() )
2932 mImpl->ChangeState( EventData::EDITING );
2934 // Handle the IMF (predicitive text) state changes
2935 if( COMMIT == type )
2937 // IMF manager is no longer handling key-events
2938 mImpl->ClearPreEditFlag();
2942 if( !mImpl->mEventData->mPreEditFlag )
2944 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2946 // Record the start of the pre-edit text
2947 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2950 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2951 mImpl->mEventData->mPreEditFlag = true;
2953 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2956 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2958 // Restrict new text to fit within Maximum characters setting.
2959 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2960 maxLengthReached = ( characterCount > maxSizeOfNewText );
2962 // The cursor position.
2963 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2965 // Update the text's style.
2967 // Updates the text style runs by adding characters.
2968 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2970 // Get the character index from the cursor index.
2971 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2973 // Retrieve the text's style for the given index.
2975 mImpl->RetrieveDefaultInputStyle( style );
2976 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2978 // Whether to add a new text color run.
2979 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2981 // Whether to add a new font run.
2982 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2983 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2984 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2985 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2986 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2991 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2992 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2994 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2995 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2996 colorRun.characterRun.characterIndex = cursorIndex;
2997 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3000 if( addFontNameRun ||
3006 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3007 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3009 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3011 if( addFontNameRun )
3013 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3014 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3015 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3016 fontDescriptionRun.familyDefined = true;
3018 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3021 if( addFontWeightRun )
3023 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3024 fontDescriptionRun.weightDefined = true;
3027 if( addFontWidthRun )
3029 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3030 fontDescriptionRun.widthDefined = true;
3033 if( addFontSlantRun )
3035 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3036 fontDescriptionRun.slantDefined = true;
3039 if( addFontSizeRun )
3041 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3042 fontDescriptionRun.sizeDefined = true;
3045 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3046 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3049 // Insert at current cursor position.
3050 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3052 if( cursorIndex < numberOfCharactersInModel )
3054 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3058 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3061 // Mark the first paragraph to be updated.
3062 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3064 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3065 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3066 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3067 mImpl->mTextUpdateInfo.mClearAll = true;
3071 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3072 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3075 // Update the cursor index.
3076 cursorIndex += maxSizeOfNewText;
3078 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 );
3081 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3082 mImpl->IsPlaceholderAvailable() )
3084 // Show place-holder if empty after removing the pre-edit text
3085 ShowPlaceholderText();
3086 mImpl->mEventData->mUpdateCursorPosition = true;
3087 mImpl->ClearPreEditFlag();
3089 else if( removedPrevious ||
3091 ( 0 != utf32Characters.Count() ) )
3093 // Queue an inserted event
3094 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3096 mImpl->mEventData->mUpdateCursorPosition = true;
3097 if( removedSelected )
3099 mImpl->mEventData->mScrollAfterDelete = true;
3103 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3107 if( maxLengthReached )
3109 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3111 mImpl->ResetImfManager();
3113 if( NULL != mImpl->mEditableControlInterface )
3115 // Do this last since it provides callbacks into application code
3116 mImpl->mEditableControlInterface->MaxLengthReached();
3121 void Controller::PasteText( const std::string& stringToPaste )
3123 InsertText( stringToPaste, Text::Controller::COMMIT );
3124 mImpl->ChangeState( EventData::EDITING );
3125 mImpl->RequestRelayout();
3127 if( NULL != mImpl->mEditableControlInterface )
3129 // Do this last since it provides callbacks into application code
3130 mImpl->mEditableControlInterface->TextChanged();
3134 bool Controller::RemoveText( int cursorOffset,
3135 int numberOfCharacters,
3136 UpdateInputStyleType type )
3138 bool removed = false;
3140 if( NULL == mImpl->mEventData )
3145 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3146 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3148 if( !mImpl->IsShowingPlaceholderText() )
3150 // Delete at current cursor position
3151 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3152 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3154 CharacterIndex cursorIndex = 0;
3156 // Validate the cursor position & number of characters
3157 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3159 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3162 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3164 numberOfCharacters = currentText.Count() - cursorIndex;
3167 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.
3168 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3170 // Mark the paragraphs to be updated.
3171 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3173 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3174 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3175 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3176 mImpl->mTextUpdateInfo.mClearAll = true;
3180 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3181 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3184 // Update the input style and remove the text's style before removing the text.
3186 if( UPDATE_INPUT_STYLE == type )
3188 // Keep a copy of the current input style.
3189 InputStyle currentInputStyle;
3190 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3192 // Set first the default input style.
3193 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3195 // Update the input style.
3196 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3198 // Compare if the input style has changed.
3199 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3201 if( hasInputStyleChanged )
3203 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3204 // Queue the input style changed signal.
3205 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3209 // Updates the text style runs by removing characters. Runs with no characters are removed.
3210 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3212 // Remove the characters.
3213 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3214 Vector<Character>::Iterator last = first + numberOfCharacters;
3216 currentText.Erase( first, last );
3218 // Cursor position retreat
3219 oldCursorIndex = cursorIndex;
3221 mImpl->mEventData->mScrollAfterDelete = true;
3223 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3231 bool Controller::RemoveSelectedText()
3233 bool textRemoved( false );
3235 if( EventData::SELECTING == mImpl->mEventData->mState )
3237 std::string removedString;
3238 mImpl->RetrieveSelection( removedString, true );
3240 if( !removedString.empty() )
3243 mImpl->ChangeState( EventData::EDITING );
3250 // private : Relayout.
3252 bool Controller::DoRelayout( const Size& size,
3253 OperationsMask operationsRequired,
3256 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3257 bool viewUpdated( false );
3259 // Calculate the operations to be done.
3260 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3262 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3263 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3265 // Get the current layout size.
3266 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3268 if( NO_OPERATION != ( LAYOUT & operations ) )
3270 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3272 // Some vectors with data needed to layout and reorder may be void
3273 // after the first time the text has been laid out.
3274 // Fill the vectors again.
3276 // Calculate the number of glyphs to layout.
3277 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3278 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3279 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3280 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3282 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3283 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3284 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3285 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3287 if( 0u == totalNumberOfGlyphs )
3289 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3291 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3294 // Nothing else to do if there is no glyphs.
3295 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3299 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3300 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3301 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3302 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3303 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3304 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3305 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3307 // Set the layout parameters.
3308 Layout::Parameters layoutParameters( size,
3310 lineBreakInfo.Begin(),
3311 wordBreakInfo.Begin(),
3312 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3314 glyphsToCharactersMap.Begin(),
3315 charactersPerGlyph.Begin(),
3316 charactersToGlyphBuffer,
3317 glyphsPerCharacterBuffer,
3318 totalNumberOfGlyphs,
3319 mImpl->mModel->mHorizontalAlignment,
3320 mImpl->mModel->mLineWrapMode );
3322 // Resize the vector of positions to have the same size than the vector of glyphs.
3323 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3324 glyphPositions.Resize( totalNumberOfGlyphs );
3326 // Whether the last character is a new paragraph character.
3327 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3328 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3330 // The initial glyph and the number of glyphs to layout.
3331 layoutParameters.startGlyphIndex = startGlyphIndex;
3332 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3333 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3334 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3336 // Update the ellipsis
3337 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3339 if( NULL != mImpl->mEventData )
3341 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3343 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3345 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3347 // Disable ellipsis when editing
3348 elideTextEnabled = false;
3351 // Reset the scroll position in inactive state
3352 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3354 ResetScrollPosition();
3358 // Update the visual model.
3360 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3362 mImpl->mModel->mVisualModel->mLines,
3366 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3370 layoutSize = newLayoutSize;
3372 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3374 mImpl->mAutoScrollDirectionRTL = false;
3377 // Reorder the lines
3378 if( NO_OPERATION != ( REORDER & operations ) )
3380 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3381 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3383 // Check first if there are paragraphs with bidirectional info.
3384 if( 0u != bidirectionalInfo.Count() )
3387 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3389 // Reorder the lines.
3390 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3391 ReorderLines( bidirectionalInfo,
3393 requestedNumberOfCharacters,
3394 mImpl->mModel->mVisualModel->mLines,
3395 bidirectionalLineInfo );
3397 // Set the bidirectional info per line into the layout parameters.
3398 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3399 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3401 // Re-layout the text. Reorder those lines with right to left characters.
3402 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3404 requestedNumberOfCharacters,
3407 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3409 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3412 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3418 // Sets the layout size.
3419 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3421 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3426 if( NO_OPERATION != ( ALIGN & operations ) )
3428 // The laid-out lines.
3429 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3431 // Need to align with the control's size as the text may contain lines
3432 // starting either with left to right text or right to left.
3433 mImpl->mLayoutEngine.Align( size,
3435 requestedNumberOfCharacters,
3436 mImpl->mModel->mHorizontalAlignment,
3438 mImpl->mModel->mAlignmentOffset );
3442 #if defined(DEBUG_ENABLED)
3443 std::string currentText;
3444 GetText( currentText );
3445 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3447 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3451 void Controller::CalculateVerticalOffset( const Size& controlSize )
3453 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3455 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3457 // Get the line height of the default font.
3458 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3461 switch( mImpl->mModel->mVerticalAlignment )
3463 case Layout::VERTICAL_ALIGN_TOP:
3465 mImpl->mModel->mScrollPosition.y = 0.f;
3468 case Layout::VERTICAL_ALIGN_CENTER:
3470 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3473 case Layout::VERTICAL_ALIGN_BOTTOM:
3475 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3481 // private : Events.
3483 void Controller::ProcessModifyEvents()
3485 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3487 if( 0u == events.Count() )
3493 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3494 endIt = events.End();
3498 const ModifyEvent& event = *it;
3500 if( ModifyEvent::TEXT_REPLACED == event.type )
3502 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3503 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3505 TextReplacedEvent();
3507 else if( ModifyEvent::TEXT_INSERTED == event.type )
3509 TextInsertedEvent();
3511 else if( ModifyEvent::TEXT_DELETED == event.type )
3513 // Placeholder-text cannot be deleted
3514 if( !mImpl->IsShowingPlaceholderText() )
3521 if( NULL != mImpl->mEventData )
3523 // When the text is being modified, delay cursor blinking
3524 mImpl->mEventData->mDecorator->DelayCursorBlink();
3527 // Discard temporary text
3531 void Controller::TextReplacedEvent()
3533 // The natural size needs to be re-calculated.
3534 mImpl->mRecalculateNaturalSize = true;
3536 // Apply modifications to the model
3537 mImpl->mOperationsPending = ALL_OPERATIONS;
3540 void Controller::TextInsertedEvent()
3542 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3544 if( NULL == mImpl->mEventData )
3549 mImpl->mEventData->mCheckScrollAmount = true;
3551 // The natural size needs to be re-calculated.
3552 mImpl->mRecalculateNaturalSize = true;
3554 // Apply modifications to the model; TODO - Optimize this
3555 mImpl->mOperationsPending = ALL_OPERATIONS;
3558 void Controller::TextDeletedEvent()
3560 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3562 if( NULL == mImpl->mEventData )
3567 mImpl->mEventData->mCheckScrollAmount = true;
3569 // The natural size needs to be re-calculated.
3570 mImpl->mRecalculateNaturalSize = true;
3572 // Apply modifications to the model; TODO - Optimize this
3573 mImpl->mOperationsPending = ALL_OPERATIONS;
3576 void Controller::SelectEvent( float x, float y, bool selectAll )
3578 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3580 if( NULL != mImpl->mEventData )
3584 Event event( Event::SELECT_ALL );
3585 mImpl->mEventData->mEventQueue.push_back( event );
3589 Event event( Event::SELECT );
3590 event.p2.mFloat = x;
3591 event.p3.mFloat = y;
3592 mImpl->mEventData->mEventQueue.push_back( event );
3595 mImpl->mEventData->mCheckScrollAmount = true;
3596 mImpl->mEventData->mIsLeftHandleSelected = true;
3597 mImpl->mEventData->mIsRightHandleSelected = true;
3598 mImpl->RequestRelayout();
3602 bool Controller::BackspaceKeyEvent()
3604 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3606 bool removed = false;
3608 if( NULL == mImpl->mEventData )
3613 // IMF manager is no longer handling key-events
3614 mImpl->ClearPreEditFlag();
3616 if( EventData::SELECTING == mImpl->mEventData->mState )
3618 removed = RemoveSelectedText();
3620 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3622 // Remove the character before the current cursor position
3623 removed = RemoveText( -1,
3625 UPDATE_INPUT_STYLE );
3630 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3631 !mImpl->IsPlaceholderAvailable() )
3633 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3637 ShowPlaceholderText();
3639 mImpl->mEventData->mUpdateCursorPosition = true;
3640 mImpl->mEventData->mScrollAfterDelete = true;
3646 // private : Helpers.
3648 void Controller::ResetText()
3651 mImpl->mModel->mLogicalModel->mText.Clear();
3653 // We have cleared everything including the placeholder-text
3654 mImpl->PlaceholderCleared();
3656 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3657 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3658 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3660 // Clear any previous text.
3661 mImpl->mTextUpdateInfo.mClearAll = true;
3663 // The natural size needs to be re-calculated.
3664 mImpl->mRecalculateNaturalSize = true;
3666 // Apply modifications to the model
3667 mImpl->mOperationsPending = ALL_OPERATIONS;
3670 void Controller::ShowPlaceholderText()
3672 if( mImpl->IsPlaceholderAvailable() )
3674 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3676 if( NULL == mImpl->mEventData )
3681 mImpl->mEventData->mIsShowingPlaceholderText = true;
3683 // Disable handles when showing place-holder text
3684 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3685 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3686 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3688 const char* text( NULL );
3691 // TODO - Switch Placeholder text when changing state
3692 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3693 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3695 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3696 size = mImpl->mEventData->mPlaceholderTextActive.size();
3700 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3701 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3704 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3705 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3707 // Reset model for showing placeholder.
3708 mImpl->mModel->mLogicalModel->mText.Clear();
3709 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3711 // Convert text into UTF-32
3712 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3713 utf32Characters.Resize( size );
3715 // This is a bit horrible but std::string returns a (signed) char*
3716 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3718 // Transform a text array encoded in utf8 into an array encoded in utf32.
3719 // It returns the actual number of characters.
3720 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3721 utf32Characters.Resize( characterCount );
3723 // The characters to be added.
3724 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3726 // Reset the cursor position
3727 mImpl->mEventData->mPrimaryCursorPosition = 0;
3729 // The natural size needs to be re-calculated.
3730 mImpl->mRecalculateNaturalSize = true;
3732 // Apply modifications to the model
3733 mImpl->mOperationsPending = ALL_OPERATIONS;
3735 // Update the rest of the model during size negotiation
3736 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3740 void Controller::ClearFontData()
3742 if( mImpl->mFontDefaults )
3744 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3747 // Set flags to update the model.
3748 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3749 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3750 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3752 mImpl->mTextUpdateInfo.mClearAll = true;
3753 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3754 mImpl->mRecalculateNaturalSize = true;
3756 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3761 UPDATE_LAYOUT_SIZE |
3766 void Controller::ClearStyleData()
3768 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3769 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3772 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3774 // Reset the cursor position
3775 if( NULL != mImpl->mEventData )
3777 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3779 // Update the cursor if it's in editing mode.
3780 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3782 mImpl->mEventData->mUpdateCursorPosition = true;
3787 void Controller::ResetScrollPosition()
3789 if( NULL != mImpl->mEventData )
3791 // Reset the scroll position.
3792 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3793 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3797 void Controller::SetControlInterface( ControlInterface* controlInterface )
3799 mImpl->mControlInterface = controlInterface;
3802 bool Controller::ShouldClearFocusOnEscape() const
3804 return mImpl->mShouldClearFocusOnEscape;
3807 // private : Private contructors & copy operator.
3809 Controller::Controller()
3812 mImpl = new Controller::Impl( NULL, NULL );
3815 Controller::Controller( ControlInterface* controlInterface )
3817 mImpl = new Controller::Impl( controlInterface, NULL );
3820 Controller::Controller( ControlInterface* controlInterface,
3821 EditableControlInterface* editableControlInterface )
3823 mImpl = new Controller::Impl( controlInterface,
3824 editableControlInterface );
3827 // The copy constructor and operator are left unimplemented.
3829 // protected : Destructor.
3831 Controller::~Controller()
3838 } // namespace Toolkit