1695ca4cb2aca8909d5e560b3d29608e1614a427
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_SearchBarPresenter.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUiCtrl_SearchBarPresenter.cpp
20  * @brief               This is the implementation file for the _SearchBarPresenter class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FBaseErrorDefine.h>
25 #include <FGrp_BitmapImpl.h>
26 #include "FUi_ResourceManager.h"
27 #include "FUiAnim_VisualElement.h"
28 #include "FUiCtrl_Edit.h"
29 #include "FUiCtrl_Form.h"
30 #include "FUiCtrl_SearchBar.h"
31 #include "FUiCtrl_SearchBarModel.h"
32 #include "FUiCtrl_SearchBarPresenter.h"
33 #include "FUiCtrl_Toolbar.h"
34 #include "FUi_CoordinateSystemUtils.h"
35
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Ui::Animations;
38 using namespace Tizen::Base;
39 using namespace Tizen::Ui;
40
41 namespace Tizen { namespace Ui { namespace Controls {
42
43 _SearchBarPresenter::_SearchBarPresenter(void)
44         : __pSearchBar(null)
45         , __pSearchBarModel(null)
46         , __pCancelButton(null)
47         , __pEdit(null)
48         , __pContainer(null)
49         , __searchFieldBounds(FloatRectangle())
50         , __pIconElement(null)
51         , __pReplacedSearchFieldNormalBitmap(null)
52         , __pReplacedSearchFieldDisabledBitmap(null)
53         , __pSearchFieldEffectBitmap(null)
54 {
55 }
56
57 _SearchBarPresenter::~_SearchBarPresenter(void)
58 {
59         delete __pSearchBarModel;
60         __pSearchBarModel = null;
61
62         if (__pIconElement)
63         {
64                 __pIconElement->Destroy();
65                 __pIconElement = null;
66         }
67
68         if (__pReplacedSearchFieldNormalBitmap)
69         {
70                 delete __pReplacedSearchFieldNormalBitmap;
71                 __pReplacedSearchFieldNormalBitmap = null;
72         }
73
74         if (__pReplacedSearchFieldDisabledBitmap)
75         {
76                 delete __pReplacedSearchFieldDisabledBitmap;
77                 __pReplacedSearchFieldDisabledBitmap = null;
78         }
79
80         if (__pSearchFieldEffectBitmap)
81         {
82                 delete __pSearchFieldEffectBitmap;
83                 __pSearchFieldEffectBitmap = null;
84         }
85 }
86
87 result
88 _SearchBarPresenter::Construct(const _SearchBar& searchBar)
89 {
90         result r = E_SUCCESS;
91         _VisualElement* pSearchBarElement = null;
92
93         __pSearchBar = const_cast <_SearchBar*>(&searchBar);
94         SysTryReturn(NID_UI_CTRL, __pSearchBar, E_SYSTEM, E_SYSTEM,
95                      "[E_SYSTEM] A system error has occurred. The searchbar instance is null.");
96
97         __pCancelButton = __pSearchBar->GetSearchBarButton();
98         SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
99                      "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
100
101         __pEdit = __pSearchBar->GetSearchField();
102         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
103                      "[E_SYSTEM] A system error has occurred. The edit instance is null.");
104
105         __pContainer = __pSearchBar->GetSearchBarContainer();
106         SysTryReturn(NID_UI_CTRL, __pContainer, E_SYSTEM, E_SYSTEM,
107                      " [E_SYSTEM] A system error has occurred. Failed to get the content.");
108
109         r = LoadSearchFieldIcon();
110         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
111
112         _VisualElement* pEditElement = __pEdit->GetVisualElement();
113         SysTryReturn(NID_UI_CTRL, pEditElement, E_SYSTEM, E_SYSTEM,
114                      "[E_SYSTEM] A system error has occurred. Failed to get edit visual element.");
115
116         __pIconElement = new (std::nothrow) _VisualElement();
117         SysTryCatch(NID_UI_CTRL, __pIconElement, , E_OUT_OF_MEMORY,
118                     "[E_OUT_OF_MEMORY] Memory allocation failed.");
119
120         r = __pIconElement->Construct();
121         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
122
123         __pIconElement->SetShowState(true);
124
125         r = __pIconElement->SetSurfaceOpaque(false);
126         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
127
128         __pIconElement->SetImplicitAnimationEnabled(false);
129
130         r = pEditElement->AttachChild(*__pIconElement);
131         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
132
133         pSearchBarElement = __pSearchBar->GetVisualElement();
134         SysTryCatch(NID_UI_CTRL, pSearchBarElement, , E_SYSTEM,
135                     "[E_SYSTEM] A system error has occurred. Failed to get searchbar's visual element.");
136
137         return r;
138
139 CATCH:
140         if (__pIconElement)
141         {
142                 __pIconElement->Destroy();
143                 __pIconElement = null;
144         }
145
146         return r;
147 }
148
149 result
150 _SearchBarPresenter::LoadSearchFieldIcon()
151 {
152         result r = E_SUCCESS;
153         Color searchFieldIconColor;
154         Bitmap* pSearchFieldBitmap;
155
156
157         r = GET_BITMAP_CONFIG_N(SEARCHBAR::ICON_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pSearchFieldBitmap);
158         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
159
160         r = GET_BITMAP_CONFIG_N(SEARCHBAR::ICON_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pSearchFieldEffectBitmap);
161         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r,"[%s] Propagating.", GetErrorMessage(r));
162
163         GET_COLOR_CONFIG(SEARCHBAR::ICON_BG_NORMAL, searchFieldIconColor);
164
165         __pReplacedSearchFieldNormalBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pSearchFieldBitmap, Color::GetColor(COLOR_ID_MAGENTA), searchFieldIconColor);
166         SysTryCatch(NID_UI_CTRL, __pReplacedSearchFieldNormalBitmap != null, r = GetLastResult(), GetLastResult(),"[%s] Propagating.",
167                 GetErrorMessage(GetLastResult()));
168
169         delete pSearchFieldBitmap;
170         pSearchFieldBitmap = null;
171
172         r = GET_BITMAP_CONFIG_N(SEARCHBAR::ICON_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pSearchFieldBitmap);
173         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r,"[%s] Propagating.", GetErrorMessage(r));
174
175         GET_COLOR_CONFIG(SEARCHBAR::ICON_BG_DISABLED, searchFieldIconColor);
176
177         __pReplacedSearchFieldDisabledBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pSearchFieldBitmap, Color::GetColor(COLOR_ID_MAGENTA), searchFieldIconColor);
178         SysTryCatch(NID_UI_CTRL, __pReplacedSearchFieldDisabledBitmap != null, r = GetLastResult(), GetLastResult(),"[%s] Propagating.",
179                 GetErrorMessage(GetLastResult()));
180
181         delete pSearchFieldBitmap;
182         pSearchFieldBitmap = null;
183
184         return r;
185
186 CATCH:
187         delete pSearchFieldBitmap;
188         pSearchFieldBitmap = null;
189
190         delete __pSearchFieldEffectBitmap;
191         __pSearchFieldEffectBitmap = null;
192
193         delete __pReplacedSearchFieldNormalBitmap;
194         __pReplacedSearchFieldNormalBitmap = null;
195
196         return r;
197 }
198
199 result
200 _SearchBarPresenter::Install(void)
201 {
202         result r = E_SUCCESS;
203
204         _SearchBarModel* pModel = new (std::nothrow) _SearchBarModel;
205         SysTryReturn(NID_UI_CTRL, pModel, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
206
207         r = pModel->Construct();
208         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM,
209                     "[E_SYSTEM] A system error has occurred. The searchbar model construction failed.");
210
211         __pSearchBarModel = pModel;
212
213         return E_SUCCESS;
214
215 CATCH:
216         delete pModel;
217         return E_SYSTEM;
218 }
219
220 result
221 _SearchBarPresenter::UpdateContentArea(bool invalidate)
222 {
223         SearchBarMode mode = __pSearchBarModel->GetMode();
224         SysTryReturn(NID_UI_CTRL, mode == SEARCH_BAR_MODE_INPUT, E_INVALID_OPERATION, E_INVALID_OPERATION,
225                      "[E_INVALID_OPERATION] The searchbar mode cannot be updated.");
226
227         __pSearchBar->Invalidate(invalidate);
228
229         return E_SUCCESS;
230 }
231
232 result
233 _SearchBarPresenter::SetContentAreaVisible(bool visible)
234 {
235         return __pSearchBarModel->SetContentAreaVisible(visible);
236 }
237
238 bool
239 _SearchBarPresenter::IsContentAreaVisible(void) const
240 {
241         return __pSearchBarModel->IsContentAreaVisible();
242 }
243
244 SearchBarMode
245 _SearchBarPresenter::GetMode(void) const
246 {
247         return __pSearchBarModel->GetMode();
248 }
249
250 bool
251 _SearchBarPresenter::IsModeLocked(void) const
252 {
253         return __pSearchBarModel->IsModeLocked();
254 }
255
256 result
257 _SearchBarPresenter::SetMode(SearchBarMode mode)
258 {
259         SysTryReturn(NID_UI_CTRL, IsModeLocked() == false, E_INVALID_OPERATION, E_INVALID_OPERATION,
260                      "[E_INVALID_OPERATION] The searchbar mode is locked.");
261
262         if (GetMode() == mode)
263         {
264                 return E_SUCCESS;
265         }
266
267         __pSearchBarModel->SetMode(mode);
268
269         result r = ChangeMode(mode);
270         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
271                      "[E_SYSTEM] A system error has occurred. Failed to change the mode of searchbar.");
272
273         return r;
274 }
275
276 result
277 _SearchBarPresenter::SetModeLocked(bool modeLocked)
278 {
279         return __pSearchBarModel->SetModeLocked(modeLocked);
280 }
281
282 result
283 _SearchBarPresenter::Draw(void)
284 {
285         result r = E_SUCCESS;
286
287         Color bgColor = __pSearchBar->GetColor();
288
289         FloatRectangle bounds(0.0f, 0.0f, __pSearchBar->GetBoundsF().width, __pSearchBar->GetBoundsF().height);
290
291         Bitmap* pBackgroundBitmap = __pSearchBar->GetBackgroundBitmap();
292
293         if (pBackgroundBitmap)
294         {
295                 Canvas* pCanvas = __pSearchBar->GetCanvasN();
296                 r = GetLastResult();
297                 SysTryReturn(NID_UI_CTRL, (pCanvas != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
298
299                 pCanvas->SetBackgroundColor(bgColor);
300                 pCanvas->Clear();
301
302                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
303                 {
304                         pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
305                 }
306                 else
307                 {
308                         pCanvas->DrawBitmap(bounds, *pBackgroundBitmap, FloatRectangle(0.0f, 0.0f, pBackgroundBitmap->GetWidthF(), pBackgroundBitmap->GetHeightF()));
309                 }
310
311                 delete pCanvas;
312         }
313         else
314         {
315                 __pSearchBar->SetBackgroundColor(bgColor);
316         }
317
318         r = DrawIcon();
319         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
320
321         return r;
322 }
323
324 void
325 _SearchBarPresenter::SetCancelButtonVisible(bool visible)
326 {
327         if ((__pSearchBar->IsUsableCancelButton() == false) && visible)
328         {
329                 return;
330         }
331
332         if (__pCancelButton == null)
333         {
334                 return;
335         }
336
337         __pCancelButton->SetVisibleState(visible);
338
339         return;
340 }
341
342 void
343 _SearchBarPresenter::SetContainerVisible(bool visible)
344 {
345         if (__pContainer == null)
346         {
347                 return;
348         }
349
350         __pContainer->SetVisibleState(visible);
351
352         return;
353 }
354
355
356 result
357 _SearchBarPresenter::DrawIcon(void)
358 {
359         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
360                      "[E_SYSTEM] A system error has occurred. Failed to get edit instance.");
361         SysTryReturn(NID_UI_CTRL, __pIconElement, E_SYSTEM, E_SYSTEM,
362                      "[E_SYSTEM] A system error has occurred. Failed to get edit visual element.");
363
364         result r = E_SUCCESS;
365
366         Canvas* pIconCanvas = null;
367         FloatRectangle iconBounds;
368
369         bool isCustomBitmap = false;
370
371         isCustomBitmap = IS_CUSTOM_BITMAP(SEARCHBAR::ICON_NORMAL);
372
373         float iconMarginH = 0.0f;
374         float iconWidth = 0.0f;
375         float iconHeight = 0.0f;
376         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
377
378         GET_SHAPE_CONFIG(SEARCHBAR::ICON_HORIZONTAL_MARGIN, orientation, iconMarginH);
379         GET_SHAPE_CONFIG(SEARCHBAR::ICON_WIDTH, orientation, iconWidth);
380         GET_SHAPE_CONFIG(SEARCHBAR::ICON_HEIGHT, orientation, iconHeight);
381
382         iconBounds.x = iconMarginH;
383         iconBounds.y = (__pEdit->GetBoundsF().height - iconHeight) / 2.0f;
384         iconBounds.width = iconWidth;
385         iconBounds.height = iconHeight;
386
387         __pIconElement->SetBounds(FloatRectangle(iconBounds.x, iconBounds.y, iconBounds.width, iconBounds.height));
388
389         pIconCanvas = __pIconElement->GetCanvasN(FloatRectangle(0.0f, 0.0f, iconBounds.width, iconBounds.height));
390         SysTryReturnResult(NID_UI_CTRL, pIconCanvas != null, GetLastResult(), "Propagating.");
391
392         pIconCanvas->SetBackgroundColor(Color(0));
393         pIconCanvas->Clear();
394         if (__pSearchBar->IsEnabled())
395         {
396                 if (__pReplacedSearchFieldNormalBitmap != null)
397                 {
398                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pReplacedSearchFieldNormalBitmap))
399                         {
400                                 pIconCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pReplacedSearchFieldNormalBitmap);
401                         }
402                         else
403                         {
404                                 pIconCanvas->DrawBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pReplacedSearchFieldNormalBitmap);
405                         }
406                 }
407         }
408         else
409         {
410                 if (__pReplacedSearchFieldDisabledBitmap != null)
411                 {
412                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pReplacedSearchFieldDisabledBitmap))
413                         {
414                                 pIconCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pReplacedSearchFieldDisabledBitmap);
415                         }
416                         else
417                         {
418                                 pIconCanvas->DrawBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pReplacedSearchFieldDisabledBitmap);
419                         }
420                 }
421         }
422
423         if (!isCustomBitmap && __pSearchFieldEffectBitmap != null)
424         {
425                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pSearchFieldEffectBitmap))
426                 {
427                         pIconCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pSearchFieldEffectBitmap);
428                 }
429                 else
430                 {
431                         pIconCanvas->DrawBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pSearchFieldEffectBitmap);
432                 }
433         }
434
435         delete pIconCanvas;
436         pIconCanvas = null;
437
438         return r;
439 }
440
441
442 result
443 _SearchBarPresenter::ChangeMode(SearchBarMode mode)
444 {
445         result r = E_SUCCESS;
446
447         if (mode == SEARCH_BAR_MODE_NORMAL)
448         {
449                 InitializeViewModeLayout();
450                 SetCancelButtonVisible(false);
451                 SetContainerVisible(false);
452
453                 if (__pEdit)
454                 {
455                         __pEdit->ClearText();
456                         __pEdit->SetCursorDisabled(true);
457                         __pEdit->SetBounds(__searchFieldBounds);
458                         __pEdit->HideKeypad();
459                 }
460
461                 r = __pSearchBar->SendSearchBarEvent(_SEARCH_BAR_EVENT_MODE_CHANGE);
462                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
463                              "[E_SYSTEM] A system error has occurred. Failed to fire the searchbar event.");
464         }
465         else
466         {
467                 r = __pSearchBar->SendSearchBarEvent(_SEARCH_BAR_EVENT_MODE_CHANGE);
468                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
469                              "[E_SYSTEM] A system error has occurred. Failed to fire the searchbar event.");
470
471                 InitializeInputModeLayout();
472                 SetCancelButtonVisible(true);
473                 __pSearchBar->SetContentDimming();
474
475                 if (__pEdit)
476                 {
477                         __pEdit->SetCursorDisabled(false);
478
479                         float buttonWidth = 0.0f;
480                         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
481                         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
482
483                         float cancelButtonWidth = 0.0f;
484                         cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
485
486                         if (cancelButtonWidth <= buttonWidth)
487                         {
488                                 __pEdit->SetBounds(__searchFieldBounds);
489                         }
490                         __pEdit->ShowKeypad();
491                 }
492                 __pSearchBar->SetContentsArea();
493
494                 if (IsContentAreaVisible())
495                 {
496                         SetContainerVisible(true);
497                 }
498
499                 __pSearchBar->Invalidate();
500         }
501
502         return E_SUCCESS;
503 }
504
505 void
506 _SearchBarPresenter::InitializeInputModeLayout(void)
507 {
508         InitializeViewModeLayout();
509
510         if (__pSearchBar->IsUsableCancelButton() == false)
511         {
512                 return;
513         }
514
515         float horizontalMargin = 0.0f;
516         float buttonRightMargin = 0.0f;
517         float buttonLeftMargin = 0.0f;
518         float buttonWidth = 0.0f;
519         float searchFieldMinWidth = 0.0f;
520
521         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
522
523         GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
524         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_LEFT_MARGIN, orientation, buttonLeftMargin);
525         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_RIGHT_MARGIN, orientation, buttonRightMargin);
526         GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH, orientation, searchFieldMinWidth);
527         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
528
529         float buttonResizableSearchBarWidth = (horizontalMargin + searchFieldMinWidth +
530                                              buttonWidth + buttonLeftMargin + buttonRightMargin);
531
532         if (__pSearchBar->GetBoundsF().width < buttonResizableSearchBarWidth)
533         {
534                 __searchFieldBounds.width = searchFieldMinWidth;
535         }
536
537         else
538         {
539                 __searchFieldBounds.width = __pSearchBar->GetBoundsF().width - (buttonRightMargin +
540                                                                                buttonWidth + buttonLeftMargin + horizontalMargin);
541         }
542
543         __searchFieldBounds.width = (__pSearchBar->GetBoundsF().width > searchFieldMinWidth) ? __searchFieldBounds.width : searchFieldMinWidth;
544
545         float cancelButtonWidth = 0.0f;
546         cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
547
548         if (cancelButtonWidth > buttonWidth)
549         {
550                 __pSearchBar->RecalculateButtonBounds();
551         }
552
553         return;
554 }
555
556 void
557 _SearchBarPresenter::InitializeViewModeLayout(void)
558 {
559         float horizontalMargin = 0.0f;
560         float verticalMargin = 0.0f;
561         float searchFieldMinWidth = 0.0f;
562         float searchBarMinHeight = 0.0f;
563         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
564
565         GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
566         GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, verticalMargin);
567         GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH, orientation, searchFieldMinWidth);
568         GET_SHAPE_CONFIG(SEARCHBAR::MIN_HEIGHT, orientation, searchBarMinHeight);
569
570         float searchFieldMinHeight = searchBarMinHeight - (verticalMargin * 2.0f);
571
572         __searchFieldBounds.x = horizontalMargin;
573         __searchFieldBounds.y = verticalMargin;
574         __searchFieldBounds.width = __pSearchBar->GetBoundsF().width - (horizontalMargin * 2.0f);
575         __searchFieldBounds.height = __pSearchBar->GetBoundsF().height - (verticalMargin * 2.0f);
576
577         __searchFieldBounds.width = (__searchFieldBounds.width > searchFieldMinWidth) ? __searchFieldBounds.width : searchFieldMinWidth;
578         __searchFieldBounds.height = (__searchFieldBounds.height > searchFieldMinHeight) ? __searchFieldBounds.height : searchFieldMinHeight;
579
580         return;
581 }
582
583 void
584 _SearchBarPresenter::OnBoundsChanged(void)
585 {
586         _Control* pClippedGroupControl = __pSearchBar->GetClippedGroupControl();
587
588         if (pClippedGroupControl != null)
589         {
590                 pClippedGroupControl->SetBounds(FloatRectangle(FloatPoint(0.0f, 0.0f), __pSearchBar->GetSizeF()));
591         }
592
593         if (GetMode() == SEARCH_BAR_MODE_NORMAL)
594         {
595                 InitializeViewModeLayout();
596         }
597         else
598         {
599                 InitializeInputModeLayout();
600         }
601
602         result r = E_SUCCESS;
603         float cancelButtonWidth = 0.0f;
604
605         if (__pCancelButton != null)
606         {
607                 r = __pSearchBar->ResizeCancelButton();
608                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.",GetErrorMessage(r));
609
610                 cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
611         }
612
613         r = __pEdit->SetBounds(__searchFieldBounds);
614         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.",GetErrorMessage(r));
615
616         if (__pSearchBar->IsUsableCancelButton() && GetMode() == SEARCH_BAR_MODE_INPUT)
617         {
618                 float buttonWidth = 0.0f;
619                 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
620                 GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
621
622                 if (cancelButtonWidth > buttonWidth)
623                 {
624                         __pSearchBar->RecalculateButtonBounds();
625                 }
626         }
627
628         __pSearchBar->SetContentsArea();
629         __pSearchBar->Invalidate(true);
630
631         return;
632 }
633
634 void
635 _SearchBarPresenter::SetHeaderVisibleState(bool visible)
636 {
637         _Form* pForm = null;
638         _Control* pControlCore = __pEdit->GetParent();
639
640         while (true)
641         {
642                 if (pControlCore == null)
643                 {
644                         SysLog(NID_UI_CTRL,"[E_SYSTEM] The parent form is null.");
645
646                         return;
647                 }
648
649                 pForm = dynamic_cast<_Form*>(pControlCore);
650                 if (pForm != null)
651                 {
652                         break;
653                 }
654
655                 pControlCore = pControlCore->GetParent();
656         }
657
658         _Toolbar* pHeader = pForm->GetHeader();
659         if (pHeader == null)
660         {
661                 return;
662         }
663
664         pHeader->SetVisibleState(visible);
665
666         return;
667 }
668
669 }}} // Tizen::Ui::Controls