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