2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUiCtrl_SearchBarPresenter.cpp
20 * @brief This is the implementation file for the _SearchBarPresenter class.
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"
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Ui::Animations;
38 using namespace Tizen::Base;
39 using namespace Tizen::Ui;
41 namespace Tizen { namespace Ui { namespace Controls {
43 _SearchBarPresenter::_SearchBarPresenter(void)
45 , __pSearchBarModel(null)
46 , __pCancelButton(null)
49 , __searchFieldBounds(FloatRectangle())
50 , __pIconElement(null)
51 , __pReplacedSearchFieldNormalBitmap(null)
52 , __pReplacedSearchFieldDisabledBitmap(null)
53 , __pReplacedSearchBarBitmap(null)
54 , __pSearchBarBitmap(null)
55 , __pSearchFieldEffectBitmap(null)
56 , __pSearchBarEffectBitmap(null)
57 , __currentBgColor(Color())
62 _SearchBarPresenter::~_SearchBarPresenter(void)
64 delete __pSearchBarModel;
65 __pSearchBarModel = null;
67 if (__pReplacedSearchFieldNormalBitmap)
69 delete __pReplacedSearchFieldNormalBitmap;
70 __pReplacedSearchFieldNormalBitmap = null;
73 if (__pReplacedSearchFieldDisabledBitmap)
75 delete __pReplacedSearchFieldDisabledBitmap;
76 __pReplacedSearchFieldDisabledBitmap = null;
79 if (__pReplacedSearchBarBitmap)
81 delete __pReplacedSearchBarBitmap;
82 __pReplacedSearchBarBitmap = null;
85 if (__pSearchBarBitmap)
87 delete __pSearchBarBitmap;
88 __pSearchBarBitmap = null;
91 if (__pSearchFieldEffectBitmap)
93 delete __pSearchFieldEffectBitmap;
94 __pSearchFieldEffectBitmap = null;
97 if (__pSearchBarEffectBitmap)
99 delete __pSearchBarEffectBitmap;
100 __pSearchBarEffectBitmap = null;
105 _SearchBarPresenter::Construct(const _SearchBar& searchBar)
107 result r = E_SUCCESS;
108 _VisualElement* pSearchBarElement = null;
110 __pSearchBar = const_cast <_SearchBar*>(&searchBar);
111 SysTryReturn(NID_UI_CTRL, __pSearchBar, E_SYSTEM, E_SYSTEM,
112 "[E_SYSTEM] A system error has occurred. The searchbar instance is null.");
114 __pCancelButton = __pSearchBar->GetSearchBarButton();
115 SysTryReturn(NID_UI_CTRL, __pCancelButton, E_SYSTEM, E_SYSTEM,
116 "[E_SYSTEM] A system error has occurred. The cancel button instance is null.");
118 __pEdit = __pSearchBar->GetSearchField();
119 SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
120 "[E_SYSTEM] A system error has occurred. The edit instance is null.");
122 __pContainer = __pSearchBar->GetSearchBarContainer();
123 SysTryReturn(NID_UI_CTRL, __pContainer, E_SYSTEM, E_SYSTEM,
124 " [E_SYSTEM] A system error has occurred. Failed to get the content.");
126 r = LoadSearchBarBitmaps();
127 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
129 _VisualElement* pEditElement = __pEdit->GetVisualElement();
130 SysTryReturn(NID_UI_CTRL, pEditElement, E_SYSTEM, E_SYSTEM,
131 "[E_SYSTEM] A system error has occurred. Failed to get edit visual element.");
133 __pIconElement = new (std::nothrow) _VisualElement();
134 SysTryCatch(NID_UI_CTRL, __pIconElement, , E_OUT_OF_MEMORY,
135 "[E_OUT_OF_MEMORY] Memory allocation failed.");
137 r = __pIconElement->Construct();
138 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
140 __pIconElement->SetShowState(true);
142 r = __pIconElement->SetSurfaceOpaque(false);
143 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
145 __pIconElement->SetImplicitAnimationEnabled(false);
147 r = pEditElement->AttachChild(*__pIconElement);
148 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
150 pSearchBarElement = __pSearchBar->GetVisualElement();
151 SysTryCatch(NID_UI_CTRL, pSearchBarElement, , E_SYSTEM,
152 "[E_SYSTEM] A system error has occurred. Failed to get searchbar's visual element.");
159 __pIconElement->Destroy();
160 __pIconElement = null;
167 _SearchBarPresenter::LoadSearchBarBitmaps()
169 result r = E_SUCCESS;
170 Color searchFieldIconColor;
171 Bitmap* pSearchFieldBitmap;
173 r = GET_BITMAP_CONFIG_N(SEARCHBAR::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pSearchBarBitmap);
174 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
176 r = GET_BITMAP_CONFIG_N(SEARCHBAR::BG_NORMAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pSearchBarEffectBitmap);
177 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r,"[%s] Propagating.", GetErrorMessage(r));
179 __currentBgColor = __pSearchBar->GetColor();
181 __pReplacedSearchBarBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pSearchBarBitmap, Color::GetColor(COLOR_ID_MAGENTA), __currentBgColor);
182 SysTryCatch(NID_UI_CTRL, __pReplacedSearchBarBitmap != null, r = GetLastResult(), GetLastResult(),"[%s] Propagating.",
183 GetErrorMessage(GetLastResult()));
185 r = GET_BITMAP_CONFIG_N(SEARCHBAR::ICON_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pSearchFieldBitmap);
186 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
188 r = GET_BITMAP_CONFIG_N(SEARCHBAR::ICON_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pSearchFieldEffectBitmap);
189 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r,"[%s] Propagating.", GetErrorMessage(r));
191 GET_COLOR_CONFIG(SEARCHBAR::ICON_BG_NORMAL, searchFieldIconColor);
193 __pReplacedSearchFieldNormalBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pSearchFieldBitmap, Color::GetColor(COLOR_ID_MAGENTA), searchFieldIconColor);
194 SysTryCatch(NID_UI_CTRL, __pReplacedSearchFieldNormalBitmap != null, r = GetLastResult(), GetLastResult(),"[%s] Propagating.",
195 GetErrorMessage(GetLastResult()));
197 delete pSearchFieldBitmap;
198 pSearchFieldBitmap = null;
200 r = GET_BITMAP_CONFIG_N(SEARCHBAR::ICON_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pSearchFieldBitmap);
201 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r,"[%s] Propagating.", GetErrorMessage(r));
203 GET_COLOR_CONFIG(SEARCHBAR::ICON_BG_DISABLED, searchFieldIconColor);
205 __pReplacedSearchFieldDisabledBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pSearchFieldBitmap, Color::GetColor(COLOR_ID_MAGENTA), searchFieldIconColor);
206 SysTryCatch(NID_UI_CTRL, __pReplacedSearchFieldDisabledBitmap != null, r = GetLastResult(), GetLastResult(),"[%s] Propagating.",
207 GetErrorMessage(GetLastResult()));
209 delete pSearchFieldBitmap;
210 pSearchFieldBitmap = null;
215 delete __pSearchBarBitmap;
216 __pSearchBarBitmap = null;
218 delete __pSearchBarEffectBitmap;
219 __pSearchBarEffectBitmap = null;
221 delete __pReplacedSearchBarBitmap;
222 __pReplacedSearchBarBitmap = null;
224 delete pSearchFieldBitmap;
225 pSearchFieldBitmap = null;
227 delete __pSearchFieldEffectBitmap;
228 __pSearchFieldEffectBitmap = null;
230 delete __pReplacedSearchFieldNormalBitmap;
231 __pReplacedSearchFieldNormalBitmap = null;
237 _SearchBarPresenter::Install(void)
239 result r = E_SUCCESS;
241 _SearchBarModel* pModel = new (std::nothrow) _SearchBarModel;
242 SysTryReturn(NID_UI_CTRL, pModel, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
244 r = pModel->Construct();
245 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM,
246 "[E_SYSTEM] A system error has occurred. The searchbar model construction failed.");
248 __pSearchBarModel = pModel;
258 _SearchBarPresenter::UpdateContentArea(bool invalidate)
260 SearchBarMode mode = __pSearchBarModel->GetMode();
261 SysTryReturn(NID_UI_CTRL, mode == SEARCH_BAR_MODE_INPUT, E_INVALID_OPERATION, E_INVALID_OPERATION,
262 "[E_INVALID_OPERATION] The searchbar mode cannot be updated.");
264 __pSearchBar->Invalidate(invalidate);
270 _SearchBarPresenter::SetContentAreaVisible(bool visible)
272 return __pSearchBarModel->SetContentAreaVisible(visible);
276 _SearchBarPresenter::IsContentAreaVisible(void) const
278 return __pSearchBarModel->IsContentAreaVisible();
282 _SearchBarPresenter::GetMode(void) const
284 return __pSearchBarModel->GetMode();
288 _SearchBarPresenter::IsModeLocked(void) const
290 return __pSearchBarModel->IsModeLocked();
294 _SearchBarPresenter::SetMode(SearchBarMode mode)
296 SysTryReturn(NID_UI_CTRL, IsModeLocked() == false, E_INVALID_OPERATION, E_INVALID_OPERATION,
297 "[E_INVALID_OPERATION] The searchbar mode is locked.");
299 if (GetMode() == mode)
304 __pSearchBarModel->SetMode(mode);
306 result r = ChangeMode(mode);
307 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
308 "[E_SYSTEM] A system error has occurred. Failed to change the mode of searchbar.");
314 _SearchBarPresenter::SetModeLocked(bool modeLocked)
316 return __pSearchBarModel->SetModeLocked(modeLocked);
320 _SearchBarPresenter::Draw(void)
322 result r = E_SUCCESS;
324 Color bgColor = __pSearchBar->GetColor();
326 FloatRectangle bounds(0.0f, 0.0f, __pSearchBar->GetBoundsF().width, __pSearchBar->GetBoundsF().height);
328 Bitmap* pBackgroundBitmap = __pSearchBar->GetBackgroundBitmap();
330 if (!pBackgroundBitmap)
332 r = DrawSearchBarDefaultBitmap();
333 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
337 String imagePath = L"";
339 if (!_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
341 imagePath = _BitmapImpl::GetInstance(*pBackgroundBitmap)->GetFileName();
344 if(!imagePath.IsEmpty())
346 __pSearchBar->GetVisualElement()->SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255, (float)bgColor.GetGreen() / 255, (float)bgColor.GetBlue() / 255, (float)bgColor.GetAlpha() / 255));
347 __pSearchBar->GetVisualElement()->SetImageSource(imagePath);
352 __pSearchBar->GetVisualElement()->SetImageSource(L"");
353 __lazyDecode = false;
354 Canvas* pCanvas = __pSearchBar->GetCanvasN();
356 SysTryReturn(NID_UI_CTRL, (pCanvas != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
358 pCanvas->SetBackgroundColor(bgColor);
361 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
363 pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
367 pCanvas->DrawBitmap(bounds, *pBackgroundBitmap, FloatRectangle(0.0f, 0.0f, pBackgroundBitmap->GetWidthF(), pBackgroundBitmap->GetHeightF()));
375 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
381 _SearchBarPresenter::DrawSearchBarDefaultBitmap(void)
383 result r = E_SUCCESS;
384 Canvas* pCanvas = null;
385 bool isCustomBitmap = false;
386 FloatRectangle bounds = __pSearchBar->GetBoundsF();
388 Color bgColor = __pSearchBar->GetColor();
390 if (bgColor != __currentBgColor)
392 delete __pReplacedSearchBarBitmap;
393 __pReplacedSearchBarBitmap = null;
395 __pReplacedSearchBarBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pSearchBarBitmap, Color::GetColor(COLOR_ID_MAGENTA), bgColor);
397 SysTryReturn(NID_UI_CTRL, (__pReplacedSearchBarBitmap != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
398 __currentBgColor = bgColor;
401 isCustomBitmap = IS_CUSTOM_BITMAP(SEARCHBAR::BG_NORMAL);
403 pCanvas = __pSearchBar->GetCanvasN();
405 SysTryReturn(NID_UI_CTRL, (pCanvas != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
407 pCanvas->SetBackgroundColor(Color(0));
410 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pReplacedSearchBarBitmap))
412 pCanvas->DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height), *__pReplacedSearchBarBitmap);
416 pCanvas->DrawBitmap(FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height), *__pReplacedSearchBarBitmap);
419 if (!isCustomBitmap && __pSearchBarEffectBitmap != null)
421 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pSearchBarEffectBitmap))
423 pCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, bounds.width, bounds.height), *__pSearchBarEffectBitmap);
427 pCanvas->DrawBitmap(FloatRectangle(0, 0, bounds.width, bounds.height), *__pSearchBarEffectBitmap);
436 _SearchBarPresenter::SetCancelButtonVisible(bool visible)
438 if ((__pSearchBar->IsUsableCancelButton() == false) && visible)
443 if (__pCancelButton == null)
448 __pCancelButton->SetVisibleState(visible);
454 _SearchBarPresenter::SetContainerVisible(bool visible)
456 if (__pContainer == null)
461 __pContainer->SetVisibleState(visible);
468 _SearchBarPresenter::DrawIcon(void)
470 SysTryReturn(NID_UI_CTRL, __pEdit, E_SYSTEM, E_SYSTEM,
471 "[E_SYSTEM] A system error has occurred. Failed to get edit instance.");
472 SysTryReturn(NID_UI_CTRL, __pIconElement, E_SYSTEM, E_SYSTEM,
473 "[E_SYSTEM] A system error has occurred. Failed to get edit visual element.");
475 result r = E_SUCCESS;
477 Canvas* pIconCanvas = null;
478 FloatRectangle iconBounds;
480 bool isCustomBitmap = false;
482 isCustomBitmap = IS_CUSTOM_BITMAP(SEARCHBAR::ICON_NORMAL);
484 float iconMarginH = 0.0f;
485 float iconWidth = 0.0f;
486 float iconHeight = 0.0f;
487 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
489 GET_SHAPE_CONFIG(SEARCHBAR::ICON_HORIZONTAL_MARGIN, orientation, iconMarginH);
490 GET_SHAPE_CONFIG(SEARCHBAR::ICON_WIDTH, orientation, iconWidth);
491 GET_SHAPE_CONFIG(SEARCHBAR::ICON_HEIGHT, orientation, iconHeight);
493 iconBounds.x = iconMarginH;
494 iconBounds.y = (__pEdit->GetBoundsF().height - iconHeight) / 2.0f;
495 iconBounds.width = iconWidth;
496 iconBounds.height = iconHeight;
498 __pIconElement->SetBounds(FloatRectangle(iconBounds.x, iconBounds.y, iconBounds.width, iconBounds.height));
500 pIconCanvas = __pIconElement->GetCanvasN(FloatRectangle(0.0f, 0.0f, iconBounds.width, iconBounds.height));
501 SysTryReturnResult(NID_UI_CTRL, pIconCanvas != null, GetLastResult(), "Propagating.");
503 pIconCanvas->SetBackgroundColor(Color(0));
504 pIconCanvas->Clear();
505 if (__pSearchBar->IsEnabled())
507 if (__pReplacedSearchFieldNormalBitmap != null)
509 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pReplacedSearchFieldNormalBitmap))
511 pIconCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pReplacedSearchFieldNormalBitmap);
515 pIconCanvas->DrawBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pReplacedSearchFieldNormalBitmap);
521 if (__pReplacedSearchFieldDisabledBitmap != null)
523 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pReplacedSearchFieldDisabledBitmap))
525 pIconCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pReplacedSearchFieldDisabledBitmap);
529 pIconCanvas->DrawBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pReplacedSearchFieldDisabledBitmap);
534 if (!isCustomBitmap && __pSearchFieldEffectBitmap != null)
536 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pSearchFieldEffectBitmap))
538 pIconCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pSearchFieldEffectBitmap);
542 pIconCanvas->DrawBitmap(FloatRectangle(0, 0, iconBounds.width, iconBounds.height), *__pSearchFieldEffectBitmap);
554 _SearchBarPresenter::ChangeMode(SearchBarMode mode)
556 result r = E_SUCCESS;
558 if (mode == SEARCH_BAR_MODE_NORMAL)
560 __pSearchBar->SetFocusCallbackParameter(true);
561 InitializeViewModeLayout();
562 SetCancelButtonVisible(false);
563 SetContainerVisible(false);
567 __pEdit->ClearText();
568 __pEdit->SetBounds(__searchFieldBounds);
569 if (__pEdit->IsFocused())
571 __pEdit->HideKeypad();
575 r = __pSearchBar->SendSearchBarEvent(_SEARCH_BAR_EVENT_MODE_CHANGE);
576 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
577 "[E_SYSTEM] A system error has occurred. Failed to fire the searchbar event.");
581 r = __pSearchBar->SendSearchBarEvent(_SEARCH_BAR_EVENT_MODE_CHANGE);
582 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
583 "[E_SYSTEM] A system error has occurred. Failed to fire the searchbar event.");
585 InitializeInputModeLayout();
586 SetCancelButtonVisible(true);
587 __pSearchBar->SetContentDimming();
591 float buttonWidth = 0.0f;
592 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
593 GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
595 float cancelButtonWidth = 0.0f;
596 cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
598 if (cancelButtonWidth <= buttonWidth)
600 __pEdit->SetBounds(__searchFieldBounds);
602 __pEdit->ShowKeypad();
604 __pSearchBar->SetContentsArea();
606 if (IsContentAreaVisible())
608 SetContainerVisible(true);
611 __pSearchBar->Invalidate();
618 _SearchBarPresenter::InitializeInputModeLayout(void)
620 InitializeViewModeLayout();
622 if (__pSearchBar->IsUsableCancelButton() == false)
627 float horizontalMargin = 0.0f;
628 float buttonRightMargin = 0.0f;
629 float buttonLeftMargin = 0.0f;
630 float buttonWidth = 0.0f;
631 float searchFieldMinWidth = 0.0f;
633 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
635 GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
636 GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_LEFT_MARGIN, orientation, buttonLeftMargin);
637 GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_RIGHT_MARGIN, orientation, buttonRightMargin);
638 GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH, orientation, searchFieldMinWidth);
639 GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
641 float buttonResizableSearchBarWidth = (horizontalMargin + searchFieldMinWidth +
642 buttonWidth + buttonLeftMargin + buttonRightMargin);
644 if (__pSearchBar->GetBoundsF().width < buttonResizableSearchBarWidth)
646 __searchFieldBounds.width = searchFieldMinWidth;
651 __searchFieldBounds.width = __pSearchBar->GetBoundsF().width - (buttonRightMargin +
652 buttonWidth + buttonLeftMargin + horizontalMargin);
655 __searchFieldBounds.width = (__pSearchBar->GetBoundsF().width > searchFieldMinWidth) ? __searchFieldBounds.width : searchFieldMinWidth;
657 float cancelButtonWidth = 0.0f;
658 cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
660 if (cancelButtonWidth > buttonWidth)
662 __pSearchBar->RecalculateButtonBounds();
669 _SearchBarPresenter::InitializeViewModeLayout(void)
671 float horizontalMargin = 0.0f;
672 float verticalMargin = 0.0f;
673 float searchBarMinWidthModeNormal = 0.0f;
674 float searchBarMinHeight = 0.0f;
675 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
677 GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
678 GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, verticalMargin);
679 GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH_NORMAL_MODE, orientation, searchBarMinWidthModeNormal);
680 GET_SHAPE_CONFIG(SEARCHBAR::MIN_HEIGHT, orientation, searchBarMinHeight);
682 float searchFieldMinHeight = searchBarMinHeight - (verticalMargin * 2.0f);
684 __searchFieldBounds.x = horizontalMargin;
685 if (__pSearchBar->GetBoundsF().height < searchBarMinHeight)
687 verticalMargin = (__pSearchBar->GetBoundsF().height - searchFieldMinHeight)/2.0f;
688 if (verticalMargin < 0.0f)
690 verticalMargin = 0.0f;
693 __searchFieldBounds.y = verticalMargin;
694 __searchFieldBounds.width = __pSearchBar->GetBoundsF().width - (horizontalMargin * 2.0f);
695 __searchFieldBounds.height = __pSearchBar->GetBoundsF().height - (verticalMargin * 2.0f);
697 __searchFieldBounds.width = (__searchFieldBounds.width > searchBarMinWidthModeNormal) ? __searchFieldBounds.width : searchBarMinWidthModeNormal;
698 __searchFieldBounds.height = (__searchFieldBounds.height > searchFieldMinHeight) ? __searchFieldBounds.height : searchFieldMinHeight;
704 _SearchBarPresenter::OnBoundsChanged(void)
706 _Control* pClippedGroupControl = __pSearchBar->GetClippedGroupControl();
708 if (pClippedGroupControl != null)
710 pClippedGroupControl->SetBounds(FloatRectangle(FloatPoint(0.0f, 0.0f), __pSearchBar->GetSizeF()));
713 if (GetMode() == SEARCH_BAR_MODE_NORMAL)
715 InitializeViewModeLayout();
719 InitializeInputModeLayout();
722 result r = E_SUCCESS;
723 float cancelButtonWidth = 0.0f;
725 if (__pCancelButton != null)
727 r = __pSearchBar->ResizeCancelButton();
728 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.",GetErrorMessage(r));
730 cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
733 r = __pEdit->SetBounds(__searchFieldBounds);
734 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.",GetErrorMessage(r));
736 if (__pSearchBar->IsUsableCancelButton() && GetMode() == SEARCH_BAR_MODE_INPUT)
738 float buttonWidth = 0.0f;
739 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
740 GET_SHAPE_CONFIG(SEARCHBAR::BUTTON_WIDTH, orientation, buttonWidth);
742 if (cancelButtonWidth > buttonWidth)
744 __pSearchBar->RecalculateButtonBounds();
748 __pSearchBar->SetContentsArea();
749 __pSearchBar->Invalidate(true);
755 _SearchBarPresenter::OnCanvasRequestedN(const FloatRectangle& bounds)
757 Canvas* pCanvas = null;
759 if (__lazyDecode == true)
761 Bitmap* pBackgroundBitmap = __pSearchBar->GetBackgroundBitmap();
762 SysTryReturn(NID_UI_CTRL, pBackgroundBitmap != null, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get the background bitmap.");
764 //Decode the bitmap explicitly
765 pBackgroundBitmap->IsNinePatchedBitmap();
767 pCanvas = __pSearchBar->GetCanvasN();
774 _SearchBarPresenter::SetHeaderVisibleState(bool visible)
777 _Control* pControlCore = __pEdit->GetParent();
781 if (pControlCore == null)
783 SysLog(NID_UI_CTRL,"[E_SYSTEM] The parent form is null.");
788 pForm = dynamic_cast<_Form*>(pControlCore);
794 pControlCore = pControlCore->GetParent();
797 _Toolbar* pHeader = pForm->GetHeader();
803 pHeader->SetVisibleState(visible);
808 }}} // Tizen::Ui::Controls