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