Fix for JIRA 40541, 40539, 40517, 40511, 40502 and UTs
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_SearchBar.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUiCtrl_SearchBar.cpp
20  * @brief               This is the implementation file for the _SearchBar class.
21  */
22
23 #include <FBaseErrorDefine.h>
24 #include <FBaseSysLog.h>
25 #include <FGrp_BitmapImpl.h>
26 #include "FUiAnim_VisualElement.h"
27 #include "FUi_ResourceManager.h"
28 #include "FUiCtrl_SearchBar.h"
29 #include "FUiCtrl_SearchBarPresenter.h"
30 #include "FUiCtrl_Form.h"
31 #include "FUiCtrl_Edit.h"
32 #include "FUiCtrl_Panel.h"
33 #include "FUiCtrl_OverlayPanel.h"
34 #include "FUiCtrl_Keypad.h"
35 #include "FUiCtrl_ColorPicker.h"
36 #include "FUiCtrl_ActionEvent.h"
37 #include "FUiCtrl_TextBlockEvent.h"
38 #include "FUiCtrl_TextEvent.h"
39 #include "FUi_AccessibilityContainer.h"
40 #include "FUi_AccessibilityElement.h"
41 #include "FUi_AccessibilityManager.h"
42 #include "FUi_CoordinateSystemUtils.h"
43 #include "FUiCtrl_SearchBarImpl.h"
44 #include "FUiCtrl_EditFieldImpl.h"
45 #include "FUiCtrl_ButtonImpl.h"
46 #include <FSys_SettingInfoImpl.h>
47
48
49 using namespace Tizen::Graphics;
50 using namespace Tizen::Ui;
51 using namespace Tizen::Ui::Animations;
52 using namespace Tizen::Base;
53 using namespace Tizen::Base::Runtime;
54 using namespace Tizen::Locales;
55 using namespace Tizen::System;
56
57 namespace Tizen { namespace Ui { namespace Controls
58 {
59
60 IMPLEMENT_PROPERTY(_SearchBar);
61
62 _SearchBar::_SearchBar(void)
63         : __pSearchBarPresenter(null)
64         , __pClippedGroupControl(null)
65         , __pEdit(null)
66         , __pCancelButton(null)
67         , __pContainer(null)
68         , __pContentControl(null)
69         , __actionId(0)
70         , __searchBarStyle(0)
71         , __isButtonEnabled(true)
72         , __isUsableCancelButton(false)
73         , __isUserContainerBounds(false)
74         , __isCancelActionInProgress(false)
75         , __isUserGuideTextColor(false)
76         , __isKeypadOpening(false)
77         , __isupdateContentBounds(false)
78         , __isKeyPressed(false)
79         , __isFocusCallbackToBeFired(true)
80         , __isButtonTextChangedByApp(false)
81         , __keypadAction(CORE_KEYPAD_ACTION_SEARCH)
82         , __pBackgroundBitmap(null)
83         , __backgroundColor(Color())
84         , __contentColor(Color())
85         , __pActionEvent(null)
86         , __pKeypadEvent(null)
87         , __pTextBlockEvent(null)
88         , __pTextEvent(null)
89         , __pSearchBarEvent(null)
90         , __pLanguageEvent(null)
91         , __pAccessibilitySearchBarElement(null)
92 {
93         for (int i = 0; i < SEARCHBAR_BUTTON_COLOR_MAX; i++)
94         {
95                 __buttonColor[i] = Color(0);
96                 __buttonTextColor[i] = Color(0);
97         }
98
99         for (int i = 0; i < SEARCHBAR_COLOR_MAX; i++)
100         {
101                 __color[i] = Color(0);
102                 __textColor[i] = Color(0);
103                 __guideTextColor[i] = Color(0);
104         }
105
106         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
107         if (pContainer)
108         {
109                 pContainer->Activate(true);
110         }
111 }
112
113 _SearchBar::~_SearchBar(void)
114 {
115         SettingInfo::RemoveSettingEventListener(*this);
116
117         delete __pSearchBarPresenter;
118         __pSearchBarPresenter = null;
119
120         if (__pClippedGroupControl)
121         {
122                 DetachChild(*__pClippedGroupControl);
123
124                 delete __pClippedGroupControl;
125                 __pClippedGroupControl = null;
126         }
127
128         if (__pContainer)
129         {
130                 DetachChild(*__pContainer);
131
132                 delete __pContainer;
133                 __pContainer = null;
134         }
135
136         if (__pActionEvent)
137         {
138                 delete __pActionEvent;
139                 __pActionEvent = null;
140         }
141
142         if (__pKeypadEvent)
143         {
144                 delete __pKeypadEvent;
145                 __pKeypadEvent = null;
146         }
147
148         if (__pTextBlockEvent)
149         {
150                 delete __pTextBlockEvent;
151                 __pTextBlockEvent = null;
152         }
153
154         if (__pTextEvent)
155         {
156                 delete __pTextEvent;
157                 __pTextEvent = null;
158         }
159
160         if (__pSearchBarEvent)
161         {
162                 delete __pSearchBarEvent;
163                 __pSearchBarEvent = null;
164         }
165
166         if (__pAccessibilitySearchBarElement)
167         {
168                 __pAccessibilitySearchBarElement->Activate(false);
169                 __pAccessibilitySearchBarElement = null;
170         }
171
172         delete __pBackgroundBitmap;
173         __pBackgroundBitmap = null;
174 }
175
176 _SearchBar*
177 _SearchBar::CreateSearchBarN(void)
178 {
179         _SearchBar* pSearchBar = new (std::nothrow) _SearchBar;
180         SysTryReturn(NID_UI_CTRL, pSearchBar, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
181         if (GetLastResult() != E_SUCCESS)
182         {
183                 delete pSearchBar;
184                 return null;
185         }
186
187         pSearchBar->AcquireHandle();
188         pSearchBar->SetTouchPressThreshold(_TOUCH_PRESS_THRESHOLD_INSENSITIVE);
189
190         return pSearchBar;
191 }
192
193 result
194 _SearchBar::Initialize(bool enableSearchBarButton, CoreKeypadAction keypadAction)
195 {
196         result r = E_SUCCESS;
197
198         // Setting Button color
199         GET_COLOR_CONFIG(SEARCHBAR::BUTTON_BG_NORMAL, __buttonColor[SEARCH_BAR_BUTTON_STATUS_NORMAL]);
200         GET_COLOR_CONFIG(SEARCHBAR::BUTTON_BG_PRESSED, __buttonColor[SEARCH_BAR_BUTTON_STATUS_PRESSED]);
201         GET_COLOR_CONFIG(SEARCHBAR::BUTTON_BG_HIGHLIGHTED, __buttonColor[SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED]);
202         GET_COLOR_CONFIG(SEARCHBAR::BUTTON_BG_DISABLED, __buttonColor[SEARCH_BAR_BUTTON_STATUS_DISABLED]);
203
204         GET_COLOR_CONFIG(SEARCHBAR::BUTTON_TEXT_NORMAL, __buttonTextColor[SEARCH_BAR_BUTTON_STATUS_NORMAL]);
205         GET_COLOR_CONFIG(SEARCHBAR::BUTTON_TEXT_PRESSED, __buttonTextColor[SEARCH_BAR_BUTTON_STATUS_PRESSED]);
206         GET_COLOR_CONFIG(SEARCHBAR::BUTTON_TEXT_HIGHLIGHTED, __buttonTextColor[SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED]);
207         GET_COLOR_CONFIG(SEARCHBAR::BUTTON_TEXT_DISABLED, __buttonTextColor[SEARCH_BAR_BUTTON_STATUS_DISABLED]);
208
209         GET_COLOR_CONFIG(SEARCHBAR::CONTENT_AREA_BG_NORMAL, __contentColor);
210
211         for (int i = 0; i < SEARCHBAR_COLOR_MAX; i++)
212         {
213                 switch(i)
214                 {
215                 case SEARCH_FIELD_STATUS_DISABLED:
216                         GET_COLOR_CONFIG(SEARCHBAR::EDIT_BG_DISABLED, __color[i]);
217                         GET_COLOR_CONFIG(SEARCHBAR::EDIT_TEXT_DISABLED, __textColor[i]);
218                         GET_COLOR_CONFIG(SEARCHBAR::GUIDE_TEXT_DISABLED, __guideTextColor[i]);
219                         break;
220
221                 case SEARCH_FIELD_STATUS_HIGHLIGHTED:
222                         GET_COLOR_CONFIG(SEARCHBAR::EDIT_BG_NORMAL, __color[i]);
223                         GET_COLOR_CONFIG(SEARCHBAR::EDIT_TEXT_HIGHLIGHTED, __textColor[i]);
224                         GET_COLOR_CONFIG(SEARCHBAR::GUIDE_TEXT_HIGHLIGHTED, __guideTextColor[i]);
225                         break;
226                 default:
227                         GET_COLOR_CONFIG(SEARCHBAR::EDIT_BG_NORMAL, __color[i]);
228                         GET_COLOR_CONFIG(SEARCHBAR::EDIT_TEXT_NORMAL, __textColor[i]);
229                         GET_COLOR_CONFIG(SEARCHBAR::GUIDE_TEXT_NORMAL, __guideTextColor[i]);
230                         break;
231                 }
232         }
233
234         __isUsableCancelButton = enableSearchBarButton;
235         __keypadAction = keypadAction;
236
237         GetVisualElement()->SetClipChildrenEnabled(false);
238
239         r = CreateClippedGroupControl();
240         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
241                      "[E_SYSTEM] A system error has occurred. The construction of parent control for clipped group control failed.");
242
243         r = CreateSearchField();
244         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
245                      "[E_SYSTEM] A system error has occurred. The edit construction failed.");
246         r = CreateCancelButton();
247         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
248                      "[E_SYSTEM] A system error has occurred. The cancel button construction failed.");
249
250         SetContentsArea();
251         r = CreateContentsArea();
252         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
253                      "[E_SYSTEM] A system error has occurred. The construction of parent for content failed.");
254
255         _SearchBarPresenter* pPresenter = new (std::nothrow) _SearchBarPresenter;
256         SysTryReturn(NID_UI_CTRL, pPresenter, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
257
258         r = pPresenter->Construct(*this);
259         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
260
261         r = pPresenter->Install();
262         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
263
264         __pSearchBarPresenter = pPresenter;
265
266         CreateAccessibilityElement();
267
268         r = _SettingInfoImpl::AddSettingEventListener(*this);
269         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
270
271         return r;
272
273 CATCH:
274         delete pPresenter;
275         pPresenter = null;
276
277         return r;
278 }
279
280 result
281 _SearchBar::CreateSearchField(void)
282 {
283         result r = E_SUCCESS;
284
285         FloatRectangle editBounds;
286         float horizontalMargin = 0.0f;
287         float verticalMargin = 0.0f;
288         float iconHorizontalMargin = 0.0f;
289         float textHorizontalMargin = 0.0f;
290         float iconWidth = 0.0f;
291         float textSize = 0.0f;
292         float searchBarMinHeight = 0.0f;
293         float searchBarMinWidthModeNormal = 0.0f;
294
295         FloatRectangle searchBarBounds = GetBoundsF();
296         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
297
298         GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
299         GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, verticalMargin);
300         GET_SHAPE_CONFIG(SEARCHBAR::ICON_HORIZONTAL_MARGIN, orientation, iconHorizontalMargin);
301         GET_SHAPE_CONFIG(SEARCHBAR::ICON_WIDTH, orientation, iconWidth);
302         GET_SHAPE_CONFIG(SEARCHBAR::TEXT_HORIZONTAL_MARGIN, orientation, textHorizontalMargin);
303         GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH_NORMAL_MODE, orientation, searchBarMinWidthModeNormal);
304         GET_SHAPE_CONFIG(SEARCHBAR::MIN_HEIGHT, orientation, searchBarMinHeight);
305
306         float searchFieldMinHeight = searchBarMinHeight - (verticalMargin * 2.0f);
307
308         editBounds.x = horizontalMargin;
309
310         if (searchBarBounds.height < searchBarMinHeight)
311         {
312                 verticalMargin = (searchBarBounds.height - searchFieldMinHeight)/2.0f;
313                 if (verticalMargin < 0.0f)
314                 {
315                         verticalMargin = 0.0f;
316                 }
317         }
318
319         editBounds.y = verticalMargin;
320
321         editBounds.width = searchBarBounds.width - (editBounds.x * 2.0f);
322         editBounds.height = searchBarBounds.height - (editBounds.y * 2.0f);
323
324         editBounds.width = (editBounds.width > searchBarMinWidthModeNormal) ? editBounds.width : searchBarMinWidthModeNormal;
325         editBounds.height = (editBounds.height > searchFieldMinHeight) ? editBounds.height : searchFieldMinHeight;
326
327         _SearchBarImpl* pSearchBarImpl = static_cast<_SearchBarImpl*>(GetUserData());
328         __pEdit = &(pSearchBarImpl->GetEditFieldImpl()->GetCore());
329
330         SysTryReturnResult(NID_UI_CTRL, __pEdit != null, E_SYSTEM,
331                            "[E_SYSTEM] A system error has occured. Failed to get _Edit instance");
332
333         __pEdit->SetKeypadCommandButtonVisible(false);
334         __pEdit->SetBounds(editBounds);
335         __pEdit->AddKeypadEventListener(*this);
336         __pEdit->AddTextBlockEventListener(*this);
337         __pEdit->AddTextEventListener(*this);
338
339         GET_SHAPE_CONFIG(SEARCHBAR::EDIT_TEXT_SIZE, orientation, textSize);
340         __pEdit->SetTextSize(textSize);
341
342         __pEdit->SetHorizontalMargin(iconHorizontalMargin + iconWidth + textHorizontalMargin, EDIT_TEXT_LEFT_MARGIN);
343         __pEdit->SetHorizontalMargin(textHorizontalMargin, EDIT_TEXT_RIGHT_MARGIN);
344         __pEdit->SetLimitLength(SEARCHBAR_TEXT_LENGTH_MAX);
345
346         for (int status = 0; status < SEARCHBAR_COLOR_MAX; status++)
347         {
348                 EditStatus editStatus = ConvertSearchBarStatus((SearchFieldStatus) status);
349                 __pEdit->SetColor(editStatus, __color[status]);
350         }
351
352         __pEdit->SetTextColor(EDIT_TEXT_COLOR_NORMAL, __textColor[SEARCH_FIELD_STATUS_NORMAL]);
353         __pEdit->SetTextColor(EDIT_TEXT_COLOR_DISABLED, __textColor[SEARCH_FIELD_STATUS_DISABLED]);
354         __pEdit->SetTextColor(EDIT_TEXT_COLOR_HIGHLIGHTED, __textColor[SEARCH_FIELD_STATUS_HIGHLIGHTED]);
355
356         __pEdit->ReplaceDefaultBackgroundBitmapForSearchBar();
357
358         __pEdit->SetKeypadAction(__keypadAction);
359
360         r = __pClippedGroupControl->AttachChild(*__pEdit);
361         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM,
362                     "[E_SYSTEM] A system error has occurred. Failed to attach edit as child.");
363
364         return E_SUCCESS;
365
366 CATCH:
367         delete __pEdit;
368         __pEdit = null;
369
370         return r;
371 }
372
373 result
374 _SearchBar::CreateCancelButton(void)
375 {
376         result r = E_SUCCESS;
377
378         float textSize = 0.0f;
379         String cancelButtonText;
380
381         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
382
383         _SearchBarImpl* pSearchBarImpl = static_cast<_SearchBarImpl*>(GetUserData());
384         __pCancelButton = &(pSearchBarImpl->GetButtonImpl()->GetCore());
385
386         SysTryReturnResult(NID_UI_CTRL, __pCancelButton != null, E_SYSTEM,
387                            "[E_SYSTEM] A system error has occured. Failed to get _Edit instance");
388
389         r = GetLastResult();
390         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
391
392         r = ResizeCancelButton();
393         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
394
395         GET_STRING_CONFIG(IDS_COM_SK_CANCEL, cancelButtonText);
396         r = __pCancelButton->SetText(cancelButtonText);
397         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
398
399         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_TEXT_SIZE, orientation, textSize);
400         r = __pCancelButton->SetTextSize(textSize);
401         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
402
403         __pCancelButton->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
404         __pCancelButton->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
405
406         r = __pCancelButton->SetActionId(__actionId);
407         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
408
409         r = __pCancelButton->AddActionEventListener(*this);
410         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
411
412         __pCancelButton->SetVisibleState(false);
413
414         for (int status = 0; status < SEARCHBAR_BUTTON_COLOR_MAX; status++)
415         {
416                 _ButtonStatus buttonStatus = ConvertSearchBarButtonStatus((SearchBarButtonStatus) status);
417
418                 r = __pCancelButton->SetColor(buttonStatus, __buttonColor[status]);
419                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
420
421                 r = __pCancelButton->SetTextColor(buttonStatus, __buttonTextColor[status]);
422                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
423         }
424
425         r = __pClippedGroupControl->AttachChild(*__pCancelButton);
426         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM,
427                     "[E_SYSTEM] A system error has occurred. Failed to attach button as child.");
428
429         return E_SUCCESS;
430
431 CATCH:
432         delete __pCancelButton;
433         __pCancelButton = null;
434
435         return r;
436 }
437
438 result
439 _SearchBar::CreateContentsArea(void)
440 {
441         result r = E_SUCCESS;
442
443         __pContainer = _Control::CreateControlN();
444
445         r = GetLastResult();
446         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
447
448         __pContainer->SetVisibleState(false);
449
450         r = AttachChild(*__pContainer);
451         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM,
452                     "[E_SYSTEM] A system error has occurred. Failed to attach the parent of content.");
453
454         return E_SUCCESS;
455
456 CATCH:
457         delete __pContainer;
458         __pContainer = null;
459
460         return r;
461 }
462
463 void
464 _SearchBar::SetContentsArea(void)
465 {
466         if (__isUserContainerBounds)
467         {
468                 return;
469         }
470
471         FloatDimension screenSize = _ControlManager::GetInstance()->GetScreenSizeF();
472         float width = screenSize.width;
473         float height = screenSize.height;
474
475         _Control* pParent = GetParentForm();
476         if (pParent != null)
477         {
478                 width = pParent->GetClientBoundsF().width;
479                 height = pParent->GetClientBoundsF().height;
480         }
481
482         FloatRectangle controlBounds = GetBoundsF();
483         controlBounds = CoordinateSystem::AlignToDevice(FloatRectangle(controlBounds));
484
485         __contentAreaBounds.x = 0.0f;
486         __contentAreaBounds.y = controlBounds.height;
487         __contentAreaBounds.width = width - controlBounds.x;
488         __contentAreaBounds.height = height - (controlBounds.y + controlBounds.height);
489
490         if (__pContainer)
491         {
492                 result r = E_SUCCESS;
493                 r = __pContainer->SetBounds(__contentAreaBounds);
494                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
495         }
496         return;
497 }
498
499 _Control*
500 _SearchBar::GetContent(void) const
501 {
502         return __pContentControl;
503 }
504
505 result
506 _SearchBar::SetContent(const _Control* pContent)
507 {
508         __pContentControl = const_cast <_Control*>(pContent);
509         result r = E_SUCCESS;
510
511         if (__pContainer)
512         {
513                 r = __pContainer->AttachChild(*__pContentControl);
514                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating");
515         }
516
517         return r;
518 }
519
520 result
521 _SearchBar::UpdateContentArea(bool invalidate)
522 {
523         return __pSearchBarPresenter->UpdateContentArea(invalidate);
524 }
525
526 result
527 _SearchBar::SetContentAreaVisible(bool visible)
528 {
529         SysTryReturn(NID_UI_CTRL, __pContainer, E_SYSTEM, E_SYSTEM,
530                      "[E_SYSTEM] A system error has occurred. The instance of parent to content is null.");
531
532         SearchBarMode searchBarMode = GetMode();
533         if (searchBarMode == SEARCH_BAR_MODE_INPUT)
534         {
535                 __pContainer->SetVisibleState(visible);
536         }
537
538         return __pSearchBarPresenter->SetContentAreaVisible(visible);
539 }
540
541 bool
542 _SearchBar::IsContentAreaVisible(void) const
543 {
544         return __pSearchBarPresenter->IsContentAreaVisible();
545 }
546
547 result
548 _SearchBar::SetContentAreaSize(const Dimension& size)
549 {
550         return SetProperty("contentAreaSize", Variant(size));
551 }
552
553 Dimension
554 _SearchBar::GetContentAreaSize(void) const
555 {
556         Variant size = GetProperty("contentAreaSize");
557
558         return size.ToDimension();
559 }
560
561 SearchBarMode
562 _SearchBar::GetMode(void) const
563 {
564         return __pSearchBarPresenter->GetMode();
565 }
566
567 bool
568 _SearchBar::IsModeLocked(void) const
569 {
570         return __pSearchBarPresenter->IsModeLocked();
571 }
572
573 result
574 _SearchBar::SetMode(SearchBarMode mode)
575 {
576         return __pSearchBarPresenter->SetMode(mode);
577 }
578
579 result
580 _SearchBar::SetModeLocked(bool modeLocked)
581 {
582         if (modeLocked == true && GetMode() == SEARCH_BAR_MODE_NORMAL)
583         {
584                 __pEdit->SetViewModeEnabled(true);
585         }
586
587         if (modeLocked == false && __pEdit->IsViewModeEnabled())
588         {
589                 __pEdit->SetViewModeEnabled(false);
590         }
591
592         return __pSearchBarPresenter->SetModeLocked(modeLocked);
593 }
594
595 int
596 _SearchBar::GetButtonActionId(void) const
597 {
598         Variant actionId = GetProperty("buttonActionId");
599
600         return actionId.ToInt();
601 }
602
603 Color
604 _SearchBar::GetButtonColor(SearchBarButtonStatus status) const
605 {
606         Variant buttonColor;
607
608         switch (status)
609         {
610         case SEARCH_BAR_BUTTON_STATUS_NORMAL:
611                 buttonColor = GetProperty("buttonNormalColor");
612                 break;
613         case SEARCH_BAR_BUTTON_STATUS_PRESSED:
614                 buttonColor = GetProperty("buttonPressedColor");
615                 break;
616         case SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED:
617                 buttonColor = GetProperty("buttonHighlightedColor");
618                 break;
619         case SEARCH_BAR_BUTTON_STATUS_DISABLED:
620                 buttonColor = GetProperty("buttonDisabledColor");
621                 break;
622         default:
623                 break;
624         }
625
626         return buttonColor.ToColor();
627 }
628
629 Color
630 _SearchBar::GetButtonTextColor(SearchBarButtonStatus status) const
631 {
632         Variant buttonTextColor;
633
634         switch (status)
635         {
636         case SEARCH_BAR_BUTTON_STATUS_NORMAL:
637                 buttonTextColor = GetProperty("buttonNormalTextColor");
638                 break;
639         case SEARCH_BAR_BUTTON_STATUS_PRESSED:
640                 buttonTextColor = GetProperty("buttonPressedTextColor");
641                 break;
642         case SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED:
643                 buttonTextColor = GetProperty("buttonHighlightedTextColor");
644                 break;
645         case SEARCH_BAR_BUTTON_STATUS_DISABLED:
646                 buttonTextColor = GetProperty("buttonDisabledTextColor");
647                 break;
648         default:
649                 break;
650         }
651
652         return buttonTextColor.ToColor();
653 }
654
655 SearchBarButtonStatus
656 _SearchBar::GetButtonStatus(void) const
657 {
658         SysTryReturn(NID_UI_CTRL, __pCancelButton, SEARCH_BAR_BUTTON_STATUS_NORMAL, E_SYSTEM,
659                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
660
661         SearchBarButtonStatus buttonStatus = SEARCH_BAR_BUTTON_STATUS_NORMAL;
662
663         if (__isButtonEnabled == false)
664         {
665                 buttonStatus = SEARCH_BAR_BUTTON_STATUS_DISABLED;
666         }
667
668         return buttonStatus;
669 }
670
671 result
672 _SearchBar::SetButtonText(const String& text)
673 {
674         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
675                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
676
677         result r = E_SUCCESS;
678
679         r = __pCancelButton->SetText(text);
680         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
681                      "[E_SYSTEM] A system error has occurred. Failed to set text.");
682
683         __isButtonTextChangedByApp = true;
684
685         return r;
686 }
687
688 result
689 _SearchBar::SetButtonActionId(int actionId)
690 {
691         return SetProperty("buttonActionId", Variant(actionId));
692 }
693
694 result
695 _SearchBar::SetButtonEnabled(bool enabled)
696 {
697         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
698                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
699
700         __pCancelButton->SetEnableState(enabled);
701
702         __isButtonEnabled = enabled;
703
704         return E_SUCCESS;
705 }
706
707 result
708 _SearchBar::SetButtonColor(SearchBarButtonStatus status, const Color& color)
709 {
710         result r = E_SUCCESS;
711
712         switch (status)
713         {
714         case SEARCH_BAR_BUTTON_STATUS_NORMAL:
715                 r = SetProperty("buttonNormalColor", Variant(color));
716                 break;
717         case SEARCH_BAR_BUTTON_STATUS_PRESSED:
718                 r = SetProperty("buttonPressedColor", Variant(color));
719                 break;
720         case SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED:
721                 r = SetProperty("buttonHighlightedColor", Variant(color));
722                 break;
723         case SEARCH_BAR_BUTTON_STATUS_DISABLED:
724                 r = SetProperty("buttonDisabledColor", Variant(color));
725                 break;
726         default:
727                 break;
728         }
729
730         return r;
731 }
732
733 result
734 _SearchBar::SetButtonTextColor(SearchBarButtonStatus status, const Color& color)
735 {
736         result r = E_SUCCESS;
737
738         switch (status)
739         {
740         case SEARCH_BAR_BUTTON_STATUS_NORMAL:
741                 r = SetProperty("buttonNormalTextColor", Variant(color));
742                 break;
743         case SEARCH_BAR_BUTTON_STATUS_PRESSED:
744                 r = SetProperty("buttonPressedTextColor", Variant(color));
745                 break;
746         case SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED:
747                 r = SetProperty("buttonHighlightedTextColor", Variant(color));
748                 break;
749         case SEARCH_BAR_BUTTON_STATUS_DISABLED:
750                 r = SetProperty("buttonDisabledTextColor", Variant(color));
751                 break;
752         default:
753                 break;
754         }
755
756         return r;
757 }
758
759 result
760 _SearchBar::AppendCharacter(const Character& character)
761 {
762         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
763                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
764         SysTryReturn(NID_UI_CTRL, character.CompareTo(null), E_SYSTEM, E_SYSTEM,
765                      "[E_SYSTEM] A system error has occurred. The character is null.");
766
767         result r = E_SUCCESS;
768
769         r = __pEdit->AppendCharacter(character);
770         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
771                      "[E_SYSTEM] A system error has occurred. Failed to set character.");
772
773         return r;
774 }
775
776 result
777 _SearchBar::AppendText(const String& text)
778 {
779         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
780                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
781         SysTryReturn(NID_UI_CTRL, text.IsEmpty() == false, E_SYSTEM, E_SYSTEM,
782                      "[E_SYSTEM] A system error has occurred. The text is empty.");
783
784         result r = E_SUCCESS;
785
786         r = __pEdit->AppendText(text);
787         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
788                      "[E_SYSTEM] A system error has occurred. Failed to set text.");
789
790         return r;
791 }
792
793 result
794 _SearchBar::SetText(const String& text)
795 {
796         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
797                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
798
799         result r = E_SUCCESS;
800
801         int limitLength = __pEdit->GetTextLimitLength();
802         int textLength = text.GetLength();
803         SysTryReturn(NID_UI_CTRL, limitLength >= textLength, E_SYSTEM, E_SYSTEM,
804                      "[E_SYSTEM] A system error has occurred. textLength exceeds the limitLength");
805
806         r = __pEdit->SetText(text);
807         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
808                      "[E_SYSTEM] A system error has occurred. Failed to set text.");
809
810         return r;
811 }
812
813 result
814 _SearchBar::InsertCharacterAt(int index, const Character& character)
815 {
816         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
817                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
818         SysTryReturn(NID_UI_CTRL, index > -1, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
819                      "[E_OUT_OF_RANGE] index(%d) is out of range.", index);
820         SysTryReturn(NID_UI_CTRL, character.CompareTo(null), E_SYSTEM, E_SYSTEM,
821                      "[E_SYSTEM] A system error has occurred. The character is null.");
822
823         result r = E_SUCCESS;
824
825         int textLength = 0;
826         int limitLength = 0;
827         limitLength = __pEdit->GetTextLimitLength();
828         textLength = __pEdit->GetTextLength() + 1;
829
830         SysTryReturn(NID_UI_CTRL, limitLength >= textLength, E_MAX_EXCEEDED, E_MAX_EXCEEDED,
831                      "[E_MAX_EXCEEDED] limitLength(%d) exceeds the maximum limit textLength(%d).", limitLength, textLength);
832
833         SysTryReturn(NID_UI_CTRL, index <= __pEdit->GetTextLength(), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
834                      "[E_OUT_OF_RANGE] index(%d) is out of range of current textLength(%d).", index, __pEdit->GetTextLength());
835
836         r = __pEdit->InsertCharacterAt(index, character);
837         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
838                      "[E_SYSTEM] A system error has occurred. Failed to set text.");
839
840         return r;
841 }
842
843 result
844 _SearchBar::InsertTextAt(int index, const String& text)
845 {
846         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
847                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
848         SysTryReturn(NID_UI_CTRL, index > -1, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
849                      "[E_OUT_OF_RANGE] index(%d) is out of range.", index);
850
851         result r = E_SUCCESS;
852
853         int textLength = 0;
854         int limitLength = 0;
855         limitLength = __pEdit->GetTextLimitLength();
856         textLength = __pEdit->GetTextLength() + text.GetLength();
857
858         SysTryReturn(NID_UI_CTRL, limitLength >= textLength, E_MAX_EXCEEDED, E_MAX_EXCEEDED,
859                      "[E_MAX_EXCEEDED] limitLength(%d) exceeds the maximum limit textLength(%d).", limitLength, textLength);
860         SysTryReturn(NID_UI_CTRL, index <= __pEdit->GetTextLength(), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
861                      "[E_OUT_OF_RANGE] index(%d) is out of range of current textLength(%d).", index, __pEdit->GetTextLength());
862
863         r = __pEdit->InsertTextAt(index, text);
864         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
865                      "[E_SYSTEM] A system error has occurred. Failed to insert text.");
866
867         return r;
868 }
869
870 result
871 _SearchBar::DeleteCharacterAt(int index)
872 {
873         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
874                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
875         SysTryReturn(NID_UI_CTRL, index > -1, E_INVALID_ARG, E_INVALID_ARG,
876                      "[E_INVALID_ARG] Invalid argument(s) is used. index = %d", index);
877
878         result r = E_SUCCESS;
879         int textLength = 0;
880         textLength = __pEdit->GetTextLength();
881
882         SysTryReturn(NID_UI_CTRL, textLength > index, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
883                      "[E_OUT_OF_RANGE] index(%d) is out of range. textLength(%d)", index, textLength);
884
885         r = __pEdit->DeleteCharacterAt(index);
886         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM,
887                            "[E_SYSTEM] A system error has occured. Failed to delete character.");
888
889         return r;
890 }
891
892 result
893 _SearchBar::Clear(void)
894 {
895         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
896                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
897
898         return __pEdit->ClearText();
899 }
900
901 int
902 _SearchBar::GetTextLength(void) const
903 {
904         SysTryReturn(NID_UI_CTRL, __pEdit, -1, E_SYSTEM,
905                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
906
907         return __pEdit->GetTextLength();
908 }
909
910 String
911 _SearchBar::GetText(void) const
912 {
913         SysTryReturn(NID_UI_CTRL, __pEdit, String(), E_SYSTEM,
914                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
915
916         return __pEdit->GetText();
917 }
918
919 String
920 _SearchBar::GetText(int start, int end) const
921 {
922         SysTryReturn(NID_UI_CTRL, __pEdit, String(), E_SYSTEM,
923                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
924
925         return __pEdit->GetText(start, end);
926 }
927
928 int
929 _SearchBar::GetLimitLength(void) const
930 {
931         SysTryReturn(NID_UI_CTRL, __pEdit, -1, E_SYSTEM,
932                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
933
934         return __pEdit->GetTextLimitLength();
935 }
936
937 result
938 _SearchBar::SetLimitLength(int limitLength)
939 {
940         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
941                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
942         SysTryReturn(NID_UI_CTRL, limitLength > 0, E_INVALID_ARG, E_INVALID_ARG,
943                      "[E_INVALID_ARG] Invalid argument(s) is used.limitLength = %d", limitLength);
944
945         String tempString = GetText();
946
947         int textLength = tempString.GetLength();
948         SysTryReturn(NID_UI_CTRL, limitLength >= textLength, E_INVALID_ARG, E_INVALID_ARG,
949                      "[E_INVALID_ARG] Invalid argument(s) is used. limitLength = %d, textLength = %d", limitLength, textLength);
950
951         result r = __pEdit->SetLimitLength(limitLength);
952         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
953
954         r = SetText(tempString);
955         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, r, "[%s] Propagating.", GetErrorMessage(r));
956
957         return E_SUCCESS;
958 }
959
960 result
961 _SearchBar::ShowKeypad(void) const
962 {
963         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
964                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
965
966         SearchBarMode mode = __pSearchBarPresenter->GetMode();
967         SysTryReturn(NID_UI_CTRL, mode == SEARCH_BAR_MODE_INPUT, E_INVALID_STATE, E_INVALID_STATE,
968                      "[E_INVALID_STATE] The SearchBar is currently in Normal mode.");
969         return __pEdit->ShowKeypad();
970 }
971
972 result
973 _SearchBar::HideKeypad(void)
974 {
975         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
976                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
977
978         SearchBarMode mode = __pSearchBarPresenter->GetMode();
979         SysTryReturn(NID_UI_CTRL, mode == SEARCH_BAR_MODE_INPUT, E_SYSTEM, E_SYSTEM,
980                      "[E_SYSTEM] A system error has occurred. The SearchBar is currently in Normal mode.");
981
982         result r = __pEdit->HideKeypad();
983
984         SetContentsArea();
985
986         return r;
987 }
988
989 float
990 _SearchBar::GetSearchFieldTextSizeF(void) const
991 {
992         SysTryReturn(NID_UI_CTRL, __pEdit, -1, E_SYSTEM,
993                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
994
995         return __pEdit->GetTextSizeF();
996 }
997
998 result
999 _SearchBar::SetSearchFieldTextSize(float size)
1000 {
1001         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1002                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1003
1004         return __pEdit->SetTextSize(size);
1005 }
1006
1007 result
1008 _SearchBar::GetBlockRange(int& start, int& end) const
1009 {
1010         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1011                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1012
1013         int startIndex = -1;
1014         int endIndex = -1;
1015
1016         __pEdit->GetBlockRange(startIndex, endIndex);
1017         SysTryReturn(NID_UI_CTRL, (startIndex > -1 && endIndex > 0), E_SYSTEM, E_SYSTEM,
1018                      "[E_SYSTEM] A system error has occurred. Failed to get text block range.");
1019
1020         start = startIndex;
1021         end = endIndex - 1;
1022
1023         return E_SUCCESS;
1024 }
1025
1026 result
1027 _SearchBar::ReleaseBlock(void)
1028 {
1029         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1030                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1031
1032         result r = E_SUCCESS;
1033
1034         int start = 0;
1035         int end = 0;
1036
1037         r = GetBlockRange(start, end);
1038         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1039
1040         return __pEdit->ReleaseTextBlock();
1041 }
1042
1043 result
1044 _SearchBar::SetBlockRange(int start, int end)
1045 {
1046         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1047                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1048
1049         result r = E_SUCCESS;
1050
1051         int textLength = 0;
1052         textLength = __pEdit->GetTextLength();
1053
1054         SysTryReturn(NID_UI_CTRL, (start < end && start >= 0 && textLength >= end), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1055                      "[E_OUT_OF_RANGE] start (%d) and end (%d) is out of range.", start, end - 1);
1056
1057         r = SetCursorPosition(start);
1058         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1059
1060         r = __pEdit->BeginTextBlock();
1061         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
1062                      "[E_SYSTEM] A system error has occurred. Failed to set text block range.");
1063
1064         r = SetCursorPosition(end);
1065         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
1066                      "[E_SYSTEM] A system error has occurred. Failed to set cursor position.");
1067
1068         return E_SUCCESS;
1069 }
1070
1071 result
1072 _SearchBar::RemoveTextBlock(void)
1073 {
1074         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1075                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1076
1077         result r = E_SUCCESS;
1078
1079         r = __pEdit->RemoveTextBlock();
1080         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1081
1082         return r;
1083 }
1084
1085 Color
1086 _SearchBar::GetColor(void) const
1087 {
1088         Variant backgroundColor = GetProperty("color");
1089
1090         return backgroundColor.ToColor();
1091 }
1092
1093 Color
1094 _SearchBar::GetSearchFieldColor(SearchFieldStatus status) const
1095 {
1096         Variant searchFieldColor;
1097
1098         switch (status)
1099         {
1100         case SEARCH_FIELD_STATUS_NORMAL:
1101                 searchFieldColor = GetProperty("searchFieldNormalColor");
1102                 break;
1103         case SEARCH_FIELD_STATUS_HIGHLIGHTED:
1104                 searchFieldColor = GetProperty("searchFieldHighlightedColor");
1105                 break;
1106         case SEARCH_FIELD_STATUS_DISABLED:
1107                 searchFieldColor = GetProperty("searchFieldDisabledColor");
1108                 break;
1109         default:
1110                 break;
1111         }
1112
1113         return searchFieldColor.ToColor();
1114 }
1115
1116
1117 Color
1118 _SearchBar::GetSearchFieldTextColor(SearchFieldStatus status) const
1119 {
1120         Variant searchFieldTextColor;
1121
1122         switch (status)
1123         {
1124         case SEARCH_FIELD_STATUS_NORMAL:
1125                 searchFieldTextColor = GetProperty("searchFieldNormalTextColor");
1126                 break;
1127         case SEARCH_FIELD_STATUS_HIGHLIGHTED:
1128                 searchFieldTextColor = GetProperty("searchFieldHighlightedTextColor");
1129                 break;
1130         case SEARCH_FIELD_STATUS_DISABLED:
1131                 searchFieldTextColor = GetProperty("searchFieldDisabledTextColor");
1132                 break;
1133         default:
1134                 break;
1135         }
1136
1137         return searchFieldTextColor.ToColor();
1138 }
1139
1140
1141 result
1142 _SearchBar::SetBackgroundBitmap(const Bitmap& bitmap)
1143 {
1144         Bitmap* pNewBitmap = _BitmapImpl::CloneN(bitmap);
1145         SysTryReturn(NID_UI_CTRL, pNewBitmap, E_SYSTEM, E_SYSTEM,
1146                      "[E_SYSTEM] A system error has occurred. The creation of bitmap failed.");
1147
1148         delete __pBackgroundBitmap;
1149         __pBackgroundBitmap = null;
1150
1151         __pBackgroundBitmap = pNewBitmap;
1152
1153         return E_SUCCESS;
1154 }
1155
1156 Bitmap*
1157 _SearchBar::GetBackgroundBitmap(void) const
1158 {
1159         return __pBackgroundBitmap;
1160 }
1161
1162 result
1163 _SearchBar::SetColor(const Color& color)
1164 {
1165         return SetProperty("color", Variant(color));
1166 }
1167
1168 result
1169 _SearchBar::SetSearchFieldColor(SearchFieldStatus status, const Color& color)
1170 {
1171         result r = E_SUCCESS;
1172
1173         switch (status)
1174         {
1175         case SEARCH_FIELD_STATUS_NORMAL:
1176                 r = SetProperty("searchFieldNormalColor", Variant(color));
1177                 break;
1178         case SEARCH_FIELD_STATUS_HIGHLIGHTED:
1179                 r = SetProperty("searchFieldHighlightedColor", Variant(color));
1180                 break;
1181         case SEARCH_FIELD_STATUS_DISABLED:
1182                 r = SetProperty("searchFieldDisabledColor", Variant(color));
1183                 break;
1184         default:
1185                 break;
1186         }
1187
1188         return r;
1189 }
1190
1191
1192 result
1193 _SearchBar::SetSearchFieldTextColor(SearchFieldStatus status, const Color& color)
1194 {
1195         result r = E_SUCCESS;
1196
1197         switch (status)
1198         {
1199         case SEARCH_FIELD_STATUS_NORMAL:
1200                 r = SetProperty("searchFieldNormalTextColor", Variant(color));
1201                 break;
1202         case SEARCH_FIELD_STATUS_HIGHLIGHTED:
1203                 r = SetProperty("searchFieldHighlightedTextColor", Variant(color));
1204                 break;
1205         case SEARCH_FIELD_STATUS_DISABLED:
1206                 r = SetProperty("searchFieldDisabledTextColor", Variant(color));
1207                 break;
1208         default:
1209                 break;
1210         }
1211
1212         return r;
1213 }
1214
1215
1216 String
1217 _SearchBar::GetGuideText(void) const
1218 {
1219         SysTryReturn(NID_UI_CTRL, __pEdit, String(), E_SYSTEM,
1220                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1221
1222         return __pEdit->GetGuideText();
1223 }
1224
1225 result
1226 _SearchBar::SetGuideText(const String& guideText)
1227 {
1228         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1229                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1230
1231         __pEdit->SetGuideText(guideText);
1232
1233         return E_SUCCESS;
1234 }
1235
1236 Color
1237 _SearchBar::GetGuideTextColor(void) const
1238 {
1239         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1240                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1241
1242         return __pEdit->GetGuideTextColor();
1243 }
1244
1245 result
1246 _SearchBar::SetGuideTextColor(const Color& color)
1247 {
1248         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1249                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1250
1251         __isUserGuideTextColor = true;
1252         return __pEdit->SetGuideTextColor(color);
1253 }
1254
1255 int
1256 _SearchBar::GetCursorPosition(void) const
1257 {
1258         SysTryReturn(NID_UI_CTRL, __pEdit, -1, E_SYSTEM,
1259                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1260
1261         return __pEdit->GetCursorPosition();
1262 }
1263
1264 result
1265 _SearchBar::SetCursorPosition(int index)
1266 {
1267         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1268                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1269         SysTryReturn(NID_UI_CTRL, index > -1, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1270                      "[E_OUT_OF_RANGE] index(%d) is out of range.", GetErrorMessage(E_OUT_OF_RANGE), index);
1271
1272         int textLength = -1;
1273         textLength = __pEdit->GetTextLength();
1274
1275         SysTryReturn(NID_UI_CTRL, (index > -1 && index <= textLength), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1276                      "[E_OUT_OF_RANGE] index(%d) is out of range.", index);
1277
1278         return __pEdit->SetCursorPosition(index);
1279 }
1280
1281 bool
1282 _SearchBar::IsLowerCaseModeEnabled(void) const
1283 {
1284         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1285                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1286
1287         return __pEdit->IsLowerCaseModeEnabled();
1288 }
1289
1290 void
1291 _SearchBar::SetLowerCaseModeEnabled(bool enable)
1292 {
1293         SysTryReturnVoidResult(NID_UI_CTRL, __pEdit, E_SYSTEM,
1294                                "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1295
1296         __pEdit->SetLowerCaseModeEnabled(enable);
1297 }
1298
1299 EllipsisPosition
1300 _SearchBar::GetEllipsisPosition(void) const
1301 {
1302         SysTryReturn(NID_UI_CTRL, __pEdit, ELLIPSIS_POSITION_START, E_SYSTEM,
1303                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1304
1305         return __pEdit->GetEllipsisPosition();
1306 }
1307
1308 result
1309 _SearchBar::SetEllipsisPosition(EllipsisPosition position)
1310 {
1311         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1312                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1313         __pEdit->SetEllipsisPosition(position);
1314
1315         return E_SUCCESS;
1316 }
1317
1318 CoreKeypadAction
1319 _SearchBar::GetKeypadAction(void) const
1320 {
1321         return __keypadAction;
1322 }
1323
1324 bool
1325 _SearchBar::IsTextPredictionEnabled(void) const
1326 {
1327         SysTryReturn(NID_UI_CTRL, __pEdit, false, E_SYSTEM,
1328                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1329         return __pEdit->IsTextPredictionEnabled();
1330 }
1331
1332 result
1333 _SearchBar::SetTextPredictionEnabled(bool enable)
1334 {
1335         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1336                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1337         return __pEdit->SetTextPredictionEnabled(enable);
1338 }
1339
1340 result
1341 _SearchBar::SetCurrentLanguage(LanguageCode languageCode)
1342 {
1343         return __pEdit->SetCurrentLanguage(languageCode);
1344 }
1345
1346 result
1347 _SearchBar::GetCurrentLanguage(LanguageCode& language) const
1348 {
1349         return __pEdit->GetCurrentLanguage(language);
1350 }
1351
1352 result
1353 _SearchBar::AddActionEventListener(const _IActionEventListener& listener)
1354 {
1355         result r = E_SUCCESS;
1356
1357         if (__pActionEvent == null)
1358         {
1359                 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
1360                 r = GetLastResult();
1361                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1362
1363                 __pActionEvent->AddListener(listener);
1364         }
1365
1366         return r;
1367 }
1368
1369 result
1370 _SearchBar::RemoveActionEventListener(const _IActionEventListener& listener)
1371 {
1372         SysTryReturn(NID_UI_CTRL, __pActionEvent, E_SYSTEM, E_SYSTEM,
1373                      "[E_SYSTEM] A system error has occurred. The action event instance is null.");
1374         result r = E_SUCCESS;
1375
1376         r = __pActionEvent->RemoveListener(listener);
1377         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1378
1379         return r;
1380 }
1381
1382 result
1383 _SearchBar::AddKeypadEventListener(const _IKeypadEventListener& listener)
1384 {
1385         result r = E_SUCCESS;
1386
1387         if (__pKeypadEvent == null)
1388         {
1389                 __pKeypadEvent = _KeypadEvent::CreateInstanceN(*this);
1390                 r = GetLastResult();
1391                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1392
1393                 r = __pKeypadEvent->AddListener(listener);
1394                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1395         }
1396
1397         return r;
1398 }
1399
1400 result
1401 _SearchBar::RemoveKeypadEventListener(const _IKeypadEventListener& listener)
1402 {
1403         SysTryReturn(NID_UI_CTRL, __pKeypadEvent, E_SYSTEM, E_SYSTEM,
1404                      "[E_SYSTEM] A system error has occurred. The keypad event instance is null.");
1405         result r = E_SUCCESS;
1406
1407         r = __pKeypadEvent->RemoveListener(listener);
1408         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1409
1410         return r;
1411 }
1412
1413 result
1414 _SearchBar::AddTextBlockEventListener(const _ITextBlockEventListener& listener)
1415 {
1416         result r = E_SUCCESS;
1417
1418         if (__pTextBlockEvent == null)
1419         {
1420                 __pTextBlockEvent = _TextBlockEvent::CreateInstanceN(*this);
1421                 r = GetLastResult();
1422                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1423
1424                 r = __pTextBlockEvent->AddListener(listener);
1425                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1426
1427         }
1428
1429         return r;
1430 }
1431
1432 result
1433 _SearchBar::RemoveTextBlockEventListener(const _ITextBlockEventListener& listener)
1434 {
1435         SysTryReturn(NID_UI_CTRL, __pTextBlockEvent, E_SYSTEM, E_SYSTEM,
1436                      "[E_SYSTEM] A system error has occurred. The text block event instance is null.");
1437         result r = E_SUCCESS;
1438
1439         r = __pTextBlockEvent->RemoveListener(listener);
1440         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1441
1442         return r;
1443 }
1444
1445
1446 result
1447 _SearchBar::AddTextEventListener(const _ITextEventListener& listener)
1448 {
1449         result r = E_SUCCESS;
1450
1451         if (__pTextEvent == null)
1452         {
1453                 __pTextEvent = _TextEvent::CreateInstanceN(*this);
1454                 r = GetLastResult();
1455                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1456
1457                 r = __pTextEvent->AddListener(listener);
1458                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1459         }
1460
1461         return r;
1462 }
1463
1464 result
1465 _SearchBar::RemoveTextEventListener(const _ITextEventListener& listener)
1466 {
1467         SysTryReturn(NID_UI_CTRL, __pTextEvent, E_SYSTEM, E_SYSTEM,
1468                      "[E_SYSTEM] A system error has occurred. The text event instance is null.");
1469         result r = E_SUCCESS;
1470
1471         r = __pTextEvent->RemoveListener(listener);
1472         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1473
1474         return r;
1475 }
1476
1477 result
1478 _SearchBar::AddSearchBarEventListener(const _ISearchBarEventListener& listener)
1479 {
1480         result r = E_SUCCESS;
1481
1482         if (__pSearchBarEvent == null)
1483         {
1484                 __pSearchBarEvent = _SearchBarEvent::CreateInstanceN(*this);
1485                 r = GetLastResult();
1486                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1487
1488                 r = __pSearchBarEvent->AddListener(listener);
1489                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1490         }
1491
1492         return r;
1493 }
1494
1495 result
1496 _SearchBar::RemoveSearchBarEventListener(const _ISearchBarEventListener& listener)
1497 {
1498         SysTryReturn(NID_UI_CTRL, __pSearchBarEvent, E_SYSTEM, E_SYSTEM,
1499                      "[E_SYSTEM] A system error has occurred. The searchbar event instance is null.");
1500         result r = E_SUCCESS;
1501
1502         r = __pSearchBarEvent->RemoveListener(listener);
1503         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1504
1505         return r;
1506 }
1507
1508 result
1509 _SearchBar::AddLanguageEventListener(const _ILanguageEventListener& listener)
1510 {
1511         result r = E_SUCCESS;
1512
1513         if (__pLanguageEvent == null)
1514         {
1515                 __pLanguageEvent = _LanguageEvent::CreateInstanceN(*this);
1516                 r = GetLastResult();
1517                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1518
1519                 r = __pLanguageEvent->AddListener(listener);
1520                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1521         }
1522
1523         return r;
1524 }
1525
1526 result
1527 _SearchBar::RemoveLanguageEventListener(const _ILanguageEventListener& listener)
1528 {
1529         SysTryReturn(NID_UI_CTRL, __pLanguageEvent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] This instance isn't constructed.");
1530         result r = E_SUCCESS;
1531
1532         __pLanguageEvent->RemoveListener(listener);
1533         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1534
1535         return r;
1536 }
1537
1538 void
1539 _SearchBar::OnBoundsChanged(void)
1540 {
1541         if (__pSearchBarPresenter != null)
1542         {
1543                 __isupdateContentBounds = true;
1544                 __pSearchBarPresenter->OnBoundsChanged();
1545         }
1546
1547         if (__pAccessibilitySearchBarElement)
1548         {
1549                 __pAccessibilitySearchBarElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
1550         }
1551         return;
1552 }
1553
1554 void
1555 _SearchBar::OnChangeLayout(_ControlOrientation orientation)
1556 {
1557         __isupdateContentBounds = true;
1558         return;
1559 }
1560
1561 void
1562 _SearchBar::OnDraw(void)
1563 {
1564         if (!__isUserGuideTextColor)
1565         {
1566                 SearchFieldStatus status = GetCurrentStatus();
1567                 __pEdit->SetGuideTextColor(__guideTextColor[status]);
1568         }
1569
1570         if (__isupdateContentBounds)
1571         {
1572                 SetContentsArea();
1573                 __isupdateContentBounds = false;
1574         }
1575         __pSearchBarPresenter->Draw();
1576         return;
1577 }
1578
1579 _UiTouchEventDelivery
1580 _SearchBar::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1581 {
1582         _Edit* pEdit = dynamic_cast <_Edit*>(const_cast <_Control*>(&source));
1583         if (pEdit == null)
1584         {
1585                 return _UI_TOUCH_EVENT_DELIVERY_YES;
1586         }
1587
1588         if (GetMode() == SEARCH_BAR_MODE_INPUT)
1589         {
1590                 return _UI_TOUCH_EVENT_DELIVERY_YES;
1591         }
1592
1593         return _UI_TOUCH_EVENT_DELIVERY_YES;
1594 }
1595
1596 void
1597 _SearchBar::OnActionPerformed(const _Control& source, int actionId)
1598 {
1599         if (__actionId == actionId)
1600         {
1601                 __isCancelActionInProgress = true;
1602                 SetMode(SEARCH_BAR_MODE_NORMAL);
1603
1604                 if (__pActionEvent)
1605                 {
1606                         IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(__actionId);
1607                         result r = GetLastResult();
1608                         SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1609
1610                         __pActionEvent->Fire(*pEventArg);
1611                 }
1612                 __isCancelActionInProgress = false;
1613         }
1614         return;
1615 }
1616
1617 // Keypad callbacks
1618 void
1619 _SearchBar::OnKeypadWillOpen(void)
1620 {
1621         if (!__isKeypadOpening)
1622         {
1623                 if (__pKeypadEvent)
1624                 {
1625                         IEventArg* pEventArg = _KeypadEvent::CreateKeypadEventArgN(CORE_KEYPAD_ACTION_SEARCH, CORE_KEYPAD_EVENT_STATUS_CREATED);
1626                         result r = GetLastResult();
1627                         SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1628
1629                         __pKeypadEvent->Fire(*pEventArg);
1630                 }
1631         }
1632
1633         __isKeypadOpening = true;
1634         return;
1635 }
1636
1637 void
1638 _SearchBar::OnKeypadOpened(void)
1639 {
1640         if (__pKeypadEvent)
1641         {
1642                 IEventArg* pEventArg = _KeypadEvent::CreateKeypadEventArgN(CORE_KEYPAD_ACTION_SEARCH, CORE_KEYPAD_EVENT_STATUS_OPEN);
1643                 result r = GetLastResult();
1644                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1645
1646                 __pKeypadEvent->Fire(*pEventArg);
1647         }
1648
1649         __isKeypadOpening = false;
1650         SetContentsArea();
1651         return;
1652 }
1653
1654 void
1655 _SearchBar::OnKeypadClosed(void)
1656 {
1657         if (__pKeypadEvent)
1658         {
1659                 IEventArg* pEventArg = _KeypadEvent::CreateKeypadEventArgN(CORE_KEYPAD_ACTION_SEARCH, CORE_KEYPAD_EVENT_STATUS_CLOSE);
1660                 result r = GetLastResult();
1661                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1662
1663                 __pKeypadEvent->Fire(*pEventArg);
1664         }
1665
1666         __isKeypadOpening = false;
1667
1668         SetContentsArea();
1669         return;
1670 }
1671
1672 void
1673 _SearchBar::OnKeypadBoundsChanged(void)
1674 {
1675         if (__pKeypadEvent)
1676         {
1677                 IEventArg* pEventArg = _KeypadEvent::CreateKeypadEventArgN(CORE_KEYPAD_ACTION_SEARCH, CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
1678                 result r = GetLastResult();
1679                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1680
1681                 __pKeypadEvent->Fire(*pEventArg);
1682         }
1683
1684         SetContentsArea();
1685         return;
1686 }
1687
1688 void
1689 _SearchBar::OnKeypadActionPerformed(CoreKeypadAction keypadAction)
1690 {
1691         if (__pKeypadEvent)
1692         {
1693                 IEventArg* pEventArg = _KeypadEvent::CreateKeypadEventArgN(keypadAction, CORE_KEYPAD_EVENT_STATUS_ENTERACTION);
1694                 result r = GetLastResult();
1695                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1696
1697                 __pKeypadEvent->Fire(*pEventArg);
1698         }
1699         return;
1700 }
1701
1702 // TextBlock callbacks
1703 void
1704 _SearchBar::OnTextBlockSelected(_Control& source, int start, int end)
1705 {
1706         if (__pTextBlockEvent)
1707         {
1708                 IEventArg* pEventArg = _TextBlockEvent::CreateTextBlockEventArgN(start, end);
1709                 result r = GetLastResult();
1710                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1711
1712                 __pTextBlockEvent->Fire(*pEventArg);
1713         }
1714         return;
1715 }
1716
1717 // Text callbacks
1718 void
1719 _SearchBar::OnTextValueChanged(const _Control& source)
1720 {
1721         if (!__isCancelActionInProgress)
1722         {
1723                 SetContentDimming();
1724                 if (__pTextEvent != null)
1725                 {
1726                         IEventArg* pEventArg = _TextEvent::CreateTextEventArgN(CORE_TEXT_EVENT_CHANGED);
1727                         result r = GetLastResult();
1728                         SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1729
1730                         __pTextEvent->Fire(*pEventArg);
1731                 }
1732         }
1733         return;
1734 }
1735
1736 void
1737 _SearchBar::OnTextValueChangeCanceled(const _Control& source)
1738 {
1739         if (__pTextEvent != null)
1740         {
1741                 IEventArg* pEventArg = _TextEvent::CreateTextEventArgN(CORE_TEXT_EVENT_CANCELED);
1742                 result r = GetLastResult();
1743                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1744
1745                 __pTextEvent->Fire(*pEventArg);
1746         }
1747         return;
1748 }
1749
1750 result
1751 _SearchBar::OnAttachedToMainTree(void)
1752 {
1753         SetContentsArea();
1754         return E_SUCCESS;
1755 }
1756
1757 void
1758 _SearchBar::OnFontChanged(Font* pFont)
1759 {
1760         __pCancelButton->SetFont(pFont->GetFaceName());
1761         __pEdit->SetFont(*pFont);
1762         return;
1763 }
1764
1765 void
1766 _SearchBar::OnFontInfoRequested(unsigned long& style, int& size)
1767 {
1768         style = FONT_STYLE_PLAIN;
1769         size = __pCancelButton->GetTextSize();
1770
1771         return;
1772 }
1773
1774 bool
1775 _SearchBar::OnFocusGained(const _Control& source)
1776 {
1777         if (__isKeyPressed)
1778         {
1779                 __isKeyPressed = false;
1780                 _Control::OnDrawFocus();
1781
1782                 return true;
1783         }
1784
1785         if (GetVisibleState() == true)
1786         {
1787                 __pEdit->SetFocused();
1788         }
1789
1790         return true;
1791 }
1792
1793 bool
1794 _SearchBar::OnFocusLost(const _Control &source)
1795 {
1796         __pEdit->SetSearchFieldFocus(false);
1797         _Control::OnFocusLost(source);
1798         return true;
1799 }
1800
1801 bool
1802 _SearchBar::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1803 {
1804         _KeyCode keyCode = keyInfo.GetKeyCode();
1805
1806         if (keyCode == _KEY_RIGHT)
1807         {
1808                 if (GetMode() == SEARCH_BAR_MODE_NORMAL)
1809                 {
1810                         __pEdit->SetFocused();
1811                         return true;
1812                 }
1813
1814                 if (!__isButtonEnabled || __pCancelButton->IsFocused() || !__isUsableCancelButton)
1815                 {
1816                         return true;
1817                 }
1818
1819                 SetFocusCallBackParameter(false);
1820                 __pCancelButton->SetFocused();
1821                 __pCancelButton->Invalidate(true);
1822
1823                 return true;
1824         }
1825
1826         if (keyCode == _KEY_LEFT)
1827         {
1828                 if (__pCancelButton->GetButtonStatus() == _BUTTON_STATUS_HIGHLIGHTED)
1829                 {
1830                         __pCancelButton->Invalidate();
1831                         __pEdit->SetFocused();
1832                 }
1833
1834                 if (__pCancelButton->GetButtonStatus() == _BUTTON_STATUS_DISABLED)      //Searchbar Button is disabled, left arrow key is pressed
1835                 {
1836                         __pEdit->SetFocused();
1837                 }
1838
1839                 return true;
1840         }
1841
1842         if (keyCode == _KEY_ENTER || keyCode == _KEY_TAB)
1843         {
1844                 if (GetMode() == SEARCH_BAR_MODE_NORMAL)
1845                 {
1846                         return false;
1847                 }
1848
1849                 SetMode(SEARCH_BAR_MODE_NORMAL);
1850                 __isKeyPressed = true;
1851                 SetFocused();
1852
1853                 return true;
1854         }
1855
1856         return false;
1857 }
1858
1859 void
1860 _SearchBar::OnSettingChanged(Tizen::Base::String& key)
1861 {
1862         if (__isButtonTextChangedByApp || !__isUsableCancelButton)
1863         {
1864                 return;
1865         }
1866
1867         if (key.Equals(L"http://tizen.org/setting/locale.language", false))
1868         {
1869                 String cancelText;
1870                 GET_STRING_CONFIG(IDS_COM_SK_CANCEL, cancelText);
1871                 __pCancelButton->SetText(cancelText);
1872                 __pCancelButton->Invalidate();
1873         }
1874
1875         return;
1876 }
1877
1878 _Control*
1879 _SearchBar::GetParentForm(void) const
1880 {
1881         _Form* pForm = null;
1882         _Control* pControlCore = GetParent();
1883
1884         while (true)
1885         {
1886                 if (pControlCore == null)
1887                 {
1888                         SysLog(NID_UI_CTRL,"[E_SYSTEM] The parent form is null.");
1889
1890                         return null;
1891                 }
1892
1893                 pForm = dynamic_cast <_Form*>(pControlCore);
1894
1895                 if (pForm != null)
1896                 {
1897                         break;
1898                 }
1899
1900                 pControlCore = pControlCore->GetParent();
1901         }
1902
1903         return pControlCore;
1904 }
1905
1906 _Button*
1907 _SearchBar::GetSearchBarButton(void) const
1908 {
1909         return __pCancelButton;
1910 }
1911
1912 _Edit*
1913 _SearchBar::GetSearchField(void)
1914 {
1915         return __pEdit;
1916 }
1917
1918 _Control*
1919 _SearchBar::GetSearchBarContainer(void) const
1920 {
1921         return __pContainer;
1922 }
1923
1924 _Control*
1925 _SearchBar::GetClippedGroupControl(void) const
1926 {
1927         return __pClippedGroupControl;
1928 }
1929
1930 bool
1931 _SearchBar::IsUsableCancelButton(void) const
1932 {
1933         return __isUsableCancelButton;
1934 }
1935
1936 EditStatus
1937 _SearchBar::ConvertSearchBarStatus(SearchFieldStatus status)
1938 {
1939         EditStatus editStatus = EDIT_STATUS_NORMAL;
1940         switch (status)
1941         {
1942         case SEARCH_FIELD_STATUS_NORMAL:
1943                 editStatus = EDIT_STATUS_NORMAL;
1944                 break;
1945
1946         case SEARCH_FIELD_STATUS_DISABLED:
1947                 editStatus = EDIT_STATUS_DISABLED;
1948                 break;
1949
1950         case SEARCH_FIELD_STATUS_HIGHLIGHTED:
1951                 editStatus = EDIT_STATUS_HIGHLIGHTED;
1952                 break;
1953         default:
1954                 break;
1955         }
1956
1957         return editStatus;
1958 }
1959
1960 _ButtonStatus
1961 _SearchBar::ConvertSearchBarButtonStatus(SearchBarButtonStatus status)
1962 {
1963         _ButtonStatus buttonStatus = _BUTTON_STATUS_NORMAL;
1964
1965         switch (status)
1966         {
1967         case SEARCH_BAR_BUTTON_STATUS_NORMAL:
1968                 buttonStatus = _BUTTON_STATUS_NORMAL;
1969                 break;
1970
1971         case SEARCH_BAR_BUTTON_STATUS_PRESSED:
1972                 buttonStatus = _BUTTON_STATUS_PRESSED;
1973                 break;
1974
1975         case SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED:
1976                 buttonStatus = _BUTTON_STATUS_HIGHLIGHTED;
1977                 break;
1978
1979         case SEARCH_BAR_BUTTON_STATUS_DISABLED:
1980                 buttonStatus = _BUTTON_STATUS_DISABLED;
1981                 break;
1982         default:
1983                 break;
1984         }
1985
1986         return buttonStatus;
1987 }
1988
1989 result
1990 _SearchBar::SendSearchBarEvent(_SearchBarEventStatus status)
1991 {
1992         result r = E_SUCCESS;
1993         if (__pSearchBarEvent)
1994         {
1995                 IEventArg* pEventArg = _SearchBarEvent::CreateSearchBarEventArgN(status);
1996                 r = GetLastResult();
1997                 SysTryReturn(NID_UI_CTRL, pEventArg, r, r, "[%s] Propagating.", GetErrorMessage(r));
1998
1999                 if (IsContentAreaVisible() == false)
2000                 {
2001                         SetContentAreaVisible(false);
2002                 }
2003
2004                 __pSearchBarEvent->Fire(*pEventArg);
2005         }
2006
2007         return E_SUCCESS;
2008 }
2009
2010 void
2011 _SearchBar::SetHeaderVisibleState(bool visible)
2012 {
2013         if (__pSearchBarPresenter != null)
2014         {
2015                 __pSearchBarPresenter->SetHeaderVisibleState(visible);
2016         }
2017         return;
2018 }
2019
2020 result
2021 _SearchBar::SetPropertyButtonActionId(const Variant& actionId)
2022 {
2023         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2024                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2025         SysTryReturn(NID_UI_CTRL, actionId.ToInt() > -1, E_INVALID_ARG, E_INVALID_ARG,
2026                      "[E_INVALID_ARG] Invalid argument(s) is used. actionId.ToInt() = %d", actionId.ToInt());
2027
2028         result r = E_SUCCESS;
2029
2030         r = __pCancelButton->SetPropertyActionId(actionId);
2031         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2032                      "[%s] A system error has occurred. Failed to set actionId.", GetErrorMessage(E_SYSTEM));
2033
2034         __actionId = actionId.ToInt();
2035
2036         return r;
2037 }
2038
2039 Variant
2040 _SearchBar::GetPropertyButtonActionId(void) const
2041 {
2042         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(-1), E_SYSTEM,
2043                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2044
2045         return Variant(__actionId);
2046 }
2047
2048 result
2049 _SearchBar::SetPropertyButtonDisabledColor(const Variant& color)
2050 {
2051         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2052                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2053
2054         result r = E_SUCCESS;
2055
2056         r = __pCancelButton->SetPropertyDisabledColor(color);
2057         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2058                      "[E_SYSTEM] A system error has occurred. Failed to set button color.");
2059
2060         __buttonColor[SEARCH_BAR_BUTTON_STATUS_DISABLED] = color.ToColor();
2061
2062         return r;
2063 }
2064
2065 Variant
2066 _SearchBar::GetPropertyButtonDisabledColor(void) const
2067 {
2068         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2069                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2070
2071         return Variant(__buttonColor[SEARCH_BAR_BUTTON_STATUS_DISABLED]);
2072 }
2073
2074 result
2075 _SearchBar::SetPropertyButtonHighlightedColor(const Variant& color)
2076 {
2077         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2078                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2079
2080         result r = E_SUCCESS;
2081
2082         r = __pCancelButton->SetPropertyHighlightedColor(color);
2083         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2084                      "[E_SYSTEM] A system error has occurred. Failed to set button color.");
2085
2086         __buttonColor[SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED] = color.ToColor();
2087
2088         return r;
2089 }
2090
2091 Variant
2092 _SearchBar::GetPropertyButtonHighlightedColor(void) const
2093 {
2094         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2095                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2096
2097         return Variant(__buttonColor[SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED]);
2098 }
2099
2100 result
2101 _SearchBar::SetPropertyButtonNormalColor(const Variant& color)
2102 {
2103         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2104                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2105
2106         result r = E_SUCCESS;
2107
2108         r = __pCancelButton->SetPropertyNormalColor(color);
2109         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2110                      "[E_SYSTEM] A system error has occurred. Failed to set button color.");
2111
2112         __buttonColor[SEARCH_BAR_BUTTON_STATUS_NORMAL] = color.ToColor();
2113
2114         return r;
2115 }
2116
2117 Variant
2118 _SearchBar::GetPropertyButtonNormalColor(void) const
2119 {
2120         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2121                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2122
2123         return Variant(__buttonColor[SEARCH_BAR_BUTTON_STATUS_NORMAL]);
2124 }
2125
2126 result
2127 _SearchBar::SetPropertyButtonPressedColor(const Variant& color)
2128 {
2129         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2130                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2131
2132         result r = E_SUCCESS;
2133
2134         r = __pCancelButton->SetPropertyPressedColor(color);
2135         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2136                      "[E_SYSTEM] A system error has occurred. Failed to set button color.");
2137
2138         __buttonColor[SEARCH_BAR_BUTTON_STATUS_PRESSED] = color.ToColor();
2139
2140         return r;
2141 }
2142
2143 Variant
2144 _SearchBar::GetPropertyButtonPressedColor(void) const
2145 {
2146         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2147                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2148
2149         return Variant(__buttonColor[SEARCH_BAR_BUTTON_STATUS_PRESSED]);
2150 }
2151
2152 result
2153 _SearchBar::SetPropertyButtonDisabledTextColor(const Variant& textColor)
2154 {
2155         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2156                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2157
2158         result r = E_SUCCESS;
2159
2160         r = __pCancelButton->SetPropertyDisabledTextColor(textColor);
2161         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2162                      "[E_SYSTEM] A system error has occurred. Failed to set button text color.");
2163
2164         __buttonTextColor[SEARCH_BAR_BUTTON_STATUS_DISABLED] = textColor.ToColor();
2165
2166         return r;
2167 }
2168
2169 Variant
2170 _SearchBar::GetPropertyButtonDisabledTextColor(void) const
2171 {
2172         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2173                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2174
2175         return Variant(__buttonTextColor[SEARCH_BAR_BUTTON_STATUS_DISABLED]);
2176 }
2177
2178 result
2179 _SearchBar::SetPropertyButtonHighlightedTextColor(const Variant& textColor)
2180 {
2181         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2182                      "[E_SYSTEM]] A system error has occurred. The cancel button instance is null.");
2183
2184         result r = E_SUCCESS;
2185
2186         r = __pCancelButton->SetPropertyHighlightedTextColor(textColor);
2187         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2188                      "[E_SYSTEM] A system error has occurred. Failed to set button text color.");
2189
2190         __buttonTextColor[SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED] = textColor.ToColor();
2191
2192         return r;
2193 }
2194
2195 Variant
2196 _SearchBar::GetPropertyButtonHighlightedTextColor(void) const
2197 {
2198         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2199                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2200
2201         return Variant(__buttonTextColor[SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED]);
2202 }
2203
2204 result
2205 _SearchBar::SetPropertyButtonNormalTextColor(const Variant& textColor)
2206 {
2207         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2208                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2209
2210         result r = E_SUCCESS;
2211
2212         r = __pCancelButton->SetPropertyNormalTextColor(textColor);
2213         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2214                      "[E_SYSTEM] A system error has occurred. Failed to set button text color.");
2215
2216         __buttonTextColor[SEARCH_BAR_BUTTON_STATUS_NORMAL] = textColor.ToColor();
2217
2218         return r;
2219 }
2220
2221 Variant
2222 _SearchBar::GetPropertyButtonNormalTextColor(void) const
2223 {
2224         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2225                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2226
2227         return Variant(__buttonTextColor[SEARCH_BAR_BUTTON_STATUS_NORMAL]);
2228 }
2229
2230 result
2231 _SearchBar::SetPropertyButtonPressedTextColor(const Variant& textColor)
2232 {
2233         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2234                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2235
2236         result r = E_SUCCESS;
2237
2238         r = __pCancelButton->SetPropertyPressedTextColor(textColor);
2239         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2240                      "[E_SYSTEM] A system error has occurred. Failed to set button text color.");
2241
2242         __buttonTextColor[SEARCH_BAR_BUTTON_STATUS_PRESSED] = textColor.ToColor();
2243
2244         return r;
2245 }
2246
2247 Variant
2248 _SearchBar::GetPropertyButtonPressedTextColor(void) const
2249 {
2250         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2251                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2252
2253         return Variant(__buttonTextColor[SEARCH_BAR_BUTTON_STATUS_PRESSED]);
2254 }
2255
2256 result
2257 _SearchBar::SetPropertySearchFieldDisabledColor(const Variant& color)
2258 {
2259         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
2260                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2261
2262         result r = E_SUCCESS;
2263
2264         r = __pEdit->SetPropertyDisabledColor(color);
2265         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2266                      "[E_SYSTEM] A system error has occurred. Failed to set the edit disabled color.");
2267
2268         __color[SEARCH_FIELD_STATUS_DISABLED] = color.ToColor();
2269
2270         return r;
2271 }
2272
2273 Variant
2274 _SearchBar::GetPropertySearchFieldDisabledColor(void) const
2275 {
2276         SysTryReturn(NID_UI_CTRL, __pEdit, Variant(Color()), E_SYSTEM,
2277                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2278
2279         return Variant(__color[SEARCH_FIELD_STATUS_DISABLED]);
2280 }
2281
2282 result
2283 _SearchBar::SetPropertySearchFieldHighlightedColor(const Variant& color)
2284 {
2285         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
2286                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2287
2288         result r = E_SUCCESS;
2289
2290         r = __pEdit->SetPropertyHighlightedColor(color);
2291         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2292                      "[E_SYSTEM] A system error has occurred. Failed to set the edit highlighted color.");
2293
2294         __color[SEARCH_FIELD_STATUS_HIGHLIGHTED] = color.ToColor();
2295
2296         return r;
2297 }
2298
2299 Variant
2300 _SearchBar::GetPropertySearchFieldHighlightedColor(void) const
2301 {
2302         SysTryReturn(NID_UI_CTRL, __pEdit, Variant(Color()), E_SYSTEM,
2303                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2304
2305         return Variant(__color[SEARCH_FIELD_STATUS_HIGHLIGHTED]);
2306 }
2307
2308 result
2309 _SearchBar::SetPropertySearchFieldNormalColor(const Variant& color)
2310 {
2311         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
2312                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2313
2314         result r = E_SUCCESS;
2315
2316         r = __pEdit->SetPropertyNormalColor(color);
2317         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2318                      "[E_SYSTEM] A system error has occurred. Failed to set edit normal color.");
2319
2320         __color[SEARCH_FIELD_STATUS_NORMAL] = color.ToColor();
2321
2322         return r;
2323 }
2324
2325 Variant
2326 _SearchBar::GetPropertySearchFieldNormalColor(void) const
2327 {
2328         SysTryReturn(NID_UI_CTRL, __pEdit, Variant(Color()), E_SYSTEM,
2329                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2330
2331         return Variant(__color[SEARCH_FIELD_STATUS_NORMAL]);
2332 }
2333
2334 result
2335 _SearchBar::SetPropertySearchFieldDisabledTextColor(const Variant& textColor)
2336 {
2337         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
2338                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2339
2340         result r = E_SUCCESS;
2341
2342         r = __pEdit->SetPropertyDisabledTextColor(textColor);
2343         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2344                      "[E_SYSTEM] A system error has occurred. Failed to set edit disabled text color.");
2345
2346         __textColor[SEARCH_FIELD_STATUS_DISABLED] = textColor.ToColor();
2347
2348         return r;
2349 }
2350
2351 Variant
2352 _SearchBar::GetPropertySearchFieldDisabledTextColor(void) const
2353 {
2354         SysTryReturn(NID_UI_CTRL, __pEdit, Variant(Color()), E_SYSTEM,
2355                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2356
2357         return Variant(__textColor[SEARCH_FIELD_STATUS_DISABLED]);
2358 }
2359
2360 result
2361 _SearchBar::SetPropertySearchFieldHighlightedTextColor(const Variant& textColor)
2362 {
2363         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
2364                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2365
2366         result r = E_SUCCESS;
2367
2368         r = __pEdit->SetPropertyHighlightedTextColor(textColor);
2369         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2370                      "[E_SYSTEM] A system error has occurred. Failed to set edit highlighted text color.");
2371
2372         __textColor[SEARCH_FIELD_STATUS_HIGHLIGHTED] = textColor.ToColor();
2373
2374         return r;
2375 }
2376
2377 Variant
2378 _SearchBar::GetPropertySearchFieldHighlightedTextColor(void) const
2379 {
2380         SysTryReturn(NID_UI_CTRL, __pEdit, Variant(Color()), E_SYSTEM,
2381                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2382
2383         return Variant(__textColor[SEARCH_FIELD_STATUS_HIGHLIGHTED]);
2384 }
2385
2386 result
2387 _SearchBar::SetPropertySearchFieldNormalTextColor(const Variant& textColor)
2388 {
2389         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
2390                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2391
2392         result r = E_SUCCESS;
2393
2394         r = __pEdit->SetPropertyNormalTextColor(textColor);
2395         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2396                      "[E_SYSTEM] A system error has occurred. Failed to set edit normal text color.");
2397
2398         __textColor[SEARCH_FIELD_STATUS_NORMAL] = textColor.ToColor();
2399
2400         return r;
2401 }
2402
2403 Variant
2404 _SearchBar::GetPropertySearchFieldNormalTextColor(void) const
2405 {
2406         SysTryReturn(NID_UI_CTRL, __pEdit, Variant(Color()), E_SYSTEM,
2407                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2408
2409         return Variant(__textColor[SEARCH_FIELD_STATUS_NORMAL]);
2410 }
2411
2412 result
2413 _SearchBar::SetPropertyColor(const Variant& color)
2414 {
2415         __backgroundColor = color.ToColor();
2416
2417         return E_SUCCESS;
2418 }
2419
2420 Variant
2421 _SearchBar::GetPropertyColor(void) const
2422 {
2423         return Variant(__backgroundColor);
2424 }
2425
2426 result
2427 _SearchBar::SetPropertyContentAreaSize(const Variant& size)
2428 {
2429         FloatDimension contentAreaSize = size.ToFloatDimension();
2430         SysTryReturn(NID_UI_CTRL, contentAreaSize.width >= 0 && contentAreaSize.height >= 0, E_INVALID_ARG, E_INVALID_ARG,
2431                      "[E_INVALID_ARG] Invalid argument(s) is used. contentAreaSize.width = %f, contenAreaSize.height = %f",
2432                      contentAreaSize.width, contentAreaSize.height);
2433
2434         result r = E_SUCCESS;
2435
2436         // Todo
2437         FloatRectangle bounds = GetBoundsF();
2438         FloatRectangle contentAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
2439
2440         contentAreaBounds.x = 0.0f;
2441         contentAreaBounds.y = bounds.height;
2442         contentAreaBounds.width = contentAreaSize.width;
2443         contentAreaBounds.height = contentAreaSize.height;
2444
2445         __contentAreaBounds = contentAreaBounds;
2446         __isUserContainerBounds = true;
2447
2448         // set bounds
2449         if (__pContainer)
2450         {
2451                 r = __pContainer->SetBounds(__contentAreaBounds);
2452                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2453         }
2454
2455         return r;
2456 }
2457
2458 Variant
2459 _SearchBar::GetPropertyContentAreaSize(void) const
2460 {
2461         FloatDimension contentAreaSize(__contentAreaBounds.width, __contentAreaBounds.height);
2462
2463         return Variant(contentAreaSize);
2464 }
2465
2466 result
2467 _SearchBar::CreateClippedGroupControl(void)
2468 {
2469         result r = E_SUCCESS;
2470         FloatRectangle clippedGroupControlBounds(FloatPoint(0.0f, 0.0f), GetSizeF());
2471         __pClippedGroupControl = _Control::CreateControlN();
2472         r = GetLastResult();
2473         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2474
2475         r = AttachChild(*__pClippedGroupControl);
2476         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
2477                     "[E_SYSTEM] A system error has occurred. Failed to attach the parent of clipped control.");
2478
2479         r = __pClippedGroupControl->SetBounds(clippedGroupControlBounds);
2480         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2481
2482         __pClippedGroupControl->SetBackgroundColor(Color(0));
2483
2484         __pClippedGroupControl->SetClipChildrenEnabled(true);
2485
2486         return r;
2487
2488 CATCH:
2489         delete __pClippedGroupControl;
2490         __pClippedGroupControl = null;
2491
2492         return r;
2493
2494 }
2495
2496 void
2497 _SearchBar::CreateAccessibilityElement(void)
2498 {
2499         if (__pAccessibilitySearchBarElement != null)
2500         {
2501                 return;
2502         }
2503         _AccessibilityContainer* pContainer = null;
2504         pContainer = GetAccessibilityContainer();
2505
2506         if (pContainer)
2507         {
2508                 __pAccessibilitySearchBarElement = new (std::nothrow) _AccessibilityElement(true);
2509                 SysTryReturnVoidResult(NID_UI_CTRL, __pAccessibilitySearchBarElement, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
2510                 __pAccessibilitySearchBarElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
2511                 __pAccessibilitySearchBarElement->SetTrait(ACCESSIBILITY_TRAITS_NONE);
2512                 __pAccessibilitySearchBarElement->SetName("SearchBar");
2513                 pContainer->AddElement(*__pAccessibilitySearchBarElement);
2514         }
2515
2516         return;
2517 }
2518
2519 void
2520 _SearchBar::SetContentDimming(void)
2521 {
2522         if (__pContainer != NULL)
2523         {
2524                 if (!GetTextLength())
2525                 {
2526                         __contentColor.SetAlpha(_SEARCH_CONTENT_DIM_OPACITY);
2527                 }
2528                 else
2529                 {
2530                         __contentColor.SetAlpha(0);
2531                 }
2532                 __pContainer->SetBackgroundColor(__contentColor);
2533         }
2534         return;
2535 }
2536
2537 void
2538 _SearchBar::OnDrawFocus(void)
2539 {
2540         __pEdit->SetSearchFieldFocus(true);
2541         return;
2542 }
2543
2544 bool
2545 _SearchBar::IsContentAttachable(const _Control* pContent)
2546 {
2547         const _Window* pWindow = dynamic_cast <const _Window*>(pContent);
2548         const _ColorPicker* pColorPicker = dynamic_cast <const _ColorPicker*>(pContent);
2549         const _Form* pForm = dynamic_cast <const _Form*>(pContent);
2550         const _Keypad* pKeypad = dynamic_cast <const _Keypad*>(pContent);
2551         const _OverlayPanel* pOverlayPanel = dynamic_cast <const _OverlayPanel*>(pContent);
2552
2553         bool isContentAttachable = true;
2554
2555         isContentAttachable = ((pWindow == null) && (pColorPicker == null) &&
2556                                (pForm == null) && (pKeypad == null) && (pOverlayPanel == null));
2557         return isContentAttachable;
2558 }
2559
2560 result
2561 _SearchBar::ResizeCancelButton(void)
2562 {
2563         result r = E_SUCCESS;
2564
2565         float horizontalMargin = 0.0f;
2566         float buttonLeftMargin = 0.0f;
2567         float buttonRightMargin = 0.0f;
2568         float buttonMinWidth = 0.0f;
2569         float searchFieldMinWidth = 0.0f;
2570         float buttonVerticalMargin = 0.0f;
2571         float searchBarMinHeight = 0.0f;
2572         float buttonWidth = 0.0f;
2573         float buttonHeight = 0.0f;
2574
2575         FloatRectangle cancelButtonBounds;
2576         FloatRectangle searchBarBounds = GetBoundsF();
2577
2578         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
2579
2580         GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
2581         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_LEFT_MARGIN, orientation, buttonLeftMargin);
2582         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_RIGHT_MARGIN, orientation, buttonRightMargin);
2583         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
2584         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_HEIGHT, orientation, buttonHeight);
2585         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_MIN_WIDTH, orientation, buttonMinWidth);
2586         GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH, orientation, searchFieldMinWidth);
2587         GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, buttonVerticalMargin);
2588         GET_SHAPE_CONFIG(SEARCHBAR::MIN_HEIGHT, orientation, searchBarMinHeight);
2589
2590         cancelButtonBounds.width = buttonWidth;
2591         cancelButtonBounds.height = buttonHeight;
2592
2593         float buttonResizableSearchBarWidth = (horizontalMargin + searchFieldMinWidth +
2594                                              cancelButtonBounds.width + buttonLeftMargin + buttonRightMargin);
2595
2596         if (searchBarBounds.width < buttonResizableSearchBarWidth)
2597         {
2598                 cancelButtonBounds.width = searchBarBounds.width -(searchFieldMinWidth + buttonLeftMargin
2599                                                                    + buttonRightMargin + horizontalMargin);
2600         }
2601
2602         cancelButtonBounds.x = searchBarBounds.width - cancelButtonBounds.width - buttonRightMargin;
2603         cancelButtonBounds.y = (searchBarBounds.height - cancelButtonBounds.height)/2.0f;
2604
2605         cancelButtonBounds.y = cancelButtonBounds.y < 0.0f ? 0.0f:cancelButtonBounds.y;
2606
2607         if (cancelButtonBounds.width < buttonMinWidth)
2608         {
2609                 cancelButtonBounds.width = buttonMinWidth;
2610         }
2611
2612         cancelButtonBounds.width = (cancelButtonBounds.width > 0.0f) ? cancelButtonBounds.width : 0.0f;
2613         cancelButtonBounds.height = (cancelButtonBounds.height > 0.0f) ? cancelButtonBounds.height : 0.0f;
2614         r = __pCancelButton->SetBounds(cancelButtonBounds);
2615
2616         return r;
2617 }
2618
2619 void
2620 _SearchBar::RecalculateButtonBounds(void)
2621 {
2622         result r = E_SUCCESS;
2623
2624         float horizontalMargin = 0.0f;
2625         float verticalMargin = 0.0f;
2626         float buttonLeftMargin = 0.0f;
2627         float buttonRightMargin = 0.0f;
2628         float buttonMinWidth = 0.0f;
2629         float searchFieldMinWidth = 0.0f;
2630         float buttonVerticalMargin = 0.0f;
2631         float searchBarMinHeight = 0.0f;
2632         float buttonWidth = 0.0f;
2633         float buttonHeight = 0.0f;
2634         float cancelButtonWidth = 0.0f;
2635
2636         FloatRectangle cancelButtonBounds;
2637         FloatRectangle editBounds;
2638         FloatRectangle searchBarBounds = GetBoundsF();
2639
2640         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
2641
2642         GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
2643         GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, verticalMargin);
2644         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_LEFT_MARGIN, orientation, buttonLeftMargin);
2645         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_RIGHT_MARGIN, orientation, buttonRightMargin);
2646         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
2647         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_HEIGHT, orientation, buttonHeight);
2648         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_MIN_WIDTH, orientation, buttonMinWidth);
2649         GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH, orientation, searchFieldMinWidth);
2650         GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, buttonVerticalMargin);
2651         GET_SHAPE_CONFIG(SEARCHBAR::MIN_HEIGHT, orientation, searchBarMinHeight);
2652
2653         cancelButtonBounds.height = buttonHeight;
2654
2655         float searchFieldMinHeight = searchBarMinHeight - (verticalMargin * 2.0f);
2656         cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
2657         editBounds.x = horizontalMargin;
2658
2659         if (searchBarBounds.height < searchBarMinHeight)
2660         {
2661                 verticalMargin = (searchBarBounds.height - searchFieldMinHeight)/2.0f;
2662                 if (verticalMargin < 0.0f)
2663                 {
2664                         verticalMargin = 0.0f;
2665                 }
2666         }
2667
2668         editBounds.y = verticalMargin;
2669         editBounds.height = searchBarBounds.height - (editBounds.y * 2.0f);
2670
2671         editBounds.height = (editBounds.height > searchFieldMinHeight) ? editBounds.height : searchFieldMinHeight;
2672
2673         editBounds.width = searchBarBounds.width - cancelButtonWidth - horizontalMargin - buttonLeftMargin - buttonRightMargin;
2674
2675         if (editBounds.width < searchFieldMinWidth)
2676         {
2677                 editBounds.width = searchFieldMinWidth;
2678         }
2679
2680         cancelButtonBounds.x = editBounds.width + horizontalMargin + buttonLeftMargin;
2681         cancelButtonBounds.y = (searchBarBounds.height - cancelButtonBounds.height)/2.0f;
2682
2683         cancelButtonBounds.y = cancelButtonBounds.y < 0.0f ? 0.0f:cancelButtonBounds.y;
2684
2685         float remainingWidth = searchBarBounds.width - editBounds.width - horizontalMargin - buttonLeftMargin - buttonRightMargin;
2686
2687         if (remainingWidth < buttonMinWidth)
2688         {
2689                 cancelButtonBounds.width = buttonMinWidth;
2690         }
2691         else
2692         {
2693                 cancelButtonBounds.width = searchBarBounds.width - cancelButtonBounds.x - buttonRightMargin;
2694         }
2695
2696         cancelButtonBounds.width = (cancelButtonBounds.width > 0.0f) ? cancelButtonBounds.width : 0.0f;
2697         cancelButtonBounds.height = (cancelButtonBounds.height > 0.0f) ? cancelButtonBounds.height : 0.0f;
2698
2699         r = __pCancelButton->SetBounds(cancelButtonBounds);
2700         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2701         r = __pEdit->SetBounds(editBounds);
2702         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2703
2704         return;
2705 }
2706
2707 SearchFieldStatus
2708 _SearchBar::GetCurrentStatus(void)
2709 {
2710         SearchFieldStatus searchFieldStatus = SEARCH_FIELD_STATUS_NORMAL;
2711
2712         if (IsEnabled())
2713         {
2714                 if (__pEdit->IsFocused())
2715                 {
2716                         searchFieldStatus = SEARCH_FIELD_STATUS_HIGHLIGHTED;
2717                 }
2718         }
2719         else
2720         {
2721                 searchFieldStatus = SEARCH_FIELD_STATUS_DISABLED;
2722         }
2723
2724         return searchFieldStatus;
2725 }
2726
2727 void
2728 _SearchBar::SetEditTextFilter(IEditTextFilter* pFilter)
2729 {
2730         SysTryReturnVoidResult(NID_UI_CTRL, __pEdit, E_SYSTEM,
2731                                "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2732
2733         __pEdit->SetEditTextFilter(pFilter);
2734
2735         return;
2736 }
2737
2738 void
2739 _SearchBar::SendOpaqueCommand(const String& command)
2740 {
2741         SysTryReturnVoidResult(NID_UI_CTRL, __pEdit, E_SYSTEM,
2742                                "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2743
2744         __pEdit->SendOpaqueCommand(command);
2745
2746         return;
2747 }
2748
2749 void
2750 _SearchBar::SetFocusCallBackParameter(bool state)
2751 {
2752         __isFocusCallbackToBeFired = state;
2753         return;
2754 }
2755
2756 bool
2757 _SearchBar::IsFocusCallBackToBeFired(void) const
2758 {
2759         return __isFocusCallbackToBeFired;
2760 }
2761 }}} // Tizen::Ui::Controls