X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller.cpp;h=83c81a38c652bd49eed532cbd6e24f7a8cc8b38f;hp=47afc968a71b5498bee9667c65a1178de6b56e1c;hb=8608d23a021ba74d1a79ee62a3fda1ef4ece09b1;hpb=2047844bb3b4a84231905c8c540d34d4c468e5ad diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 47afc96..83c81a3 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -41,6 +41,7 @@ const float MAX_FLOAT = std::numeric_limits::max(); const unsigned int POINTS_PER_INCH = 72; const std::string EMPTY_STRING(""); +const unsigned int ZERO = 0u; float ConvertToEven( float value ) { @@ -76,6 +77,9 @@ void Controller::SetText( const std::string& text ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" ); + // Reset keyboard as text changed + mImpl->ResetImfManager(); + // Remove the previously set text ResetText(); @@ -141,8 +145,8 @@ void Controller::SetText( const std::string& text ) mImpl->mEventData->mEventQueue.clear(); } - // Reset keyboard as text changed - mImpl->ResetImfManager(); + // Notify IMF as text changed + NotifyImfManager(); // Do this last since it provides callbacks into application code mImpl->mControlInterface.TextChanged(); @@ -232,8 +236,10 @@ void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily, boo mImpl->mFontDefaults = new FontDefaults(); } - mImpl->mFontDefaults->mDefaultFontFamily = defaultFontFamily; + mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily; + DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s userDefined: %s\n", defaultFontFamily.c_str(), userDefined ? "true":"false" ); mImpl->mUserDefinedFontFamily = userDefined; + // Clear the font-specific data ClearFontData(); @@ -247,20 +253,40 @@ const std::string& Controller::GetDefaultFontFamily() const { if( mImpl->mFontDefaults ) { - return mImpl->mFontDefaults->mDefaultFontFamily; + return mImpl->mFontDefaults->mFontDescription.family; + } + + return EMPTY_STRING; +} + +void Controller::SetDefaultFontStyle( const std::string& style ) +{ + if( !mImpl->mFontDefaults ) + { + mImpl->mFontDefaults = new FontDefaults(); + } + + mImpl->mFontDefaults->mFontStyle = style; +} + +const std::string& Controller::GetDefaultFontStyle() const +{ + if( mImpl->mFontDefaults ) + { + return mImpl->mFontDefaults->mFontStyle; } return EMPTY_STRING; } -void Controller::SetDefaultFontStyle( const std::string& defaultFontStyle ) +void Controller::SetDefaultFontWidth( FontWidth width ) { if( !mImpl->mFontDefaults ) { mImpl->mFontDefaults = new FontDefaults(); } - mImpl->mFontDefaults->mDefaultFontStyle = defaultFontStyle; + mImpl->mFontDefaults->mFontDescription.width = width; // Clear the font-specific data ClearFontData(); @@ -271,14 +297,70 @@ void Controller::SetDefaultFontStyle( const std::string& defaultFontStyle ) mImpl->RequestRelayout(); } -const std::string& Controller::GetDefaultFontStyle() const +FontWidth Controller::GetDefaultFontWidth() const { if( mImpl->mFontDefaults ) { - return mImpl->mFontDefaults->mDefaultFontStyle; + return mImpl->mFontDefaults->mFontDescription.width; } - return EMPTY_STRING; + return TextAbstraction::FontWidth::NORMAL; +} + +void Controller::SetDefaultFontWeight( FontWeight weight ) +{ + if( !mImpl->mFontDefaults ) + { + mImpl->mFontDefaults = new FontDefaults(); + } + + mImpl->mFontDefaults->mFontDescription.weight = weight; + + // Clear the font-specific data + ClearFontData(); + + mImpl->mOperationsPending = ALL_OPERATIONS; + mImpl->mRecalculateNaturalSize = true; + + mImpl->RequestRelayout(); +} + +FontWeight Controller::GetDefaultFontWeight() const +{ + if( mImpl->mFontDefaults ) + { + return mImpl->mFontDefaults->mFontDescription.weight; + } + + return TextAbstraction::FontWeight::NORMAL; +} + +void Controller::SetDefaultFontSlant( FontSlant slant ) +{ + if( !mImpl->mFontDefaults ) + { + mImpl->mFontDefaults = new FontDefaults(); + } + + mImpl->mFontDefaults->mFontDescription.slant = slant; + + // Clear the font-specific data + ClearFontData(); + + mImpl->mOperationsPending = ALL_OPERATIONS; + mImpl->mRecalculateNaturalSize = true; + + mImpl->RequestRelayout(); +} + +FontSlant Controller::GetDefaultFontSlant() const +{ + if( mImpl->mFontDefaults ) + { + return mImpl->mFontDefaults->mFontDescription.slant; + } + + return TextAbstraction::FontSlant::NORMAL; } void Controller::SetDefaultPointSize( float pointSize ) @@ -327,7 +409,7 @@ void Controller::UpdateAfterFontChange( std::string& newDefaultFont ) if ( !mImpl->mUserDefinedFontFamily ) // If user defined font then should not update when system font changes { DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() ); - mImpl->mFontDefaults->mDefaultFontFamily=newDefaultFont; + mImpl->mFontDefaults->mFontDescription.family = newDefaultFont; mImpl->UpdateModel( ALL_OPERATIONS ); mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED ); mImpl->mRecalculateNaturalSize = true; @@ -1174,7 +1256,7 @@ void Controller::KeyboardFocusLostEvent() { mImpl->ChangeState( EventData::INACTIVE ); - if( mImpl->IsShowingPlaceholderText() ) + if( !mImpl->IsShowingRealText() ) { // Revert to regular placeholder-text when not editing ShowPlaceholderText(); @@ -1441,6 +1523,11 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y ) else if( EventData::EDITING != mImpl->mEventData->mState && EventData::EDITING_WITH_GRAB_HANDLE != mImpl->mEventData->mState ) { + if( mImpl->IsShowingPlaceholderText() && ! mImpl->IsFocusedPlaceholderAvailable() ) + { + // Hide placeholder text + ResetText(); + } // Show cursor on first tap mImpl->ChangeState( EventData::EDITING ); relayoutNeeded = true; @@ -1495,21 +1582,38 @@ void Controller::PanEvent( Gesture::State state, const Vector2& displacement ) void Controller::LongPressEvent( Gesture::State state, float x, float y ) { - DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" ); + DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" ); - if ( mImpl->IsShowingPlaceholderText() || mImpl->mLogicalModel->mText.Count() == 0u ) + if( state == Gesture::Started && + mImpl->mEventData ) { - if ( mImpl->mEventData ) + if( ! mImpl->IsShowingRealText() ) { Event event( Event::LONG_PRESS_EVENT ); event.p1.mInt = state; mImpl->mEventData->mEventQueue.push_back( event ); mImpl->RequestRelayout(); } - } - else if( mImpl->mEventData ) - { - SelectEvent( x, y, false ); + else + { + // The 1st long-press on inactive text-field is treated as tap + if( EventData::INACTIVE == mImpl->mEventData->mState ) + { + mImpl->ChangeState( EventData::EDITING ); + + Event event( Event::TAP_EVENT ); + event.p1.mUint = 1; + event.p2.mFloat = x; + event.p3.mFloat = y; + mImpl->mEventData->mEventQueue.push_back( event ); + + mImpl->RequestRelayout(); + } + else + { + SelectEvent( x, y, false ); + } + } } } @@ -1634,6 +1738,13 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt { mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text mImpl->mOperationsPending = ALL_OPERATIONS; + + // This is to reset the virtual keyboard to Upper-case + if( 0u == mImpl->mLogicalModel->mText.Count() ) + { + NotifyImfManager(); + } + if( 0u != mImpl->mLogicalModel->mText.Count() || !mImpl->IsPlaceholderAvailable() ) { @@ -1797,6 +1908,12 @@ bool Controller::BackspaceKeyEvent() if( removed ) { + // This is to reset the virtual keyboard to Upper-case + if( 0u == mImpl->mLogicalModel->mText.Count() ) + { + NotifyImfManager(); + } + if( 0u != mImpl->mLogicalModel->mText.Count() || !mImpl->IsPlaceholderAvailable() ) { @@ -1812,6 +1929,25 @@ bool Controller::BackspaceKeyEvent() return removed; } +void Controller::NotifyImfManager() +{ + if( mImpl->mEventData ) + { + ImfManager imfManager = ImfManager::Get(); + + if( imfManager ) + { + // Notifying IMF of a cursor change triggers a surrounding text request so updating it now. + std::string text; + GetText( text ); + imfManager.SetSurroundingText( text ); + + imfManager.SetCursorPosition( GetLogicalCursorPosition() ); + imfManager.NotifyCursorPosition(); + } + } +} + void Controller::ShowPlaceholderText() { if( mImpl->IsPlaceholderAvailable() )