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