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