Button Resizing in SB
[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         GET_COLOR_CONFIG(SEARCHBAR::ICON_BG_DISABLED, searchFieldIconColor);
170
171         __pReplacedSearchFieldDisabledBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pSearchFieldBitmap, Color::GetColor(COLOR_ID_MAGENTA), searchFieldIconColor);
172         SysTryCatch(NID_UI_CTRL, __pReplacedSearchFieldDisabledBitmap != null, r = GetLastResult(), GetLastResult(),"[%s] Propagating.",
173                 GetErrorMessage(GetLastResult()));
174
175         delete pSearchFieldBitmap;
176         pSearchFieldBitmap = null;
177
178         return r;
179
180 CATCH:
181         delete pSearchFieldBitmap;
182         pSearchFieldBitmap = null;
183
184         delete __pSearchFieldEffectBitmap;
185         __pSearchFieldEffectBitmap = null;
186
187         delete __pReplacedSearchFieldNormalBitmap;
188         __pReplacedSearchFieldNormalBitmap = null;
189
190         return r;
191 }
192
193 result
194 _SearchBarPresenter::Install(void)
195 {
196         result r = E_SUCCESS;
197
198         _SearchBarModel* pModel = new (std::nothrow) _SearchBarModel;
199         SysTryReturn(NID_UI_CTRL, pModel, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
200
201         r = pModel->Construct();
202         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM,
203                     "[E_SYSTEM] A system error has occurred. The searchbar model construction failed.");
204
205         __pSearchBarModel = pModel;
206
207         return E_SUCCESS;
208
209 CATCH:
210         delete pModel;
211         return E_SYSTEM;
212 }
213
214 result
215 _SearchBarPresenter::UpdateContentArea(bool invalidate)
216 {
217         SearchBarMode mode = __pSearchBarModel->GetMode();
218         SysTryReturn(NID_UI_CTRL, mode == SEARCH_BAR_MODE_INPUT, E_INVALID_OPERATION, E_INVALID_OPERATION,
219                      "[E_INVALID_OPERATION] The searchbar mode cannot be updated.");
220
221         __pSearchBar->Invalidate(invalidate);
222
223         return E_SUCCESS;
224 }
225
226 result
227 _SearchBarPresenter::SetContentAreaVisible(bool visible)
228 {
229         return __pSearchBarModel->SetContentAreaVisible(visible);
230 }
231
232 bool
233 _SearchBarPresenter::IsContentAreaVisible(void) const
234 {
235         return __pSearchBarModel->IsContentAreaVisible();
236 }
237
238 SearchBarMode
239 _SearchBarPresenter::GetMode(void) const
240 {
241         return __pSearchBarModel->GetMode();
242 }
243
244 bool
245 _SearchBarPresenter::IsModeLocked(void) const
246 {
247         return __pSearchBarModel->IsModeLocked();
248 }
249
250 result
251 _SearchBarPresenter::SetMode(SearchBarMode mode)
252 {
253         SysTryReturn(NID_UI_CTRL, IsModeLocked() == false, E_INVALID_OPERATION, E_INVALID_OPERATION,
254                      "[E_INVALID_OPERATION] The searchbar mode is locked.");
255
256         if (GetMode() == mode)
257         {
258                 return E_SUCCESS;
259         }
260
261         __pSearchBarModel->SetMode(mode);
262
263         result r = ChangeMode(mode);
264         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
265                      "[E_SYSTEM] A system error has occurred. Failed to change the mode of searchbar.");
266
267         return r;
268 }
269
270 result
271 _SearchBarPresenter::SetModeLocked(bool modeLocked)
272 {
273         return __pSearchBarModel->SetModeLocked(modeLocked);
274 }
275
276 result
277 _SearchBarPresenter::Draw(void)
278 {
279         result r = E_SUCCESS;
280
281         Color bgColor = __pSearchBar->GetColor();
282
283         FloatRectangle bounds(0, 0, __pSearchBar->GetBoundsF().width, __pSearchBar->GetBoundsF().height);
284
285         Bitmap* pBackgroundBitmap = __pSearchBar->GetBackgroundBitmap();
286
287         if (pBackgroundBitmap)
288         {
289                 Canvas* pCanvas = __pSearchBar->GetCanvasN();
290                 r = GetLastResult();
291                 SysTryReturn(NID_UI_CTRL, (pCanvas != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
292
293                 pCanvas->SetBackgroundColor(bgColor);
294                 pCanvas->Clear();
295
296                 if (pBackgroundBitmap->IsNinePatchedBitmap())
297                 {
298                         pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
299                 }
300                 else
301                 {
302                         pCanvas->DrawBitmap(Point(0, 0), *pBackgroundBitmap);
303                 }
304
305                 delete pCanvas;
306         }
307         else
308         {
309                 __pSearchBar->SetBackgroundColor(bgColor);
310         }
311
312         r = DrawIcon();
313         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
314
315         return r;
316 }
317
318 void
319 _SearchBarPresenter::SetCancelButtonVisible(bool visible)
320 {
321         if ((__pSearchBar->IsUsableCancelButton() == false) && visible)
322         {
323                 return;
324         }
325
326         if (__pCancelButton == null)
327         {
328                 return;
329         }
330
331         __pCancelButton->SetVisibleState(visible);
332
333         return;
334 }
335
336 void
337 _SearchBarPresenter::SetContainerVisible(bool visible)
338 {
339         if (__pContainer == null)
340         {
341                 return;
342         }
343
344         __pContainer->SetVisibleState(visible);
345
346         return;
347 }
348
349
350 result
351 _SearchBarPresenter::DrawIcon(void)
352 {
353         SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
354                      "[E_SYSTEM] A system error has occurred. Failed to get edit instance.");
355         SysTryReturn(NID_UI_CTRL, __pIconElement, E_SYSTEM, E_SYSTEM,
356                      "[E_SYSTEM] A system error has occurred. Failed to get edit visual element.");
357
358         result r = E_SUCCESS;
359
360         Canvas* pIconCanvas = null;
361         FloatRectangle iconBounds;
362
363         bool isCustomBitmap = false;
364
365         isCustomBitmap = IS_CUSTOM_BITMAP(SEARCHBAR::ICON_NORMAL);
366
367         int iconMarginH = 0;
368         int iconWidth = 0;
369         int iconHeight = 0;
370         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
371
372         GET_SHAPE_CONFIG(SEARCHBAR::ICON_HORIZONTAL_MARGIN, orientation, iconMarginH);
373         GET_SHAPE_CONFIG(SEARCHBAR::ICON_WIDTH, orientation, iconWidth);
374         GET_SHAPE_CONFIG(SEARCHBAR::ICON_HEIGHT, orientation, iconHeight);
375
376         iconBounds.x = _CoordinateSystemUtils::ConvertToFloat(iconMarginH);
377         iconBounds.y = (__pEdit->GetBoundsF().height - iconWidth) / 2.0f;
378         iconBounds.width = _CoordinateSystemUtils::ConvertToFloat(iconWidth);
379         iconBounds.height = _CoordinateSystemUtils::ConvertToFloat(iconHeight);
380
381         __pIconElement->SetBounds(FloatRectangle(iconBounds.x, iconBounds.y, iconBounds.width, iconBounds.height));
382
383         pIconCanvas = __pIconElement->GetCanvasN(FloatRectangle(0, 0, iconBounds.width, iconBounds.height));
384         SysTryReturnResult(NID_UI_CTRL, pIconCanvas != null, GetLastResult(), "Propagating.");
385
386         pIconCanvas->SetBackgroundColor(Color(0));
387         pIconCanvas->Clear();
388         if (__pSearchBar->IsEnabled())
389         {
390                 if (__pReplacedSearchFieldNormalBitmap != null)
391                 {
392                         if (__pReplacedSearchFieldNormalBitmap->IsNinePatchedBitmap())
393                         {
394                                 pIconCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pReplacedSearchFieldNormalBitmap);
395                         }
396                         else
397                         {
398                                 pIconCanvas->DrawBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pReplacedSearchFieldNormalBitmap);
399                         }
400                 }
401         }
402         else
403         {
404                 if (__pReplacedSearchFieldDisabledBitmap != null)
405                 {
406                         if (__pReplacedSearchFieldDisabledBitmap->IsNinePatchedBitmap())
407                         {
408                                 pIconCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pReplacedSearchFieldDisabledBitmap);
409                         }
410                         else
411                         {
412                                 pIconCanvas->DrawBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pReplacedSearchFieldDisabledBitmap);
413                         }
414                 }
415         }
416
417         if (!isCustomBitmap && __pSearchFieldEffectBitmap != null)
418         {
419                 if (__pSearchFieldEffectBitmap->IsNinePatchedBitmap())
420                 {
421                         pIconCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pSearchFieldEffectBitmap);
422                 }
423                 else
424                 {
425                         pIconCanvas->DrawBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pSearchFieldEffectBitmap);
426                 }
427         }
428
429         delete pIconCanvas;
430         pIconCanvas = null;
431
432         return r;
433 }
434
435
436 result
437 _SearchBarPresenter::ChangeMode(SearchBarMode mode)
438 {
439         result r = E_SUCCESS;
440
441         if (mode == SEARCH_BAR_MODE_NORMAL)
442         {
443                 InitializeViewModeLayout();
444                 SetCancelButtonVisible(false);
445                 SetContainerVisible(false);
446
447                 if (__pEdit)
448                 {
449                         __pEdit->ClearText();
450                         __pEdit->SetCursorDisabled(true);
451                         __pEdit->SetBounds(__searchFieldBounds);
452                         __pEdit->HideKeypad();
453                 }
454
455                 r = __pSearchBar->SendSearchBarEvent(_SEARCH_BAR_EVENT_MODE_CHANGE);
456                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
457                              "[E_SYSTEM] A system error has occurred. Failed to fire the searchbar event.");
458         }
459         else
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                 InitializeInputModeLayout();
466                 SetCancelButtonVisible(true);
467                 __pSearchBar->SetContentDimming();
468
469                 if (__pEdit)
470                 {
471                         __pEdit->SetCursorDisabled(false);
472
473                         float buttonWidth = 0;
474                         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
475                         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
476
477                         float cancelButtonWidth = 0.0f;
478                         cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
479
480                         if (cancelButtonWidth <= buttonWidth)
481                         {
482                                 __pEdit->SetBounds(__searchFieldBounds);
483                         }
484
485                         __pEdit->ShowKeypad();
486                 }
487                 __pSearchBar->SetContentsArea();
488
489                 if (IsContentAreaVisible())
490                 {
491                         SetContainerVisible(true);
492                 }
493
494                 __pSearchBar->Invalidate();
495         }
496
497         return E_SUCCESS;
498 }
499
500 void
501 _SearchBarPresenter::InitializeInputModeLayout(void)
502 {
503         InitializeViewModeLayout();
504
505         if (__pSearchBar->IsUsableCancelButton() == false)
506         {
507                 return;
508         }
509
510         int horizontalMargin = 0;
511         int buttonRightMargin = 0;
512         int buttonLeftMargin = 0;
513         int buttonWidth = 0;
514         int searchFieldMinWidth = 0;
515         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
516
517         GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
518         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_LEFT_MARGIN, orientation, buttonLeftMargin);
519         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_RIGHT_MARGIN, orientation, buttonRightMargin);
520         GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH, orientation, searchFieldMinWidth);
521         GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
522         int buttonResizableSearchBarWidth = (horizontalMargin + searchFieldMinWidth +
523                                              buttonWidth + buttonLeftMargin + buttonRightMargin);
524
525         if (__pSearchBar->GetBoundsF().width < buttonResizableSearchBarWidth)
526         {
527                 __searchFieldBounds.width = searchFieldMinWidth;
528         }
529
530         else
531         {
532                 __searchFieldBounds.width = __pSearchBar->GetBoundsF().width - (buttonRightMargin +
533                                                                                buttonWidth + buttonLeftMargin + horizontalMargin);
534         }
535
536         __searchFieldBounds.width = (__pSearchBar->GetBoundsF().width > searchFieldMinWidth) ? __searchFieldBounds.width : searchFieldMinWidth;
537
538         float cancelButtonWidth = 0.0f;
539         cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
540
541
542         if (cancelButtonWidth > buttonWidth)
543         {
544                 __pSearchBar->RecalculateButtonBounds();
545         }
546
547         return;
548 }
549
550 void
551 _SearchBarPresenter::InitializeViewModeLayout(void)
552 {
553         int horizontalMargin = 0;
554         int verticalMargin = 0;
555         int searchFieldMinWidth = 0;
556         int searchBarMinHeight = 0;
557         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
558
559         GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
560         GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, verticalMargin);
561         GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH, orientation, searchFieldMinWidth);
562         GET_SHAPE_CONFIG(SEARCHBAR::MIN_HEIGHT, orientation, searchBarMinHeight);
563
564         int searchFieldMinHeight = searchBarMinHeight - (verticalMargin * 2);
565
566         __searchFieldBounds.x = _CoordinateSystemUtils::ConvertToFloat(horizontalMargin);
567         __searchFieldBounds.y = _CoordinateSystemUtils::ConvertToFloat(verticalMargin);
568         __searchFieldBounds.width = __pSearchBar->GetBoundsF().width - (horizontalMargin * 2);
569         __searchFieldBounds.height = __pSearchBar->GetBoundsF().height - (verticalMargin * 2);
570
571         __searchFieldBounds.width = (__searchFieldBounds.width > searchFieldMinWidth) ? __searchFieldBounds.width : searchFieldMinWidth;
572         __searchFieldBounds.height = (__searchFieldBounds.height > searchFieldMinHeight) ? __searchFieldBounds.height : searchFieldMinHeight;
573
574         return;
575 }
576
577 void
578 _SearchBarPresenter::OnBoundsChanged(void)
579 {
580         _Control* pClippedGroupControl = __pSearchBar->GetClippedGroupControl();
581
582         if (pClippedGroupControl != null)
583         {
584                 pClippedGroupControl->SetBounds(FloatRectangle(FloatPoint(0.0f, 0.0f), __pSearchBar->GetSizeF()));
585         }
586
587         if (GetMode() == SEARCH_BAR_MODE_NORMAL)
588         {
589                 InitializeViewModeLayout();
590         }
591         else
592         {
593                 InitializeInputModeLayout();
594         }
595
596         result r = E_SUCCESS;
597
598         if (__pCancelButton != null)
599         {
600                 r = __pSearchBar->ResizeCancelButton();
601                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.",GetErrorMessage(r));
602         }
603
604         r = __pEdit->SetBounds(__searchFieldBounds);
605         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.",GetErrorMessage(r));
606
607         if (GetMode() == SEARCH_BAR_MODE_INPUT)
608         {
609                 float buttonWidth = 0;
610                 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
611                 GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
612                 float cancelButtonWidth = 0.0f;
613                 cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
614                 if (cancelButtonWidth > buttonWidth)
615                 {
616                         __pSearchBar->RecalculateButtonBounds();
617                 }
618         }
619
620         __pSearchBar->SetContentsArea();
621
622         return;
623 }
624
625 void
626 _SearchBarPresenter::SetHeaderVisibleState(bool visible)
627 {
628         _Form* pForm = null;
629         _Control* pControlCore = __pEdit->GetParent();
630
631         while (true)
632         {
633                 if (pControlCore == null)
634                 {
635                         SysLog(NID_UI_CTRL,"[E_SYSTEM] The parent form is null.");
636
637                         return;
638                 }
639
640                 pForm = dynamic_cast<_Form*>(pControlCore);
641                 if (pForm != null)
642                 {
643                         break;
644                 }
645
646                 pControlCore = pControlCore->GetParent();
647         }
648
649         _Toolbar* pHeader = pForm->GetHeader();
650         if (pHeader == null)
651         {
652                 return;
653         }
654
655         pHeader->SetVisibleState(visible);
656
657         return;
658 }
659
660 }}} // Tizen::Ui::Controls