Merge "fixed bug" into tizen_2.1
[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         __isButtonTextChangedByApp = true;
675         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
676                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
677
678         result r = E_SUCCESS;
679
680         r = __pCancelButton->SetText(text);
681         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
682                      "[E_SYSTEM] A system error has occurred. Failed to set text.");
683
684         return r;
685 }
686
687 result
688 _SearchBar::SetButtonActionId(int actionId)
689 {
690         return SetProperty("buttonActionId", Variant(actionId));
691 }
692
693 result
694 _SearchBar::SetButtonEnabled(bool enabled)
695 {
696         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
697                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
698
699         __pCancelButton->SetEnableState(enabled);
700
701         __isButtonEnabled = enabled;
702
703         return E_SUCCESS;
704 }
705
706 result
707 _SearchBar::SetButtonColor(SearchBarButtonStatus status, const Color& color)
708 {
709         result r = E_SUCCESS;
710
711         switch (status)
712         {
713         case SEARCH_BAR_BUTTON_STATUS_NORMAL:
714                 r = SetProperty("buttonNormalColor", Variant(color));
715                 break;
716         case SEARCH_BAR_BUTTON_STATUS_PRESSED:
717                 r = SetProperty("buttonPressedColor", Variant(color));
718                 break;
719         case SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED:
720                 r = SetProperty("buttonHighlightedColor", Variant(color));
721                 break;
722         case SEARCH_BAR_BUTTON_STATUS_DISABLED:
723                 r = SetProperty("buttonDisabledColor", Variant(color));
724                 break;
725         default:
726                 break;
727         }
728
729         return r;
730 }
731
732 result
733 _SearchBar::SetButtonTextColor(SearchBarButtonStatus status, const Color& color)
734 {
735         result r = E_SUCCESS;
736
737         switch (status)
738         {
739         case SEARCH_BAR_BUTTON_STATUS_NORMAL:
740                 r = SetProperty("buttonNormalTextColor", Variant(color));
741                 break;
742         case SEARCH_BAR_BUTTON_STATUS_PRESSED:
743                 r = SetProperty("buttonPressedTextColor", Variant(color));
744                 break;
745         case SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED:
746                 r = SetProperty("buttonHighlightedTextColor", Variant(color));
747                 break;
748         case SEARCH_BAR_BUTTON_STATUS_DISABLED:
749                 r = SetProperty("buttonDisabledTextColor", Variant(color));
750                 break;
751         default:
752                 break;
753         }
754
755         return r;
756 }
757
758 result
759 _SearchBar::AppendCharacter(const Character& character)
760 {
761         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
762                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
763         SysTryReturn(NID_UI_CTRL, character.CompareTo(null), E_SYSTEM, E_SYSTEM,
764                      "[E_SYSTEM] A system error has occurred. The character is null.");
765
766         result r = E_SUCCESS;
767
768         r = __pEdit->AppendCharacter(character);
769         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
770                      "[E_SYSTEM] A system error has occurred. Failed to set character.");
771
772         return r;
773 }
774
775 result
776 _SearchBar::AppendText(const String& text)
777 {
778         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
779                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
780         SysTryReturn(NID_UI_CTRL, text.IsEmpty() == false, E_SYSTEM, E_SYSTEM,
781                      "[E_SYSTEM] A system error has occurred. The text is empty.");
782
783         result r = E_SUCCESS;
784
785         r = __pEdit->AppendText(text);
786         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
787                      "[E_SYSTEM] A system error has occurred. Failed to set text.");
788
789         return r;
790 }
791
792 result
793 _SearchBar::SetText(const String& text)
794 {
795         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
796                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
797
798         result r = E_SUCCESS;
799
800         int limitLength = __pEdit->GetTextLimitLength();
801         int textLength = text.GetLength();
802         SysTryReturn(NID_UI_CTRL, limitLength >= textLength, E_SYSTEM, E_SYSTEM,
803                      "[E_SYSTEM] A system error has occurred. textLength exceeds the limitLength");
804
805         r = __pEdit->SetText(text);
806         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
807                      "[E_SYSTEM] A system error has occurred. Failed to set text.");
808
809         return r;
810 }
811
812 result
813 _SearchBar::InsertCharacterAt(int index, const Character& character)
814 {
815         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
816                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
817         SysTryReturn(NID_UI_CTRL, index > -1, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
818                      "[E_OUT_OF_RANGE] index(%d) is out of range.", index);
819         SysTryReturn(NID_UI_CTRL, character.CompareTo(null), E_SYSTEM, E_SYSTEM,
820                      "[E_SYSTEM] A system error has occurred. The character is null.");
821
822         result r = E_SUCCESS;
823
824         int textLength = 0;
825         int limitLength = 0;
826         limitLength = __pEdit->GetTextLimitLength();
827         textLength = __pEdit->GetTextLength() + 1;
828
829         SysTryReturn(NID_UI_CTRL, limitLength >= textLength, E_MAX_EXCEEDED, E_MAX_EXCEEDED,
830                      "[E_MAX_EXCEEDED] limitLength(%d) exceeds the maximum limit textLength(%d).", limitLength, textLength);
831
832         SysTryReturn(NID_UI_CTRL, index <= __pEdit->GetTextLength(), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
833                      "[E_OUT_OF_RANGE] index(%d) is out of range of current textLength(%d).", index, __pEdit->GetTextLength());
834
835         r = __pEdit->InsertCharacterAt(index, character);
836         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
837                      "[E_SYSTEM] A system error has occurred. Failed to set text.");
838
839         return r;
840 }
841
842 result
843 _SearchBar::InsertTextAt(int index, const String& text)
844 {
845         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
846                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
847         SysTryReturn(NID_UI_CTRL, index > -1, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
848                      "[E_OUT_OF_RANGE] index(%d) is out of range.", index);
849
850         result r = E_SUCCESS;
851
852         int textLength = 0;
853         int limitLength = 0;
854         limitLength = __pEdit->GetTextLimitLength();
855         textLength = __pEdit->GetTextLength() + text.GetLength();
856
857         SysTryReturn(NID_UI_CTRL, limitLength >= textLength, E_MAX_EXCEEDED, E_MAX_EXCEEDED,
858                      "[E_MAX_EXCEEDED] limitLength(%d) exceeds the maximum limit textLength(%d).", limitLength, textLength);
859         SysTryReturn(NID_UI_CTRL, index <= __pEdit->GetTextLength(), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
860                      "[E_OUT_OF_RANGE] index(%d) is out of range of current textLength(%d).", index, __pEdit->GetTextLength());
861
862         r = __pEdit->InsertTextAt(index, text);
863         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
864                      "[E_SYSTEM] A system error has occurred. Failed to insert text.");
865
866         return r;
867 }
868
869 result
870 _SearchBar::DeleteCharacterAt(int index)
871 {
872         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
873                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
874         SysTryReturn(NID_UI_CTRL, index > -1, E_INVALID_ARG, E_INVALID_ARG,
875                      "[E_INVALID_ARG] Invalid argument(s) is used. index = %d", index);
876
877         result r = E_SUCCESS;
878         int textLength = 0;
879         textLength = __pEdit->GetTextLength();
880
881         SysTryReturn(NID_UI_CTRL, textLength > index, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
882                      "[E_OUT_OF_RANGE] index(%d) is out of range. textLength(%d)", index, textLength);
883
884         r = __pEdit->DeleteCharacterAt(index);
885         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM,
886                            "[E_SYSTEM] A system error has occured. Failed to delete character.");
887
888         return r;
889 }
890
891 result
892 _SearchBar::Clear(void)
893 {
894         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
895                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
896
897         return __pEdit->ClearText();
898 }
899
900 int
901 _SearchBar::GetTextLength(void) const
902 {
903         SysTryReturn(NID_UI_CTRL, __pEdit, -1, E_SYSTEM,
904                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
905
906         return __pEdit->GetTextLength();
907 }
908
909 String
910 _SearchBar::GetText(void) const
911 {
912         SysTryReturn(NID_UI_CTRL, __pEdit, String(), E_SYSTEM,
913                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
914
915         return __pEdit->GetText();
916 }
917
918 String
919 _SearchBar::GetText(int start, int end) const
920 {
921         SysTryReturn(NID_UI_CTRL, __pEdit, String(), E_SYSTEM,
922                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
923
924         return __pEdit->GetText(start, end);
925 }
926
927 int
928 _SearchBar::GetLimitLength(void) const
929 {
930         SysTryReturn(NID_UI_CTRL, __pEdit, -1, E_SYSTEM,
931                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
932
933         return __pEdit->GetTextLimitLength();
934 }
935
936 result
937 _SearchBar::SetLimitLength(int limitLength)
938 {
939         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
940                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
941         SysTryReturn(NID_UI_CTRL, limitLength > 0, E_INVALID_ARG, E_INVALID_ARG,
942                      "[E_INVALID_ARG] Invalid argument(s) is used.limitLength = %d", limitLength);
943
944         String tempString = GetText();
945
946         int textLength = tempString.GetLength();
947         SysTryReturn(NID_UI_CTRL, limitLength >= textLength, E_INVALID_ARG, E_INVALID_ARG,
948                      "[E_INVALID_ARG] Invalid argument(s) is used. limitLength = %d, textLength = %d", limitLength, textLength);
949
950         result r = __pEdit->SetLimitLength(limitLength);
951         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
952
953         r = SetText(tempString);
954         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, r, "[%s] Propagating.", GetErrorMessage(r));
955
956         return E_SUCCESS;
957 }
958
959 result
960 _SearchBar::ShowKeypad(void) const
961 {
962         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
963                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
964
965         SearchBarMode mode = __pSearchBarPresenter->GetMode();
966         SysTryReturn(NID_UI_CTRL, mode == SEARCH_BAR_MODE_INPUT, E_INVALID_STATE, E_INVALID_STATE,
967                      "[E_INVALID_STATE] The SearchBar is currently in Normal mode.");
968         return __pEdit->ShowKeypad();
969 }
970
971 result
972 _SearchBar::HideKeypad(void)
973 {
974         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
975                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
976
977         SearchBarMode mode = __pSearchBarPresenter->GetMode();
978         SysTryReturn(NID_UI_CTRL, mode == SEARCH_BAR_MODE_INPUT, E_SYSTEM, E_SYSTEM,
979                      "[E_SYSTEM] A system error has occurred. The SearchBar is currently in Normal mode.");
980
981         result r = __pEdit->HideKeypad();
982
983         SetContentsArea();
984
985         return r;
986 }
987
988 float
989 _SearchBar::GetSearchFieldTextSizeF(void) const
990 {
991         SysTryReturn(NID_UI_CTRL, __pEdit, -1, E_SYSTEM,
992                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
993
994         return __pEdit->GetTextSizeF();
995 }
996
997 result
998 _SearchBar::SetSearchFieldTextSize(float size)
999 {
1000         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1001                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1002
1003         return __pEdit->SetTextSize(size);
1004 }
1005
1006 result
1007 _SearchBar::GetBlockRange(int& start, int& end) const
1008 {
1009         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1010                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1011
1012         int startIndex = -1;
1013         int endIndex = -1;
1014
1015         __pEdit->GetBlockRange(startIndex, endIndex);
1016         SysTryReturn(NID_UI_CTRL, (startIndex > -1 && endIndex > 0), E_SYSTEM, E_SYSTEM,
1017                      "[E_SYSTEM] A system error has occurred. Failed to get text block range.");
1018
1019         start = startIndex;
1020         end = endIndex - 1;
1021
1022         return E_SUCCESS;
1023 }
1024
1025 result
1026 _SearchBar::ReleaseBlock(void)
1027 {
1028         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1029                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1030
1031         result r = E_SUCCESS;
1032
1033         int start = 0;
1034         int end = 0;
1035
1036         r = GetBlockRange(start, end);
1037         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1038
1039         return __pEdit->ReleaseTextBlock();
1040 }
1041
1042 result
1043 _SearchBar::SetBlockRange(int start, int end)
1044 {
1045         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1046                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1047
1048         result r = E_SUCCESS;
1049
1050         int textLength = 0;
1051         textLength = __pEdit->GetTextLength();
1052
1053         SysTryReturn(NID_UI_CTRL, (start < end && start >= 0 && textLength >= end), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1054                      "[E_OUT_OF_RANGE] start (%d) and end (%d) is out of range.", start, end - 1);
1055
1056         r = SetCursorPosition(start);
1057         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1058
1059         r = __pEdit->BeginTextBlock();
1060         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
1061                      "[E_SYSTEM] A system error has occurred. Failed to set text block range.");
1062
1063         r = SetCursorPosition(end);
1064         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
1065                      "[E_SYSTEM] A system error has occurred. Failed to set cursor position.");
1066
1067         return E_SUCCESS;
1068 }
1069
1070 result
1071 _SearchBar::RemoveTextBlock(void)
1072 {
1073         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1074                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1075
1076         result r = E_SUCCESS;
1077
1078         r = __pEdit->RemoveTextBlock();
1079         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1080
1081         return r;
1082 }
1083
1084 Color
1085 _SearchBar::GetColor(void) const
1086 {
1087         Variant backgroundColor = GetProperty("color");
1088
1089         return backgroundColor.ToColor();
1090 }
1091
1092 Color
1093 _SearchBar::GetSearchFieldColor(SearchFieldStatus status) const
1094 {
1095         Variant searchFieldColor;
1096
1097         switch (status)
1098         {
1099         case SEARCH_FIELD_STATUS_NORMAL:
1100                 searchFieldColor = GetProperty("searchFieldNormalColor");
1101                 break;
1102         case SEARCH_FIELD_STATUS_HIGHLIGHTED:
1103                 searchFieldColor = GetProperty("searchFieldHighlightedColor");
1104                 break;
1105         case SEARCH_FIELD_STATUS_DISABLED:
1106                 searchFieldColor = GetProperty("searchFieldDisabledColor");
1107                 break;
1108         default:
1109                 break;
1110         }
1111
1112         return searchFieldColor.ToColor();
1113 }
1114
1115
1116 Color
1117 _SearchBar::GetSearchFieldTextColor(SearchFieldStatus status) const
1118 {
1119         Variant searchFieldTextColor;
1120
1121         switch (status)
1122         {
1123         case SEARCH_FIELD_STATUS_NORMAL:
1124                 searchFieldTextColor = GetProperty("searchFieldNormalTextColor");
1125                 break;
1126         case SEARCH_FIELD_STATUS_HIGHLIGHTED:
1127                 searchFieldTextColor = GetProperty("searchFieldHighlightedTextColor");
1128                 break;
1129         case SEARCH_FIELD_STATUS_DISABLED:
1130                 searchFieldTextColor = GetProperty("searchFieldDisabledTextColor");
1131                 break;
1132         default:
1133                 break;
1134         }
1135
1136         return searchFieldTextColor.ToColor();
1137 }
1138
1139
1140 result
1141 _SearchBar::SetBackgroundBitmap(const Bitmap& bitmap)
1142 {
1143         Bitmap* pNewBitmap = _BitmapImpl::CloneN(bitmap);
1144         SysTryReturn(NID_UI_CTRL, pNewBitmap, E_SYSTEM, E_SYSTEM,
1145                      "[E_SYSTEM] A system error has occurred. The creation of bitmap failed.");
1146
1147         delete __pBackgroundBitmap;
1148         __pBackgroundBitmap = null;
1149
1150         __pBackgroundBitmap = pNewBitmap;
1151
1152         return E_SUCCESS;
1153 }
1154
1155 Bitmap*
1156 _SearchBar::GetBackgroundBitmap(void) const
1157 {
1158         return __pBackgroundBitmap;
1159 }
1160
1161 result
1162 _SearchBar::SetColor(const Color& color)
1163 {
1164         return SetProperty("color", Variant(color));
1165 }
1166
1167 result
1168 _SearchBar::SetSearchFieldColor(SearchFieldStatus status, const Color& color)
1169 {
1170         result r = E_SUCCESS;
1171
1172         switch (status)
1173         {
1174         case SEARCH_FIELD_STATUS_NORMAL:
1175                 r = SetProperty("searchFieldNormalColor", Variant(color));
1176                 break;
1177         case SEARCH_FIELD_STATUS_HIGHLIGHTED:
1178                 r = SetProperty("searchFieldHighlightedColor", Variant(color));
1179                 break;
1180         case SEARCH_FIELD_STATUS_DISABLED:
1181                 r = SetProperty("searchFieldDisabledColor", Variant(color));
1182                 break;
1183         default:
1184                 break;
1185         }
1186
1187         return r;
1188 }
1189
1190
1191 result
1192 _SearchBar::SetSearchFieldTextColor(SearchFieldStatus status, const Color& color)
1193 {
1194         result r = E_SUCCESS;
1195
1196         switch (status)
1197         {
1198         case SEARCH_FIELD_STATUS_NORMAL:
1199                 r = SetProperty("searchFieldNormalTextColor", Variant(color));
1200                 break;
1201         case SEARCH_FIELD_STATUS_HIGHLIGHTED:
1202                 r = SetProperty("searchFieldHighlightedTextColor", Variant(color));
1203                 break;
1204         case SEARCH_FIELD_STATUS_DISABLED:
1205                 r = SetProperty("searchFieldDisabledTextColor", Variant(color));
1206                 break;
1207         default:
1208                 break;
1209         }
1210
1211         return r;
1212 }
1213
1214
1215 String
1216 _SearchBar::GetGuideText(void) const
1217 {
1218         SysTryReturn(NID_UI_CTRL, __pEdit, String(), E_SYSTEM,
1219                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1220
1221         return __pEdit->GetGuideText();
1222 }
1223
1224 result
1225 _SearchBar::SetGuideText(const String& guideText)
1226 {
1227         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1228                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1229
1230         __pEdit->SetGuideText(guideText);
1231
1232         return E_SUCCESS;
1233 }
1234
1235 Color
1236 _SearchBar::GetGuideTextColor(void) const
1237 {
1238         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1239                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1240
1241         return __pEdit->GetGuideTextColor();
1242 }
1243
1244 result
1245 _SearchBar::SetGuideTextColor(const Color& color)
1246 {
1247         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1248                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1249
1250         __isUserGuideTextColor = true;
1251         return __pEdit->SetGuideTextColor(color);
1252 }
1253
1254 int
1255 _SearchBar::GetCursorPosition(void) const
1256 {
1257         SysTryReturn(NID_UI_CTRL, __pEdit, -1, E_SYSTEM,
1258                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1259
1260         return __pEdit->GetCursorPosition();
1261 }
1262
1263 result
1264 _SearchBar::SetCursorPosition(int index)
1265 {
1266         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1267                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1268         SysTryReturn(NID_UI_CTRL, index > -1, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1269                      "[E_OUT_OF_RANGE] index(%d) is out of range.", GetErrorMessage(E_OUT_OF_RANGE), index);
1270
1271         int textLength = -1;
1272         textLength = __pEdit->GetTextLength();
1273
1274         SysTryReturn(NID_UI_CTRL, (index > -1 && index <= textLength), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1275                      "[E_OUT_OF_RANGE] index(%d) is out of range.", index);
1276
1277         return __pEdit->SetCursorPosition(index);
1278 }
1279
1280 bool
1281 _SearchBar::IsLowerCaseModeEnabled(void) const
1282 {
1283         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1284                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1285
1286         return __pEdit->IsLowerCaseModeEnabled();
1287 }
1288
1289 void
1290 _SearchBar::SetLowerCaseModeEnabled(bool enable)
1291 {
1292         SysTryReturnVoidResult(NID_UI_CTRL, __pEdit, E_SYSTEM,
1293                                "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1294
1295         __pEdit->SetLowerCaseModeEnabled(enable);
1296 }
1297
1298 EllipsisPosition
1299 _SearchBar::GetEllipsisPosition(void) const
1300 {
1301         SysTryReturn(NID_UI_CTRL, __pEdit, ELLIPSIS_POSITION_START, E_SYSTEM,
1302                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1303
1304         return __pEdit->GetEllipsisPosition();
1305 }
1306
1307 result
1308 _SearchBar::SetEllipsisPosition(EllipsisPosition position)
1309 {
1310         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1311                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1312         __pEdit->SetEllipsisPosition(position);
1313
1314         return E_SUCCESS;
1315 }
1316
1317 CoreKeypadAction
1318 _SearchBar::GetKeypadAction(void) const
1319 {
1320         return __keypadAction;
1321 }
1322
1323 bool
1324 _SearchBar::IsTextPredictionEnabled(void) const
1325 {
1326         SysTryReturn(NID_UI_CTRL, __pEdit, false, E_SYSTEM,
1327                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1328         return __pEdit->IsTextPredictionEnabled();
1329 }
1330
1331 result
1332 _SearchBar::SetTextPredictionEnabled(bool enable)
1333 {
1334         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
1335                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
1336         return __pEdit->SetTextPredictionEnabled(enable);
1337 }
1338
1339 result
1340 _SearchBar::SetCurrentLanguage(LanguageCode languageCode)
1341 {
1342         return __pEdit->SetCurrentLanguage(languageCode);
1343 }
1344
1345 result
1346 _SearchBar::GetCurrentLanguage(LanguageCode& language) const
1347 {
1348         return __pEdit->GetCurrentLanguage(language);
1349 }
1350
1351 result
1352 _SearchBar::AddActionEventListener(const _IActionEventListener& listener)
1353 {
1354         result r = E_SUCCESS;
1355
1356         if (__pActionEvent == null)
1357         {
1358                 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
1359                 r = GetLastResult();
1360                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1361
1362                 __pActionEvent->AddListener(listener);
1363         }
1364
1365         return r;
1366 }
1367
1368 result
1369 _SearchBar::RemoveActionEventListener(const _IActionEventListener& listener)
1370 {
1371         SysTryReturn(NID_UI_CTRL, __pActionEvent, E_SYSTEM, E_SYSTEM,
1372                      "[E_SYSTEM] A system error has occurred. The action event instance is null.");
1373         result r = E_SUCCESS;
1374
1375         r = __pActionEvent->RemoveListener(listener);
1376         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1377
1378         return r;
1379 }
1380
1381 result
1382 _SearchBar::AddKeypadEventListener(const _IKeypadEventListener& listener)
1383 {
1384         result r = E_SUCCESS;
1385
1386         if (__pKeypadEvent == null)
1387         {
1388                 __pKeypadEvent = _KeypadEvent::CreateInstanceN(*this);
1389                 r = GetLastResult();
1390                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1391
1392                 r = __pKeypadEvent->AddListener(listener);
1393                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1394         }
1395
1396         return r;
1397 }
1398
1399 result
1400 _SearchBar::RemoveKeypadEventListener(const _IKeypadEventListener& listener)
1401 {
1402         SysTryReturn(NID_UI_CTRL, __pKeypadEvent, E_SYSTEM, E_SYSTEM,
1403                      "[E_SYSTEM] A system error has occurred. The keypad event instance is null.");
1404         result r = E_SUCCESS;
1405
1406         r = __pKeypadEvent->RemoveListener(listener);
1407         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1408
1409         return r;
1410 }
1411
1412 result
1413 _SearchBar::AddTextBlockEventListener(const _ITextBlockEventListener& listener)
1414 {
1415         result r = E_SUCCESS;
1416
1417         if (__pTextBlockEvent == null)
1418         {
1419                 __pTextBlockEvent = _TextBlockEvent::CreateInstanceN(*this);
1420                 r = GetLastResult();
1421                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1422
1423                 r = __pTextBlockEvent->AddListener(listener);
1424                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1425
1426         }
1427
1428         return r;
1429 }
1430
1431 result
1432 _SearchBar::RemoveTextBlockEventListener(const _ITextBlockEventListener& listener)
1433 {
1434         SysTryReturn(NID_UI_CTRL, __pTextBlockEvent, E_SYSTEM, E_SYSTEM,
1435                      "[E_SYSTEM] A system error has occurred. The text block event instance is null.");
1436         result r = E_SUCCESS;
1437
1438         r = __pTextBlockEvent->RemoveListener(listener);
1439         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1440
1441         return r;
1442 }
1443
1444
1445 result
1446 _SearchBar::AddTextEventListener(const _ITextEventListener& listener)
1447 {
1448         result r = E_SUCCESS;
1449
1450         if (__pTextEvent == null)
1451         {
1452                 __pTextEvent = _TextEvent::CreateInstanceN(*this);
1453                 r = GetLastResult();
1454                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1455
1456                 r = __pTextEvent->AddListener(listener);
1457                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1458         }
1459
1460         return r;
1461 }
1462
1463 result
1464 _SearchBar::RemoveTextEventListener(const _ITextEventListener& listener)
1465 {
1466         SysTryReturn(NID_UI_CTRL, __pTextEvent, E_SYSTEM, E_SYSTEM,
1467                      "[E_SYSTEM] A system error has occurred. The text event instance is null.");
1468         result r = E_SUCCESS;
1469
1470         r = __pTextEvent->RemoveListener(listener);
1471         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1472
1473         return r;
1474 }
1475
1476 result
1477 _SearchBar::AddSearchBarEventListener(const _ISearchBarEventListener& listener)
1478 {
1479         result r = E_SUCCESS;
1480
1481         if (__pSearchBarEvent == null)
1482         {
1483                 __pSearchBarEvent = _SearchBarEvent::CreateInstanceN(*this);
1484                 r = GetLastResult();
1485                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1486
1487                 r = __pSearchBarEvent->AddListener(listener);
1488                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1489         }
1490
1491         return r;
1492 }
1493
1494 result
1495 _SearchBar::RemoveSearchBarEventListener(const _ISearchBarEventListener& listener)
1496 {
1497         SysTryReturn(NID_UI_CTRL, __pSearchBarEvent, E_SYSTEM, E_SYSTEM,
1498                      "[E_SYSTEM] A system error has occurred. The searchbar event instance is null.");
1499         result r = E_SUCCESS;
1500
1501         r = __pSearchBarEvent->RemoveListener(listener);
1502         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1503
1504         return r;
1505 }
1506
1507 result
1508 _SearchBar::AddLanguageEventListener(const _ILanguageEventListener& listener)
1509 {
1510         result r = E_SUCCESS;
1511
1512         if (__pLanguageEvent == null)
1513         {
1514                 __pLanguageEvent = _LanguageEvent::CreateInstanceN(*this);
1515                 r = GetLastResult();
1516                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1517
1518                 r = __pLanguageEvent->AddListener(listener);
1519                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1520         }
1521
1522         return r;
1523 }
1524
1525 result
1526 _SearchBar::RemoveLanguageEventListener(const _ILanguageEventListener& listener)
1527 {
1528         SysTryReturn(NID_UI_CTRL, __pLanguageEvent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] This instance isn't constructed.");
1529         result r = E_SUCCESS;
1530
1531         __pLanguageEvent->RemoveListener(listener);
1532         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1533
1534         return r;
1535 }
1536
1537 void
1538 _SearchBar::OnBoundsChanged(void)
1539 {
1540         if (__pSearchBarPresenter != null)
1541         {
1542                 __isupdateContentBounds = true;
1543                 __pSearchBarPresenter->OnBoundsChanged();
1544         }
1545
1546         if (__pAccessibilitySearchBarElement)
1547         {
1548                 __pAccessibilitySearchBarElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
1549         }
1550         return;
1551 }
1552
1553 void
1554 _SearchBar::OnChangeLayout(_ControlOrientation orientation)
1555 {
1556         __isupdateContentBounds = true;
1557         return;
1558 }
1559
1560 void
1561 _SearchBar::OnDraw(void)
1562 {
1563         if (!__isUserGuideTextColor)
1564         {
1565                 SearchFieldStatus status = GetCurrentStatus();
1566                 __pEdit->SetGuideTextColor(__guideTextColor[status]);
1567         }
1568
1569         if (__isupdateContentBounds)
1570         {
1571                 SetContentsArea();
1572                 __isupdateContentBounds = false;
1573         }
1574         __pSearchBarPresenter->Draw();
1575         return;
1576 }
1577
1578 _UiTouchEventDelivery
1579 _SearchBar::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1580 {
1581         _Edit* pEdit = dynamic_cast <_Edit*>(const_cast <_Control*>(&source));
1582         if (pEdit == null)
1583         {
1584                 return _UI_TOUCH_EVENT_DELIVERY_YES;
1585         }
1586
1587         if (GetMode() == SEARCH_BAR_MODE_INPUT)
1588         {
1589                 return _UI_TOUCH_EVENT_DELIVERY_YES;
1590         }
1591
1592         return _UI_TOUCH_EVENT_DELIVERY_YES;
1593 }
1594
1595 void
1596 _SearchBar::OnActionPerformed(const _Control& source, int actionId)
1597 {
1598         if (__actionId == actionId)
1599         {
1600                 __isCancelActionInProgress = true;
1601                 SetMode(SEARCH_BAR_MODE_NORMAL);
1602
1603                 if (__pActionEvent)
1604                 {
1605                         IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(__actionId);
1606                         result r = GetLastResult();
1607                         SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1608
1609                         __pActionEvent->Fire(*pEventArg);
1610                 }
1611                 __isCancelActionInProgress = false;
1612         }
1613         return;
1614 }
1615
1616 // Keypad callbacks
1617 void
1618 _SearchBar::OnKeypadWillOpen(void)
1619 {
1620         if (!__isKeypadOpening)
1621         {
1622                 if (__pKeypadEvent)
1623                 {
1624                         IEventArg* pEventArg = _KeypadEvent::CreateKeypadEventArgN(CORE_KEYPAD_ACTION_SEARCH, CORE_KEYPAD_EVENT_STATUS_CREATED);
1625                         result r = GetLastResult();
1626                         SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1627
1628                         __pKeypadEvent->Fire(*pEventArg);
1629                 }
1630         }
1631
1632         __isKeypadOpening = true;
1633         return;
1634 }
1635
1636 void
1637 _SearchBar::OnKeypadOpened(void)
1638 {
1639         if (__pKeypadEvent)
1640         {
1641                 IEventArg* pEventArg = _KeypadEvent::CreateKeypadEventArgN(CORE_KEYPAD_ACTION_SEARCH, CORE_KEYPAD_EVENT_STATUS_OPEN);
1642                 result r = GetLastResult();
1643                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1644
1645                 __pKeypadEvent->Fire(*pEventArg);
1646         }
1647
1648         __isKeypadOpening = false;
1649         SetContentsArea();
1650         return;
1651 }
1652
1653 void
1654 _SearchBar::OnKeypadClosed(void)
1655 {
1656         if (__pKeypadEvent)
1657         {
1658                 IEventArg* pEventArg = _KeypadEvent::CreateKeypadEventArgN(CORE_KEYPAD_ACTION_SEARCH, CORE_KEYPAD_EVENT_STATUS_CLOSE);
1659                 result r = GetLastResult();
1660                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1661
1662                 __pKeypadEvent->Fire(*pEventArg);
1663         }
1664
1665         __isKeypadOpening = false;
1666
1667         SetContentsArea();
1668         return;
1669 }
1670
1671 void
1672 _SearchBar::OnKeypadBoundsChanged(void)
1673 {
1674         if (__pKeypadEvent)
1675         {
1676                 IEventArg* pEventArg = _KeypadEvent::CreateKeypadEventArgN(CORE_KEYPAD_ACTION_SEARCH, CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
1677                 result r = GetLastResult();
1678                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1679
1680                 __pKeypadEvent->Fire(*pEventArg);
1681         }
1682
1683         SetContentsArea();
1684         return;
1685 }
1686
1687 void
1688 _SearchBar::OnKeypadActionPerformed(CoreKeypadAction keypadAction)
1689 {
1690         if (__pKeypadEvent)
1691         {
1692                 IEventArg* pEventArg = _KeypadEvent::CreateKeypadEventArgN(keypadAction, CORE_KEYPAD_EVENT_STATUS_ENTERACTION);
1693                 result r = GetLastResult();
1694                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1695
1696                 __pKeypadEvent->Fire(*pEventArg);
1697         }
1698         return;
1699 }
1700
1701 // TextBlock callbacks
1702 void
1703 _SearchBar::OnTextBlockSelected(_Control& source, int start, int end)
1704 {
1705         if (__pTextBlockEvent)
1706         {
1707                 IEventArg* pEventArg = _TextBlockEvent::CreateTextBlockEventArgN(start, end);
1708                 result r = GetLastResult();
1709                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1710
1711                 __pTextBlockEvent->Fire(*pEventArg);
1712         }
1713         return;
1714 }
1715
1716 // Text callbacks
1717 void
1718 _SearchBar::OnTextValueChanged(const _Control& source)
1719 {
1720         if (!__isCancelActionInProgress)
1721         {
1722                 SetContentDimming();
1723                 if (__pTextEvent != null)
1724                 {
1725                         IEventArg* pEventArg = _TextEvent::CreateTextEventArgN(CORE_TEXT_EVENT_CHANGED);
1726                         result r = GetLastResult();
1727                         SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1728
1729                         __pTextEvent->Fire(*pEventArg);
1730                 }
1731         }
1732         return;
1733 }
1734
1735 void
1736 _SearchBar::OnTextValueChangeCanceled(const _Control& source)
1737 {
1738         if (__pTextEvent != null)
1739         {
1740                 IEventArg* pEventArg = _TextEvent::CreateTextEventArgN(CORE_TEXT_EVENT_CANCELED);
1741                 result r = GetLastResult();
1742                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, r, "[%s] Propagating.", GetErrorMessage(r));
1743
1744                 __pTextEvent->Fire(*pEventArg);
1745         }
1746         return;
1747 }
1748
1749 result
1750 _SearchBar::OnAttachedToMainTree(void)
1751 {
1752         SetContentsArea();
1753         return E_SUCCESS;
1754 }
1755
1756 void
1757 _SearchBar::OnFontChanged(Font* pFont)
1758 {
1759         __pCancelButton->SetFont(pFont->GetFaceName());
1760         __pEdit->SetFont(*pFont);
1761         return;
1762 }
1763
1764 void
1765 _SearchBar::OnFontInfoRequested(unsigned long& style, int& size)
1766 {
1767         style = FONT_STYLE_PLAIN;
1768         size = __pCancelButton->GetTextSize();
1769
1770         return;
1771 }
1772
1773 bool
1774 _SearchBar::OnFocusGained(const _Control& source)
1775 {
1776         if (__isKeyPressed)
1777         {
1778                 __isKeyPressed = false;
1779                 _Control::OnDrawFocus();
1780
1781                 return true;
1782         }
1783
1784         if (GetVisibleState() == true)
1785         {
1786                 __pEdit->SetFocused();
1787         }
1788
1789         return true;
1790 }
1791
1792 bool
1793 _SearchBar::OnFocusLost(const _Control &source)
1794 {
1795         __pEdit->SetSearchFieldFocus(false);
1796         _Control::OnFocusLost(source);
1797         return true;
1798 }
1799
1800 bool
1801 _SearchBar::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1802 {
1803         _KeyCode keyCode = keyInfo.GetKeyCode();
1804
1805         if (keyCode == _KEY_RIGHT)
1806         {
1807                 if (GetMode() == SEARCH_BAR_MODE_NORMAL)
1808                 {
1809                         __pEdit->SetFocused();
1810                         return true;
1811                 }
1812
1813                 if (!__isButtonEnabled || __pCancelButton->IsFocused() || !__isUsableCancelButton)
1814                 {
1815                         return true;
1816                 }
1817
1818                 __pCancelButton->SetButtonStatus(_BUTTON_STATUS_HIGHLIGHTED);
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->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1831                         __pCancelButton->Invalidate();
1832                         __pEdit->SetFocused();
1833                 }
1834
1835                 if (__pCancelButton->GetButtonStatus() == _BUTTON_STATUS_DISABLED)      //Searchbar Button is disabled, left arrow key is pressed
1836                 {
1837                         __pCancelButton->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1838                         SetButtonEnabled(false);
1839                         __pEdit->SetFocused();
1840                 }
1841
1842                 return true;
1843         }
1844
1845         if (keyCode == _KEY_ENTER || keyCode == _KEY_TAB)
1846         {
1847                 if (GetMode() == SEARCH_BAR_MODE_NORMAL)
1848                 {
1849                         return false;
1850                 }
1851
1852                 SetMode(SEARCH_BAR_MODE_NORMAL);
1853                 __isKeyPressed = true;
1854                 SetFocused();
1855
1856                 return true;
1857         }
1858
1859         return false;
1860 }
1861
1862 void
1863 _SearchBar::OnSettingChanged(Tizen::Base::String& key)
1864 {
1865         if (__isButtonTextChangedByApp || !__isUsableCancelButton)
1866         {
1867                 return;
1868         }
1869
1870         if (key.Equals(L"http://tizen.org/setting/locale.language", false))
1871         {
1872                 String cancelText;
1873                 GET_STRING_CONFIG(IDS_COM_SK_CANCEL, cancelText);
1874                 __pCancelButton->SetText(cancelText);
1875                 __pCancelButton->Invalidate();
1876         }
1877
1878         return;
1879 }
1880
1881 _Control*
1882 _SearchBar::GetParentForm(void) const
1883 {
1884         _Form* pForm = null;
1885         _Control* pControlCore = GetParent();
1886
1887         while (true)
1888         {
1889                 if (pControlCore == null)
1890                 {
1891                         SysLog(NID_UI_CTRL,"[E_SYSTEM] The parent form is null.");
1892
1893                         return null;
1894                 }
1895
1896                 pForm = dynamic_cast <_Form*>(pControlCore);
1897
1898                 if (pForm != null)
1899                 {
1900                         break;
1901                 }
1902
1903                 pControlCore = pControlCore->GetParent();
1904         }
1905
1906         return pControlCore;
1907 }
1908
1909 _Button*
1910 _SearchBar::GetSearchBarButton(void) const
1911 {
1912         return __pCancelButton;
1913 }
1914
1915 _Edit*
1916 _SearchBar::GetSearchField(void)
1917 {
1918         return __pEdit;
1919 }
1920
1921 _Control*
1922 _SearchBar::GetSearchBarContainer(void) const
1923 {
1924         return __pContainer;
1925 }
1926
1927 _Control*
1928 _SearchBar::GetClippedGroupControl(void) const
1929 {
1930         return __pClippedGroupControl;
1931 }
1932
1933 bool
1934 _SearchBar::IsUsableCancelButton(void) const
1935 {
1936         return __isUsableCancelButton;
1937 }
1938
1939 EditStatus
1940 _SearchBar::ConvertSearchBarStatus(SearchFieldStatus status)
1941 {
1942         EditStatus editStatus = EDIT_STATUS_NORMAL;
1943         switch (status)
1944         {
1945         case SEARCH_FIELD_STATUS_NORMAL:
1946                 editStatus = EDIT_STATUS_NORMAL;
1947                 break;
1948
1949         case SEARCH_FIELD_STATUS_DISABLED:
1950                 editStatus = EDIT_STATUS_DISABLED;
1951                 break;
1952
1953         case SEARCH_FIELD_STATUS_HIGHLIGHTED:
1954                 editStatus = EDIT_STATUS_HIGHLIGHTED;
1955                 break;
1956         default:
1957                 break;
1958         }
1959
1960         return editStatus;
1961 }
1962
1963 _ButtonStatus
1964 _SearchBar::ConvertSearchBarButtonStatus(SearchBarButtonStatus status)
1965 {
1966         _ButtonStatus buttonStatus = _BUTTON_STATUS_NORMAL;
1967
1968         switch (status)
1969         {
1970         case SEARCH_BAR_BUTTON_STATUS_NORMAL:
1971                 buttonStatus = _BUTTON_STATUS_NORMAL;
1972                 break;
1973
1974         case SEARCH_BAR_BUTTON_STATUS_PRESSED:
1975                 buttonStatus = _BUTTON_STATUS_PRESSED;
1976                 break;
1977
1978         case SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED:
1979                 buttonStatus = _BUTTON_STATUS_HIGHLIGHTED;
1980                 break;
1981
1982         case SEARCH_BAR_BUTTON_STATUS_DISABLED:
1983                 buttonStatus = _BUTTON_STATUS_DISABLED;
1984                 break;
1985         default:
1986                 break;
1987         }
1988
1989         return buttonStatus;
1990 }
1991
1992 result
1993 _SearchBar::SendSearchBarEvent(_SearchBarEventStatus status)
1994 {
1995         result r = E_SUCCESS;
1996         if (__pSearchBarEvent)
1997         {
1998                 IEventArg* pEventArg = _SearchBarEvent::CreateSearchBarEventArgN(status);
1999                 r = GetLastResult();
2000                 SysTryReturn(NID_UI_CTRL, pEventArg, r, r, "[%s] Propagating.", GetErrorMessage(r));
2001
2002                 if (IsContentAreaVisible() == false)
2003                 {
2004                         SetContentAreaVisible(false);
2005                 }
2006
2007                 __pSearchBarEvent->Fire(*pEventArg);
2008         }
2009
2010         return E_SUCCESS;
2011 }
2012
2013 void
2014 _SearchBar::SetHeaderVisibleState(bool visible)
2015 {
2016         if (__pSearchBarPresenter != null)
2017         {
2018                 __pSearchBarPresenter->SetHeaderVisibleState(visible);
2019         }
2020         return;
2021 }
2022
2023 result
2024 _SearchBar::SetPropertyButtonActionId(const Variant& actionId)
2025 {
2026         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2027                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2028         SysTryReturn(NID_UI_CTRL, actionId.ToInt() > -1, E_INVALID_ARG, E_INVALID_ARG,
2029                      "[E_INVALID_ARG] Invalid argument(s) is used. actionId.ToInt() = %d", actionId.ToInt());
2030
2031         result r = E_SUCCESS;
2032
2033         r = __pCancelButton->SetPropertyActionId(actionId);
2034         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2035                      "[%s] A system error has occurred. Failed to set actionId.", GetErrorMessage(E_SYSTEM));
2036
2037         __actionId = actionId.ToInt();
2038
2039         return r;
2040 }
2041
2042 Variant
2043 _SearchBar::GetPropertyButtonActionId(void) const
2044 {
2045         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(-1), E_SYSTEM,
2046                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2047
2048         return Variant(__actionId);
2049 }
2050
2051 result
2052 _SearchBar::SetPropertyButtonDisabledColor(const Variant& color)
2053 {
2054         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2055                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2056
2057         result r = E_SUCCESS;
2058
2059         r = __pCancelButton->SetPropertyDisabledColor(color);
2060         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2061                      "[E_SYSTEM] A system error has occurred. Failed to set button color.");
2062
2063         __buttonColor[SEARCH_BAR_BUTTON_STATUS_DISABLED] = color.ToColor();
2064
2065         return r;
2066 }
2067
2068 Variant
2069 _SearchBar::GetPropertyButtonDisabledColor(void) const
2070 {
2071         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2072                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2073
2074         return Variant(__buttonColor[SEARCH_BAR_BUTTON_STATUS_DISABLED]);
2075 }
2076
2077 result
2078 _SearchBar::SetPropertyButtonHighlightedColor(const Variant& color)
2079 {
2080         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2081                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2082
2083         result r = E_SUCCESS;
2084
2085         r = __pCancelButton->SetPropertyHighlightedColor(color);
2086         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2087                      "[E_SYSTEM] A system error has occurred. Failed to set button color.");
2088
2089         __buttonColor[SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED] = color.ToColor();
2090
2091         return r;
2092 }
2093
2094 Variant
2095 _SearchBar::GetPropertyButtonHighlightedColor(void) const
2096 {
2097         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2098                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2099
2100         return Variant(__buttonColor[SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED]);
2101 }
2102
2103 result
2104 _SearchBar::SetPropertyButtonNormalColor(const Variant& color)
2105 {
2106         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2107                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2108
2109         result r = E_SUCCESS;
2110
2111         r = __pCancelButton->SetPropertyNormalColor(color);
2112         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2113                      "[E_SYSTEM] A system error has occurred. Failed to set button color.");
2114
2115         __buttonColor[SEARCH_BAR_BUTTON_STATUS_NORMAL] = color.ToColor();
2116
2117         return r;
2118 }
2119
2120 Variant
2121 _SearchBar::GetPropertyButtonNormalColor(void) const
2122 {
2123         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2124                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2125
2126         return Variant(__buttonColor[SEARCH_BAR_BUTTON_STATUS_NORMAL]);
2127 }
2128
2129 result
2130 _SearchBar::SetPropertyButtonPressedColor(const Variant& color)
2131 {
2132         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2133                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2134
2135         result r = E_SUCCESS;
2136
2137         r = __pCancelButton->SetPropertyPressedColor(color);
2138         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2139                      "[E_SYSTEM] A system error has occurred. Failed to set button color.");
2140
2141         __buttonColor[SEARCH_BAR_BUTTON_STATUS_PRESSED] = color.ToColor();
2142
2143         return r;
2144 }
2145
2146 Variant
2147 _SearchBar::GetPropertyButtonPressedColor(void) const
2148 {
2149         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2150                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2151
2152         return Variant(__buttonColor[SEARCH_BAR_BUTTON_STATUS_PRESSED]);
2153 }
2154
2155 result
2156 _SearchBar::SetPropertyButtonDisabledTextColor(const Variant& textColor)
2157 {
2158         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2159                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2160
2161         result r = E_SUCCESS;
2162
2163         r = __pCancelButton->SetPropertyDisabledTextColor(textColor);
2164         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2165                      "[E_SYSTEM] A system error has occurred. Failed to set button text color.");
2166
2167         __buttonTextColor[SEARCH_BAR_BUTTON_STATUS_DISABLED] = textColor.ToColor();
2168
2169         return r;
2170 }
2171
2172 Variant
2173 _SearchBar::GetPropertyButtonDisabledTextColor(void) const
2174 {
2175         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2176                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2177
2178         return Variant(__buttonTextColor[SEARCH_BAR_BUTTON_STATUS_DISABLED]);
2179 }
2180
2181 result
2182 _SearchBar::SetPropertyButtonHighlightedTextColor(const Variant& textColor)
2183 {
2184         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2185                      "[E_SYSTEM]] A system error has occurred. The cancel button instance is null.");
2186
2187         result r = E_SUCCESS;
2188
2189         r = __pCancelButton->SetPropertyHighlightedTextColor(textColor);
2190         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2191                      "[E_SYSTEM] A system error has occurred. Failed to set button text color.");
2192
2193         __buttonTextColor[SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED] = textColor.ToColor();
2194
2195         return r;
2196 }
2197
2198 Variant
2199 _SearchBar::GetPropertyButtonHighlightedTextColor(void) const
2200 {
2201         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2202                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2203
2204         return Variant(__buttonTextColor[SEARCH_BAR_BUTTON_STATUS_HIGHLIGHTED]);
2205 }
2206
2207 result
2208 _SearchBar::SetPropertyButtonNormalTextColor(const Variant& textColor)
2209 {
2210         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2211                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2212
2213         result r = E_SUCCESS;
2214
2215         r = __pCancelButton->SetPropertyNormalTextColor(textColor);
2216         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2217                      "[E_SYSTEM] A system error has occurred. Failed to set button text color.");
2218
2219         __buttonTextColor[SEARCH_BAR_BUTTON_STATUS_NORMAL] = textColor.ToColor();
2220
2221         return r;
2222 }
2223
2224 Variant
2225 _SearchBar::GetPropertyButtonNormalTextColor(void) const
2226 {
2227         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2228                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2229
2230         return Variant(__buttonTextColor[SEARCH_BAR_BUTTON_STATUS_NORMAL]);
2231 }
2232
2233 result
2234 _SearchBar::SetPropertyButtonPressedTextColor(const Variant& textColor)
2235 {
2236         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
2237                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2238
2239         result r = E_SUCCESS;
2240
2241         r = __pCancelButton->SetPropertyPressedTextColor(textColor);
2242         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2243                      "[E_SYSTEM] A system error has occurred. Failed to set button text color.");
2244
2245         __buttonTextColor[SEARCH_BAR_BUTTON_STATUS_PRESSED] = textColor.ToColor();
2246
2247         return r;
2248 }
2249
2250 Variant
2251 _SearchBar::GetPropertyButtonPressedTextColor(void) const
2252 {
2253         SysTryReturn(NID_UI_CTRL, __pCancelButton, Variant(Color()), E_SYSTEM,
2254                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
2255
2256         return Variant(__buttonTextColor[SEARCH_BAR_BUTTON_STATUS_PRESSED]);
2257 }
2258
2259 result
2260 _SearchBar::SetPropertySearchFieldDisabledColor(const Variant& color)
2261 {
2262         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
2263                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2264
2265         result r = E_SUCCESS;
2266
2267         r = __pEdit->SetPropertyDisabledColor(color);
2268         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2269                      "[E_SYSTEM] A system error has occurred. Failed to set the edit disabled color.");
2270
2271         __color[SEARCH_FIELD_STATUS_DISABLED] = color.ToColor();
2272
2273         return r;
2274 }
2275
2276 Variant
2277 _SearchBar::GetPropertySearchFieldDisabledColor(void) const
2278 {
2279         SysTryReturn(NID_UI_CTRL, __pEdit, Variant(Color()), E_SYSTEM,
2280                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2281
2282         return Variant(__color[SEARCH_FIELD_STATUS_DISABLED]);
2283 }
2284
2285 result
2286 _SearchBar::SetPropertySearchFieldHighlightedColor(const Variant& color)
2287 {
2288         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
2289                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2290
2291         result r = E_SUCCESS;
2292
2293         r = __pEdit->SetPropertyHighlightedColor(color);
2294         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2295                      "[E_SYSTEM] A system error has occurred. Failed to set the edit highlighted color.");
2296
2297         __color[SEARCH_FIELD_STATUS_HIGHLIGHTED] = color.ToColor();
2298
2299         return r;
2300 }
2301
2302 Variant
2303 _SearchBar::GetPropertySearchFieldHighlightedColor(void) const
2304 {
2305         SysTryReturn(NID_UI_CTRL, __pEdit, Variant(Color()), E_SYSTEM,
2306                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2307
2308         return Variant(__color[SEARCH_FIELD_STATUS_HIGHLIGHTED]);
2309 }
2310
2311 result
2312 _SearchBar::SetPropertySearchFieldNormalColor(const Variant& color)
2313 {
2314         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
2315                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2316
2317         result r = E_SUCCESS;
2318
2319         r = __pEdit->SetPropertyNormalColor(color);
2320         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2321                      "[E_SYSTEM] A system error has occurred. Failed to set edit normal color.");
2322
2323         __color[SEARCH_FIELD_STATUS_NORMAL] = color.ToColor();
2324
2325         return r;
2326 }
2327
2328 Variant
2329 _SearchBar::GetPropertySearchFieldNormalColor(void) const
2330 {
2331         SysTryReturn(NID_UI_CTRL, __pEdit, Variant(Color()), E_SYSTEM,
2332                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2333
2334         return Variant(__color[SEARCH_FIELD_STATUS_NORMAL]);
2335 }
2336
2337 result
2338 _SearchBar::SetPropertySearchFieldDisabledTextColor(const Variant& textColor)
2339 {
2340         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
2341                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2342
2343         result r = E_SUCCESS;
2344
2345         r = __pEdit->SetPropertyDisabledTextColor(textColor);
2346         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2347                      "[E_SYSTEM] A system error has occurred. Failed to set edit disabled text color.");
2348
2349         __textColor[SEARCH_FIELD_STATUS_DISABLED] = textColor.ToColor();
2350
2351         return r;
2352 }
2353
2354 Variant
2355 _SearchBar::GetPropertySearchFieldDisabledTextColor(void) const
2356 {
2357         SysTryReturn(NID_UI_CTRL, __pEdit, Variant(Color()), E_SYSTEM,
2358                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2359
2360         return Variant(__textColor[SEARCH_FIELD_STATUS_DISABLED]);
2361 }
2362
2363 result
2364 _SearchBar::SetPropertySearchFieldHighlightedTextColor(const Variant& textColor)
2365 {
2366         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
2367                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2368
2369         result r = E_SUCCESS;
2370
2371         r = __pEdit->SetPropertyHighlightedTextColor(textColor);
2372         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2373                      "[E_SYSTEM] A system error has occurred. Failed to set edit highlighted text color.");
2374
2375         __textColor[SEARCH_FIELD_STATUS_HIGHLIGHTED] = textColor.ToColor();
2376
2377         return r;
2378 }
2379
2380 Variant
2381 _SearchBar::GetPropertySearchFieldHighlightedTextColor(void) const
2382 {
2383         SysTryReturn(NID_UI_CTRL, __pEdit, Variant(Color()), E_SYSTEM,
2384                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2385
2386         return Variant(__textColor[SEARCH_FIELD_STATUS_HIGHLIGHTED]);
2387 }
2388
2389 result
2390 _SearchBar::SetPropertySearchFieldNormalTextColor(const Variant& textColor)
2391 {
2392         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
2393                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2394
2395         result r = E_SUCCESS;
2396
2397         r = __pEdit->SetPropertyNormalTextColor(textColor);
2398         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
2399                      "[E_SYSTEM] A system error has occurred. Failed to set edit normal text color.");
2400
2401         __textColor[SEARCH_FIELD_STATUS_NORMAL] = textColor.ToColor();
2402
2403         return r;
2404 }
2405
2406 Variant
2407 _SearchBar::GetPropertySearchFieldNormalTextColor(void) const
2408 {
2409         SysTryReturn(NID_UI_CTRL, __pEdit, Variant(Color()), E_SYSTEM,
2410                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2411
2412         return Variant(__textColor[SEARCH_FIELD_STATUS_NORMAL]);
2413 }
2414
2415 result
2416 _SearchBar::SetPropertyColor(const Variant& color)
2417 {
2418         __backgroundColor = color.ToColor();
2419
2420         return E_SUCCESS;
2421 }
2422
2423 Variant
2424 _SearchBar::GetPropertyColor(void) const
2425 {
2426         return Variant(__backgroundColor);
2427 }
2428
2429 result
2430 _SearchBar::SetPropertyContentAreaSize(const Variant& size)
2431 {
2432         FloatDimension contentAreaSize = size.ToFloatDimension();
2433         SysTryReturn(NID_UI_CTRL, contentAreaSize.width >= 0 && contentAreaSize.height >= 0, E_INVALID_ARG, E_INVALID_ARG,
2434                      "[E_INVALID_ARG] Invalid argument(s) is used. contentAreaSize.width = %f, contenAreaSize.height = %f",
2435                      contentAreaSize.width, contentAreaSize.height);
2436
2437         result r = E_SUCCESS;
2438
2439         // Todo
2440         FloatRectangle bounds = GetBoundsF();
2441         FloatRectangle contentAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
2442
2443         contentAreaBounds.x = 0.0f;
2444         contentAreaBounds.y = bounds.height;
2445         contentAreaBounds.width = contentAreaSize.width;
2446         contentAreaBounds.height = contentAreaSize.height;
2447
2448         __contentAreaBounds = contentAreaBounds;
2449         __isUserContainerBounds = true;
2450
2451         // set bounds
2452         if (__pContainer)
2453         {
2454                 r = __pContainer->SetBounds(__contentAreaBounds);
2455                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2456         }
2457
2458         return r;
2459 }
2460
2461 Variant
2462 _SearchBar::GetPropertyContentAreaSize(void) const
2463 {
2464         FloatDimension contentAreaSize(__contentAreaBounds.width, __contentAreaBounds.height);
2465
2466         return Variant(contentAreaSize);
2467 }
2468
2469 result
2470 _SearchBar::CreateClippedGroupControl(void)
2471 {
2472         result r = E_SUCCESS;
2473         FloatRectangle clippedGroupControlBounds(FloatPoint(0.0f, 0.0f), GetSizeF());
2474         __pClippedGroupControl = _Control::CreateControlN();
2475         r = GetLastResult();
2476         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2477
2478         r = AttachChild(*__pClippedGroupControl);
2479         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
2480                     "[E_SYSTEM] A system error has occurred. Failed to attach the parent of clipped control.");
2481
2482         r = __pClippedGroupControl->SetBounds(clippedGroupControlBounds);
2483         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2484
2485         __pClippedGroupControl->SetBackgroundColor(Color(0));
2486
2487         __pClippedGroupControl->SetClipChildrenEnabled(true);
2488
2489         return r;
2490
2491 CATCH:
2492         delete __pClippedGroupControl;
2493         __pClippedGroupControl = null;
2494
2495         return r;
2496
2497 }
2498
2499 void
2500 _SearchBar::CreateAccessibilityElement(void)
2501 {
2502         if (__pAccessibilitySearchBarElement != null)
2503         {
2504                 return;
2505         }
2506         _AccessibilityContainer* pContainer = null;
2507         pContainer = GetAccessibilityContainer();
2508
2509         if (pContainer)
2510         {
2511                 __pAccessibilitySearchBarElement = new (std::nothrow) _AccessibilityElement(true);
2512                 SysTryReturnVoidResult(NID_UI_CTRL, __pAccessibilitySearchBarElement, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
2513                 __pAccessibilitySearchBarElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
2514                 __pAccessibilitySearchBarElement->SetTrait(ACCESSIBILITY_TRAITS_NONE);
2515                 __pAccessibilitySearchBarElement->SetName("SearchBar");
2516                 pContainer->AddElement(*__pAccessibilitySearchBarElement);
2517         }
2518
2519         return;
2520 }
2521
2522 void
2523 _SearchBar::SetContentDimming(void)
2524 {
2525         if (__pContainer != NULL)
2526         {
2527                 if (!GetTextLength())
2528                 {
2529                         __contentColor.SetAlpha(_SEARCH_CONTENT_DIM_OPACITY);
2530                 }
2531                 else
2532                 {
2533                         __contentColor.SetAlpha(0);
2534                 }
2535                 __pContainer->SetBackgroundColor(__contentColor);
2536         }
2537         return;
2538 }
2539
2540 void
2541 _SearchBar::OnDrawFocus(void)
2542 {
2543         __pEdit->SetSearchFieldFocus(true);
2544         return;
2545 }
2546
2547 bool
2548 _SearchBar::IsContentAttachable(const _Control* pContent)
2549 {
2550         const _Window* pWindow = dynamic_cast <const _Window*>(pContent);
2551         const _ColorPicker* pColorPicker = dynamic_cast <const _ColorPicker*>(pContent);
2552         const _Form* pForm = dynamic_cast <const _Form*>(pContent);
2553         const _Keypad* pKeypad = dynamic_cast <const _Keypad*>(pContent);
2554         const _OverlayPanel* pOverlayPanel = dynamic_cast <const _OverlayPanel*>(pContent);
2555
2556         bool isContentAttachable = true;
2557
2558         isContentAttachable = ((pWindow == null) && (pColorPicker == null) &&
2559                                (pForm == null) && (pKeypad == null) && (pOverlayPanel == null));
2560         return isContentAttachable;
2561 }
2562
2563 result
2564 _SearchBar::ResizeCancelButton(void)
2565 {
2566         result r = E_SUCCESS;
2567
2568         float horizontalMargin = 0.0f;
2569         float buttonLeftMargin = 0.0f;
2570         float buttonRightMargin = 0.0f;
2571         float buttonMinWidth = 0.0f;
2572         float searchFieldMinWidth = 0.0f;
2573         float buttonVerticalMargin = 0.0f;
2574         float searchBarMinHeight = 0.0f;
2575         float buttonWidth = 0.0f;
2576         float buttonHeight = 0.0f;
2577
2578         FloatRectangle cancelButtonBounds;
2579         FloatRectangle searchBarBounds = GetBoundsF();
2580
2581         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
2582
2583         GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
2584         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_LEFT_MARGIN, orientation, buttonLeftMargin);
2585         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_RIGHT_MARGIN, orientation, buttonRightMargin);
2586         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
2587         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_HEIGHT, orientation, buttonHeight);
2588         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_MIN_WIDTH, orientation, buttonMinWidth);
2589         GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH, orientation, searchFieldMinWidth);
2590         GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, buttonVerticalMargin);
2591         GET_SHAPE_CONFIG(SEARCHBAR::MIN_HEIGHT, orientation, searchBarMinHeight);
2592
2593         cancelButtonBounds.width = buttonWidth;
2594         cancelButtonBounds.height = buttonHeight;
2595
2596         float buttonResizableSearchBarWidth = (horizontalMargin + searchFieldMinWidth +
2597                                              cancelButtonBounds.width + buttonLeftMargin + buttonRightMargin);
2598
2599         if (searchBarBounds.width < buttonResizableSearchBarWidth)
2600         {
2601                 cancelButtonBounds.width = searchBarBounds.width -(searchFieldMinWidth + buttonLeftMargin
2602                                                                    + buttonRightMargin + horizontalMargin);
2603         }
2604
2605         cancelButtonBounds.x = searchBarBounds.width - cancelButtonBounds.width - buttonRightMargin;
2606         cancelButtonBounds.y = (searchBarBounds.height - cancelButtonBounds.height)/2.0f;
2607
2608         cancelButtonBounds.y = cancelButtonBounds.y < 0.0f ? 0.0f:cancelButtonBounds.y;
2609
2610         if (cancelButtonBounds.width < buttonMinWidth)
2611         {
2612                 cancelButtonBounds.width = buttonMinWidth;
2613         }
2614
2615         cancelButtonBounds.width = (cancelButtonBounds.width > 0.0f) ? cancelButtonBounds.width : 0.0f;
2616         cancelButtonBounds.height = (cancelButtonBounds.height > 0.0f) ? cancelButtonBounds.height : 0.0f;
2617         r = __pCancelButton->SetBounds(cancelButtonBounds);
2618
2619         return r;
2620 }
2621
2622 void
2623 _SearchBar::RecalculateButtonBounds(void)
2624 {
2625         result r = E_SUCCESS;
2626
2627         float horizontalMargin = 0.0f;
2628         float verticalMargin = 0.0f;
2629         float buttonLeftMargin = 0.0f;
2630         float buttonRightMargin = 0.0f;
2631         float buttonMinWidth = 0.0f;
2632         float searchFieldMinWidth = 0.0f;
2633         float buttonVerticalMargin = 0.0f;
2634         float searchBarMinHeight = 0.0f;
2635         float buttonWidth = 0.0f;
2636         float buttonHeight = 0.0f;
2637         float cancelButtonWidth = 0.0f;
2638
2639         FloatRectangle cancelButtonBounds;
2640         FloatRectangle editBounds;
2641         FloatRectangle searchBarBounds = GetBoundsF();
2642
2643         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
2644
2645         GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
2646         GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, verticalMargin);
2647         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_LEFT_MARGIN, orientation, buttonLeftMargin);
2648         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_RIGHT_MARGIN, orientation, buttonRightMargin);
2649         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
2650         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_HEIGHT, orientation, buttonHeight);
2651         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_MIN_WIDTH, orientation, buttonMinWidth);
2652         GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH, orientation, searchFieldMinWidth);
2653         GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, buttonVerticalMargin);
2654         GET_SHAPE_CONFIG(SEARCHBAR::MIN_HEIGHT, orientation, searchBarMinHeight);
2655
2656         cancelButtonBounds.height = buttonHeight;
2657
2658         float searchFieldMinHeight = searchBarMinHeight - (verticalMargin * 2.0f);
2659         cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
2660         editBounds.x = horizontalMargin;
2661
2662         if (searchBarBounds.height < searchBarMinHeight)
2663         {
2664                 verticalMargin = (searchBarBounds.height - searchFieldMinHeight)/2.0f;
2665                 if (verticalMargin < 0.0f)
2666                 {
2667                         verticalMargin = 0.0f;
2668                 }
2669         }
2670
2671         editBounds.y = verticalMargin;
2672         editBounds.height = searchBarBounds.height - (editBounds.y * 2.0f);
2673
2674         editBounds.height = (editBounds.height > searchFieldMinHeight) ? editBounds.height : searchFieldMinHeight;
2675
2676         editBounds.width = searchBarBounds.width - cancelButtonWidth - horizontalMargin - buttonLeftMargin - buttonRightMargin;
2677
2678         if (editBounds.width < searchFieldMinWidth)
2679         {
2680                 editBounds.width = searchFieldMinWidth;
2681         }
2682
2683         cancelButtonBounds.x = editBounds.width + horizontalMargin + buttonLeftMargin;
2684         cancelButtonBounds.y = (searchBarBounds.height - cancelButtonBounds.height)/2.0f;
2685
2686         cancelButtonBounds.y = cancelButtonBounds.y < 0.0f ? 0.0f:cancelButtonBounds.y;
2687
2688         float remainingWidth = searchBarBounds.width - editBounds.width - horizontalMargin - buttonLeftMargin - buttonRightMargin;
2689
2690         if (remainingWidth < buttonMinWidth)
2691         {
2692                 cancelButtonBounds.width = buttonMinWidth;
2693         }
2694         else
2695         {
2696                 cancelButtonBounds.width = searchBarBounds.width - cancelButtonBounds.x - buttonRightMargin;
2697         }
2698
2699         cancelButtonBounds.width = (cancelButtonBounds.width > 0.0f) ? cancelButtonBounds.width : 0.0f;
2700         cancelButtonBounds.height = (cancelButtonBounds.height > 0.0f) ? cancelButtonBounds.height : 0.0f;
2701
2702         r = __pCancelButton->SetBounds(cancelButtonBounds);
2703         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2704         r = __pEdit->SetBounds(editBounds);
2705         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2706
2707         return;
2708 }
2709
2710 SearchFieldStatus
2711 _SearchBar::GetCurrentStatus(void)
2712 {
2713         SearchFieldStatus searchFieldStatus = SEARCH_FIELD_STATUS_NORMAL;
2714
2715         if (IsEnabled())
2716         {
2717                 if (__pEdit->IsFocused())
2718                 {
2719                         searchFieldStatus = SEARCH_FIELD_STATUS_HIGHLIGHTED;
2720                 }
2721         }
2722         else
2723         {
2724                 searchFieldStatus = SEARCH_FIELD_STATUS_DISABLED;
2725         }
2726
2727         return searchFieldStatus;
2728 }
2729
2730 void
2731 _SearchBar::SetEditTextFilter(IEditTextFilter* pFilter)
2732 {
2733         SysTryReturnVoidResult(NID_UI_CTRL, __pEdit, E_SYSTEM,
2734                                "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2735
2736         __pEdit->SetEditTextFilter(pFilter);
2737
2738         return;
2739 }
2740
2741 void
2742 _SearchBar::SendOpaqueCommand(const String& command)
2743 {
2744         SysTryReturnVoidResult(NID_UI_CTRL, __pEdit, E_SYSTEM,
2745                                "[E_SYSTEM] A system error has occurred. The edit instance is null.");
2746
2747         __pEdit->SendOpaqueCommand(command);
2748
2749         return;
2750 }
2751
2752 void
2753 _SearchBar::SetFocusCallBackParameter(bool state)
2754 {
2755         __isFocusCallbackToBeFired = state;
2756         return;
2757 }
2758
2759 bool
2760 _SearchBar::IsFocusCallBackToBeFired(void) const
2761 {
2762         return __isFocusCallbackToBeFired;
2763 }
2764 }}} // Tizen::Ui::Controls