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