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