Fix for N_SE-40699
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_SearchBar.cpp
index 624d43f..311cb6c 100644 (file)
@@ -43,6 +43,8 @@
 #include "FUiCtrl_SearchBarImpl.h"
 #include "FUiCtrl_EditFieldImpl.h"
 #include "FUiCtrl_ButtonImpl.h"
+#include <FSys_SettingInfoImpl.h>
+
 
 using namespace Tizen::Graphics;
 using namespace Tizen::Ui;
@@ -50,6 +52,7 @@ using namespace Tizen::Ui::Animations;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Runtime;
 using namespace Tizen::Locales;
+using namespace Tizen::System;
 
 namespace Tizen { namespace Ui { namespace Controls
 {
@@ -74,6 +77,7 @@ _SearchBar::_SearchBar(void)
        , __isupdateContentBounds(false)
        , __isKeyPressed(false)
        , __isFocusCallbackToBeFired(true)
+       , __isButtonTextChangedByApp(false)
        , __keypadAction(CORE_KEYPAD_ACTION_SEARCH)
        , __pBackgroundBitmap(null)
        , __backgroundColor(Color())
@@ -108,6 +112,8 @@ _SearchBar::_SearchBar(void)
 
 _SearchBar::~_SearchBar(void)
 {
+       SettingInfo::RemoveSettingEventListener(*this);
+
        delete __pSearchBarPresenter;
        __pSearchBarPresenter = null;
 
@@ -258,6 +264,10 @@ _SearchBar::Initialize(bool enableSearchBarButton, CoreKeypadAction keypadAction
        __pSearchBarPresenter = pPresenter;
 
        CreateAccessibilityElement();
+
+       r = _SettingInfoImpl::AddSettingEventListener(*this);
+       SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
        return r;
 
 CATCH:
@@ -670,6 +680,8 @@ _SearchBar::SetButtonText(const String& text)
        SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
                     "[E_SYSTEM] A system error has occurred. Failed to set text.");
 
+       __isButtonTextChangedByApp = true;
+
        return r;
 }
 
@@ -1651,6 +1663,8 @@ _SearchBar::OnKeypadClosed(void)
                __pKeypadEvent->Fire(*pEventArg);
        }
 
+       __isKeypadOpening = false;
+
        SetContentsArea();
        return;
 }
@@ -1787,65 +1801,110 @@ _SearchBar::OnFocusLost(const _Control &source)
 bool
 _SearchBar::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
 {
+       if (!__pEdit->IsUsbKeyboardConnected())
+       {
+               return false;
+       }
+
+       if (!__pEdit->IsSearchFieldFocused())
+       {
+               return false;
+       }
+
        _KeyCode keyCode = keyInfo.GetKeyCode();
 
-       if (keyCode == _KEY_RIGHT)
+       switch (keyCode)
        {
-               if (GetMode() == SEARCH_BAR_MODE_NORMAL)
-               {
-                       __pEdit->SetFocused();
-                       return true;
-               }
+               case _KEY_RIGHT:
+                       SetFocusCallbackParameter(false);
+                       if (&source == __pEdit)
+                       {
+                               if ((!__isButtonEnabled || !__isUsableCancelButton) && __pContentControl && __pContentControl->GetVisibleState() && __pContentControl->GetEnableState())
+                               {
+                                       __pContentControl->SetFocused();
+                                       __pContentControl->OnDrawFocus();
 
-               if (!__isButtonEnabled || __pCancelButton->IsFocused() || !__isUsableCancelButton)
-               {
-                       return true;
-               }
+                                       return true;
+                               }
+                               else if (__isButtonEnabled && __isUsableCancelButton)
+                               {
+                                       __pCancelButton->SetFocused();
+                               }
 
-               __pCancelButton->SetButtonStatus(_BUTTON_STATUS_HIGHLIGHTED);
-               SetFocusCallBackParameter(false);
-               __pCancelButton->SetFocused();
-               __pCancelButton->Invalidate(true);
+                               return true;
+                       }
 
-               return true;
-       }
+                       if (&source == __pCancelButton && __pContentControl && __pContentControl->GetVisibleState() && __pContentControl->GetEnableState())
+                       {
+                               __pContentControl->SetFocused();
+                               __pContentControl->OnDrawFocus();
 
-       if (keyCode == _KEY_LEFT)
-       {
-               if (__pCancelButton->GetButtonStatus() == _BUTTON_STATUS_HIGHLIGHTED)
-               {
-                       __pCancelButton->SetButtonStatus(_BUTTON_STATUS_NORMAL);
-                       __pCancelButton->Invalidate();
-                       __pEdit->SetFocused();
-               }
+                               return true;
+                       }
 
-               if (__pCancelButton->GetButtonStatus() == _BUTTON_STATUS_DISABLED)      //Searchbar Button is disabled, left arrow key is pressed
-               {
-                       __pCancelButton->SetButtonStatus(_BUTTON_STATUS_NORMAL);
-                       SetButtonEnabled(false);
-                       __pEdit->SetFocused();
-               }
+                       break;
 
-               return true;
-       }
+               case _KEY_LEFT:
+                       if (&source == __pCancelButton)
+                       {
+                               __pEdit->SetFocused();
+                               return true;
+                       }
+
+                       if (&source == __pContentControl)
+                       {
+                               if ((__isButtonEnabled && __isUsableCancelButton))
+                               {
+                                       __pCancelButton->SetFocused();
+                               }
+                               else
+                               {
+                                       __pEdit->SetFocused();
+                               }
+                               return true;
+                       }
 
-       if (keyCode == _KEY_ENTER || keyCode == _KEY_TAB)
-       {
-               if (GetMode() == SEARCH_BAR_MODE_NORMAL)
-               {
-                       return false;
-               }
+                       break;
 
-               SetMode(SEARCH_BAR_MODE_NORMAL);
-               __isKeyPressed = true;
-               SetFocused();
+               case _KEY_ENTER:
+                       if (&source == __pCancelButton)
+                       {
+                               SetMode(SEARCH_BAR_MODE_NORMAL);
+                               __isKeyPressed = true;
+                               SetFocused();
+                               _Control::OnDrawFocus();
 
-               return true;
+                               return true;
+                       }
+
+                       break;
+
+               default:
+                       return false;
        }
 
        return false;
 }
 
+void
+_SearchBar::OnSettingChanged(Tizen::Base::String& key)
+{
+       if (__isButtonTextChangedByApp || !__isUsableCancelButton)
+       {
+               return;
+       }
+
+       if (key.Equals(L"http://tizen.org/setting/locale.language", false))
+       {
+               String cancelText;
+               GET_STRING_CONFIG(IDS_COM_SK_CANCEL, cancelText);
+               __pCancelButton->SetText(cancelText);
+               __pCancelButton->Invalidate();
+       }
+
+       return;
+}
+
 _Control*
 _SearchBar::GetParentForm(void) const
 {
@@ -2718,14 +2777,14 @@ _SearchBar::SendOpaqueCommand(const String& command)
 }
 
 void
-_SearchBar::SetFocusCallBackParameter(bool state)
+_SearchBar::SetFocusCallbackParameter(bool state)
 {
        __isFocusCallbackToBeFired = state;
        return;
 }
 
 bool
-_SearchBar::IsFocusCallBackToBeFired(void) const
+_SearchBar::IsFocusCallbackToBeFired(void) const
 {
        return __isFocusCallbackToBeFired;
 }