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