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.
18 * @file FUiCtrl_ToolbarPresenter.cpp
19 * @brief This is the implementation file for the _ToolbarPresenter class.
22 #include <FBaseSysLog.h>
23 #include <FUiAnimVisualElementPropertyAnimation.h>
24 #include <FUiAnimVisualElement.h>
25 #include <FGrp_BitmapImpl.h>
26 #include <FGrp_CanvasImpl.h>
27 #include <FGrp_FontImpl.h>
28 #include <FGrp_TextCommon.h>
29 #include <FGrp_TextTextSimple.h>
30 #include "FUiAnim_VisualElementImpl.h"
31 #include "FUi_CoordinateSystemUtils.h"
32 #include "FUi_UiTouchEvent.h"
33 #include "FUi_ResourceManager.h"
34 #include "FUiCtrl_Label.h"
35 #include "FUiCtrl_ToolbarPresenter.h"
36 #include "FUiCtrl_ToolbarModel.h"
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Runtime;
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Graphics::_Text;
42 using namespace Tizen::Ui::Animations;
44 namespace Tizen { namespace Ui { namespace Controls
47 _ToolbarPresenter::_ToolbarPresenter(void)
49 , __pToolbarModel(null)
51 , __tabEditEnabled(false)
52 , __beingEdited(false)
53 , __touchInitiatedInToolbar(false)
55 , __pressedItemIndex(-1)
56 , __initialPressesItemStatus(_BUTTON_STATUS_NORMAL)
58 , __pTitleBackgroundBitmap(null)
59 , __pTitleSlideTimer(null)
60 , __pFlickAnimationTimer(null)
61 , __titleRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
62 , __descriptionRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
64 , __pTitleTextFont(null)
66 , __pDescriptionTextObject(null)
67 , __pTitleTextObject(null)
69 , __moveDistance(0.0f)
71 , __flickDistance(0.0f)
73 , __firstLoadedItemIndex(0)
74 , __lastLoadedItemIndex(0)
75 , __tabSlideLeft(false)
76 , __tabSlideRight(false)
77 , __portraitSize(FloatDimension(0.0f, 0.0f))
78 , __landscapeSize(FloatDimension(0.0f, 0.0f))
82 , __titlePressed(false)
83 , __titleSliding(false)
85 __currentTouchPosition = FloatPoint(0.0f, 0.0f);
88 _ToolbarPresenter::~_ToolbarPresenter(void)
92 delete __pToolbarModel;
93 __pToolbarModel = null;
98 __pToolbar->DetachChild(*__pEditItem);
103 if (__pTitleBackgroundBitmap)
105 delete __pTitleBackgroundBitmap;
106 __pTitleBackgroundBitmap = null;
109 if (__pTitleSlideTimer)
111 delete __pTitleSlideTimer;
112 __pTitleSlideTimer = null;
115 if (__pFlickAnimationTimer)
117 delete __pFlickAnimationTimer;
118 __pFlickAnimationTimer = null;
121 if (__pDescriptionTextObject)
123 delete __pDescriptionTextObject;
124 __pDescriptionTextObject = null;
127 if (__pTitleTextObject)
129 delete __pTitleTextObject;
130 __pTitleTextObject = null;
135 _ToolbarPresenter::Construct(const _Toolbar& toolbar)
137 __pToolbar = const_cast<_Toolbar*>(&toolbar);
142 __fontStyle = FONT_STYLE_BOLD;
144 __portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
145 __landscapeSize = FloatDimension(__portraitSize.height, __portraitSize.width);
147 if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
149 width = __portraitSize.width;
150 height = __portraitSize.height;
154 width = __landscapeSize.width;
155 height = __landscapeSize.height;
158 __flickAnimation.SetSizeInformation(width, height, DEVICE_SIZE_HORIZONTAL, DEVICE_SIZE_VERTICAL);
159 __flickAnimation.SetSensitivity(FLICK_ANIMATION_FPS_TAB, FLICK_ANIMATION_SENSITIVITY_TAB);
160 __flickAnimation.SetDirection(FD_HORIZONTAL);
166 _ToolbarPresenter::Install(void)
168 _ToolbarModel* pModel = new (std::nothrow) _ToolbarModel();
172 result r = pModel->Construct();
178 _ToolbarPresenter::Draw(void)
180 result r = E_SUCCESS;
182 ToolbarStyle style = __pToolbar->GetStyle();
188 Canvas* pCanvas = __pToolbar->GetCanvasN();
192 SysLog(NID_UI_CTRL, "Cannot get a canvas.");
197 float buttonItemGap = 0.0f;
198 float dividerBaseHeight = 0.0f;
199 float dividerHeight = 0.0f;
201 float footerButtonItemWidth = 0.0f;
202 float footerButtonItemHeight = 0.0f;
203 float fontSize = 0.0f;
205 float dividerTopMargin = 0.0f;
206 float segmentedItemHeight = 0.0f;
208 FloatRectangle bounds(0.0f, 0.0f, __pToolbar->GetBoundsF().width, __pToolbar->GetBoundsF().height);
210 int itemCount = __pToolbar->GetItemCount();
212 __portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
213 __landscapeSize = FloatDimension(__portraitSize.height, __portraitSize.width);
215 if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
217 if (bounds.width > __portraitSize.width)
219 bounds.width = __portraitSize.width;
224 if (bounds.width > __landscapeSize.width)
226 bounds.width = __landscapeSize.width;
230 GET_SHAPE_CONFIG(HEADER::DIVIDER_WIDTH, __pToolbar->GetOrientation(), buttonItemGap);
232 if (style == TOOLBAR_TAB_LARGE)
234 GET_SHAPE_CONFIG(HEADER::TAB_LARGE_DIVIDER_HEIGHT, __pToolbar->GetOrientation(), dividerHeight);
238 GET_SHAPE_CONFIG(HEADER::DIVIDER_HEIGHT, __pToolbar->GetOrientation(), dividerHeight);
241 GET_SHAPE_CONFIG(HEADER::SEGMENTED_ITEM_HEIGHT, __pToolbar->GetOrientation(), segmentedItemHeight);
243 GET_SHAPE_CONFIG(FOOTER::BUTTON_ITEM_WIDTH, __pToolbar->GetOrientation(), footerButtonItemWidth);
244 GET_SHAPE_CONFIG(FOOTER::BUTTON_ITEM_HEIGHT, __pToolbar->GetOrientation(), footerButtonItemHeight);
246 if (style == TOOLBAR_TITLE || style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
248 if (__pTitleBackgroundBitmap)
250 delete __pTitleBackgroundBitmap;
251 __pTitleBackgroundBitmap = null;
254 if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
256 GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE_WITH_SEGMENTED, __pToolbar->GetOrientation(), fontSize);
258 if (!__titleText.IsEmpty())
260 __fontSize = fontSize;
262 __pTitleTextFont = __pToolbar->GetFallbackFont();
264 SysTryReturn(NID_UI_CTRL, __pTitleTextFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
266 __pTitleTextObject->SetFont(__pTitleTextFont, 0, __pTitleTextObject->GetTextLength());
269 else if (style == TOOLBAR_TITLE && __pToolbar->GetDescriptionText() != L""
270 && __pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) == ANIMATION_STOPPED)
272 GET_SHAPE_CONFIG(HEADER::TITLE_TOP_MARGIN_WITH_DESCRIPTION, __pToolbar->GetOrientation(), __titleRect.y);
273 __titleRect.height = _FontImpl::GetInstance(*__pTitleTextFont)->GetLeadingF();
274 GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE_WITH_DESCRIPTION, __pToolbar->GetOrientation(), fontSize);
276 DrawDescriptionText();
278 if(!__titleText.IsEmpty())
280 __fontSize = fontSize;
282 __pTitleTextFont = __pToolbar->GetFallbackFont();
284 SysTryReturn(NID_UI_CTRL, __pTitleTextFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
286 __pTitleTextObject->SetFont(__pTitleTextFont, 0, __pTitleTextObject->GetTextLength());
290 __pTitleBackgroundBitmap = new (std::nothrow) Bitmap();
291 __pTitleBackgroundBitmap->Construct(*pCanvas, __titleRect);
293 DrawTitleText(pCanvas);
296 if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
298 GET_SHAPE_CONFIG(HEADER::SEGMENTED_ITEM_HEIGHT, __pToolbar->GetOrientation(), dividerBaseHeight);
299 GET_SHAPE_CONFIG(HEADER::TITLE_HEIGHT_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), dividerTopMargin);
303 GET_SHAPE_CONFIG(HEADER::HEIGHT, __pToolbar->GetOrientation(), dividerBaseHeight);
306 if (style == TOOLBAR_TITLE || style == TOOLBAR_HEADER_SEGMENTED || style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE)
308 if (__pToolbar->GetButton(RIGHT_BUTTON))
310 if (__pToolbar->GetButton(LEFT_BUTTON))
312 DrawDivider(FloatPoint(bounds.width - __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF().width - buttonItemGap,
313 dividerTopMargin + (dividerBaseHeight - dividerHeight) / 2), pCanvas);
315 DrawDivider(FloatPoint(bounds.width - __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF().width - buttonItemGap
316 - __pToolbar->GetButton(LEFT_BUTTON)->GetBoundsF().width - buttonItemGap,
317 dividerTopMargin + (dividerBaseHeight - dividerHeight) / 2), pCanvas);
321 DrawDivider(FloatPoint(bounds.width - __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF().width - buttonItemGap,
322 dividerTopMargin + (dividerBaseHeight - dividerHeight) / 2), pCanvas);
327 if (__pToolbar->GetButton(LEFT_BUTTON))
329 DrawDivider(FloatPoint(bounds.width - __pToolbar->GetButton(LEFT_BUTTON)->GetBoundsF().width - buttonItemGap,
330 dividerTopMargin + (dividerBaseHeight - dividerHeight) / 2), pCanvas);
334 else if (style == TOOLBAR_SEGMENTED || style == TOOLBAR_TEXT || style == TOOLBAR_ICON || style == TOOLBAR_ICON_TEXT || style == TOOLBAR_COMMAND)
336 if (__pToolbar->GetButton(RIGHT_BUTTON))
338 DrawDivider(FloatPoint(bounds.width - __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF().width - buttonItemGap,
339 dividerTopMargin + (dividerBaseHeight - dividerHeight) / 2), pCanvas);
342 if (__pToolbar->GetButton(LEFT_BUTTON))
344 DrawDivider(FloatPoint(__pToolbar->GetButton(LEFT_BUTTON)->GetBoundsF().width,
345 dividerTopMargin + (dividerBaseHeight - dividerHeight) / 2), pCanvas);
356 if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
358 for (int i = 0; i < itemCount - 1 ; i++)
360 DrawDivider(FloatPoint(__pToolbar->GetItem(i)->GetBoundsF().x + __pToolbar->GetItem(i)->GetBoundsF().width,
361 dividerTopMargin + (dividerBaseHeight - dividerHeight) / 2), pCanvas);
366 for (int i = 0; i < itemCount - 1 ; i++)
368 DrawDivider(FloatPoint(__pToolbar->GetItem(i)->GetBoundsF().x + __pToolbar->GetItem(i)->GetBoundsF().width,
369 (__pToolbar->GetBoundsF().height - dividerHeight) / 2), pCanvas);
376 if ((style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE
377 || style == TOOLBAR_SEGMENTED || style == TOOLBAR_HEADER_SEGMENTED || style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE)
378 && __pToolbar->GetItemCount() > 0 && __pToolbarModel->GetSelectedItemIndex() == -1)
380 int firstEnabledItemIndex = __pToolbar->GetFirstEnabledItemIndex();
382 if(firstEnabledItemIndex != -1)
384 __pToolbar->SetItemSelected(firstEnabledItemIndex, true, false);
388 __initialDraw = false;
397 _ToolbarPresenter::DrawBackground(void)
399 Canvas* pCanvas = __pToolbar->GetCanvasN();
403 SysLog(NID_UI_CTRL, "Cannot get a canvas.");
408 ToolbarStyle style = __pToolbar->GetStyle();
410 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
413 if (style == TOOLBAR_SOFTKEY)
420 Bitmap* pReplacementColorBackgroundBitmap = null;
421 Bitmap* pBackgroundBitmap = null;
422 //Bitmap* pBackgroundEffectBitmap = null;
424 FloatRectangle bounds(0.0f, 0.0f, __pToolbar->GetBoundsF().width, __pToolbar->GetBoundsF().height);
426 __portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
427 __landscapeSize = FloatDimension(__portraitSize.height, __portraitSize.width);
429 if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
431 if (bounds.width > __portraitSize.width)
433 bounds.width = __portraitSize.width;
438 if (bounds.width > __landscapeSize.width)
440 bounds.width = __landscapeSize.width;
444 pBackgroundBitmap = __pToolbar->GetBackgroundBitmap();
445 //pBackgroundEffectBitmap = __pToolbar->GetBackgroundEffectBitmap();
447 pReplacementColorBackgroundBitmap =
448 _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pToolbar->GetColor());
450 if (__pToolbar->IsUserBackgroundBitmap())
452 if (pBackgroundBitmap)
454 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
456 pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
460 pCanvas->DrawBitmap(bounds, *pBackgroundBitmap, FloatRectangle(0.0f, 0.0f, pBackgroundBitmap->GetWidthF(), pBackgroundBitmap->GetHeightF()));
465 pCanvas->FillRectangle(__pToolbar->GetColor(), bounds);
470 if (pReplacementColorBackgroundBitmap)
472 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
474 pCanvas->DrawNinePatchedBitmap(bounds, *pReplacementColorBackgroundBitmap);
478 pCanvas->DrawBitmap(bounds, *pReplacementColorBackgroundBitmap, FloatRectangle(0.0f, 0.0f, pReplacementColorBackgroundBitmap->GetWidthF(), pReplacementColorBackgroundBitmap->GetHeightF()));
483 pCanvas->FillRectangle(__pToolbar->GetColor(), bounds);
486 //if (pBackgroundEffectBitmap)
488 // if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundEffectBitmap))
490 // pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundEffectBitmap);
494 // pCanvas->DrawBitmap(bounds, *pBackgroundEffectBitmap, FloatRectangle(0.0f, 0.0f, pBackgroundEffectBitmap->GetWidthF(), pBackgroundEffectBitmap->GetHeightF()));
499 if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
501 Bitmap* pSubTitleEffectBitmap = null;
502 Color subTitleEffectColor;
503 float topMargin = 0.0f;
505 GET_BITMAP_CONFIG_N(HEADER::SUB_TITLE_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, pSubTitleEffectBitmap);
506 GET_COLOR_CONFIG(HEADER::SUB_TITLE_EFFECT_NORMAL, subTitleEffectColor);
507 GET_SHAPE_CONFIG(HEADER::TITLE_HEIGHT_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), topMargin);
509 FloatRectangle subTitleEffectBounds(0.0f, topMargin, __pToolbar->GetBoundsF().width, __pToolbar->GetBoundsF().height - topMargin);
511 Bitmap* pReColorSubTitleEffectBitmap = null;
513 pReColorSubTitleEffectBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pSubTitleEffectBitmap, Color::GetColor(COLOR_ID_MAGENTA), subTitleEffectColor);
515 if (pReColorSubTitleEffectBitmap)
517 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReColorSubTitleEffectBitmap))
519 pCanvas->DrawNinePatchedBitmap(subTitleEffectBounds, *pReColorSubTitleEffectBitmap);
523 pCanvas->DrawBitmap(subTitleEffectBounds, *pReColorSubTitleEffectBitmap, FloatRectangle(0.0f, 0.0f, pReColorSubTitleEffectBitmap->GetWidthF(), pReColorSubTitleEffectBitmap->GetHeightF()));
527 delete pReColorSubTitleEffectBitmap;
531 delete pReplacementColorBackgroundBitmap;
537 _ToolbarPresenter::DrawDescriptionText(void)
539 result r = E_SUCCESS;
541 float textAreaHeight = 0.0f;
542 float fontSize = 0.0f;
543 float titleIconWidth = 0.0f;
545 GET_SHAPE_CONFIG(HEADER::DESCRIPTION_TEXT_HEIGHT, __pToolbar->GetOrientation(), textAreaHeight);
546 GET_SHAPE_CONFIG(HEADER::DESCRIPTION_TEXT_FONT_SIZE, __pToolbar->GetOrientation(), fontSize);
547 GET_SHAPE_CONFIG(HEADER::ICON_WIDTH, __pToolbar->GetOrientation(), titleIconWidth);
549 __fontSize = fontSize;
551 __pTextFont = __pToolbar->GetFallbackFont();
553 SysTryReturnVoidResult(NID_UI_CTRL, __pTextFont, r, "[%s] Propagating.", GetErrorMessage(r));
555 if (__pToolbar->GetTitleIcon() != null)
557 __descriptionRect.x = __toolbarUsableArea.x + titleIconWidth + __toolbarUsableArea.x;
561 __descriptionRect.x = __toolbarUsableArea.x;
564 __descriptionRect.y = __titleRect.y + __titleRect.height;
566 if(__titleText.IsEmpty())
568 __descriptionRect.width = __toolbarUsableArea.width;
572 __descriptionRect.width = __titleRect.width;
575 __descriptionRect.height = textAreaHeight;
577 Canvas* pCanvas = __pToolbar->GetCanvasN();
579 if (__pDescriptionTextObject)
581 __pDescriptionTextObject->SetFont(__pTextFont, 0, __pDescriptionTextObject->GetTextLength());
582 __pDescriptionTextObject->SetForegroundColor(__pToolbar->GetDescriptionTextColor(), 0, __pDescriptionTextObject->GetTextLength());
583 __pDescriptionTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
584 __pDescriptionTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
585 __pDescriptionTextObject->SetBounds(__descriptionRect);
586 __pDescriptionTextObject->Compose();
587 __pDescriptionTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
596 _ToolbarPresenter::DrawEditItem(const FloatPoint& point)
598 if (__pEditItem == null )
603 FloatPoint anchor = FloatPoint(0.0f, 0.0f);
605 anchor.x = point.x - (__pEditItem->GetSizeF().width / 2);
606 anchor.y = point.y - (__pEditItem->GetSizeF().height / 2);
608 __pEditItem->SetPosition(anchor);
610 __pToolbar->Invalidate(true);
616 _ToolbarPresenter::DrawDivider(const FloatPoint& point, Canvas* pCanvas)
618 ToolbarStyle style = __pToolbar->GetStyle();
620 if (style == TOOLBAR_SOFTKEY)
625 float dividerWidth = 0.0f;
626 float dividerHeight = 0.0f;
627 Color dividerLeftColor;
628 //Color dividerRightColor;
630 GET_SHAPE_CONFIG(HEADER::DIVIDER_WIDTH, __pToolbar->GetOrientation(), dividerWidth);
632 if (style == TOOLBAR_TAB_LARGE)
634 GET_SHAPE_CONFIG(HEADER::TAB_LARGE_DIVIDER_HEIGHT, __pToolbar->GetOrientation(), dividerHeight);
638 GET_SHAPE_CONFIG(HEADER::DIVIDER_HEIGHT, __pToolbar->GetOrientation(), dividerHeight);
641 if (__pToolbar->IsHeader() == true)
643 if (!__pToolbar->IsTransparent())
645 GET_COLOR_CONFIG(HEADER::DIVIDER_LINE_LEFT_NORMAL, dividerLeftColor);
646 //GET_COLOR_CONFIG(HEADER::DIVIDER_LINE_RIGHT_NORMAL, dividerRightColor);
650 GET_COLOR_CONFIG(HEADER::DIVIDER_LINE_LEFT_TRANSLUCENT_NORMAL, dividerLeftColor);
651 //GET_COLOR_CONFIG(HEADER::DIVIDER_LINE_RIGHT_TRANSLUCENT_NORMAL, dividerRightColor);
656 if (!__pToolbar->IsTransparent())
658 GET_COLOR_CONFIG(FOOTER::DIVIDER_LINE_LEFT_NORMAL, dividerLeftColor);
659 //GET_COLOR_CONFIG(FOOTER::DIVIDER_LINE_RIGHT_NORMAL, dividerRightColor);
663 GET_COLOR_CONFIG(FOOTER::DIVIDER_LINE_LEFT_TRANSLUCENT_NORMAL, dividerLeftColor);
664 //GET_COLOR_CONFIG(FOOTER::DIVIDER_LINE_RIGHT_TRANSLUCENT_NORMAL, dividerRightColor);
668 pCanvas->SetForegroundColor(dividerLeftColor);
669 pCanvas->SetLineWidth(dividerWidth);
671 pCanvas->DrawLine(FloatPoint(point.x, point.y), FloatPoint(point.x, point.y + dividerHeight));
673 //pCanvas->SetForegroundColor(dividerRightColor);
674 //pCanvas->SetLineWidth(dividerWidth/2);
676 //pCanvas->DrawLine(FloatPoint(point.x + dividerWidth, point.y), FloatPoint(point.x + dividerWidth, point.y + dividerHeight));
682 _ToolbarPresenter::DrawItems(void)
684 result r = E_SUCCESS;
686 Canvas* pCanvas = __pToolbar->GetCanvasN();
688 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, E_INVALID_STATE, "[E_INVALID_STATE] System error occurred.");
690 ToolbarStyle style = __pToolbar->GetStyle();
692 FloatRectangle usableArea = __toolbarUsableArea;
694 Bitmap* pTitleIcon = __pToolbar->GetTitleIcon();
696 _Label* pTitleBadgeIcon = __pToolbar->GetTitleBadgeIcon();
698 float iconWidth = 0.0f;
699 float titleDisplayHeight = 0.0f;
700 float leftMargin = 0.0f;
701 float headerTopMargin = 0.0f;
702 float processingAnimationIconSize = 0.0f;
703 float processingAnimationIconGap = 0.0f;
704 float titleCharacterCount = 0.0f;
705 float titleBadgeIconGap = 0.0f;
706 float titleBadgeIconTopMargin = 0.0f;
707 float fontSize = 0.0f;
708 FloatDimension titleTextDimension(0.0f, 0.0f);
709 float totalWidth = 0.0f;
710 float titleHeight = 0.0f;
712 GET_SHAPE_CONFIG(HEADER::LEFT_MARGIN, __pToolbar->GetOrientation(), leftMargin);
713 GET_SHAPE_CONFIG(HEADER::PROCESSING_ANIMATION_ICON_SIZE, __pToolbar->GetOrientation(), processingAnimationIconSize);
714 GET_SHAPE_CONFIG(HEADER::PROCESSING_ANIMATION_ICON_GAP, __pToolbar->GetOrientation(), processingAnimationIconGap);
716 GET_SHAPE_CONFIG(HEADER::TITLE_BADGE_ICON_GAP, __pToolbar->GetOrientation(), titleBadgeIconGap);
717 GET_SHAPE_CONFIG(HEADER::TITLE_BADGE_TOP_MARGIN, __pToolbar->GetOrientation(), titleBadgeIconTopMargin);
719 if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
721 GET_SHAPE_CONFIG(HEADER::TITLE_TOP_MARGIN_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), headerTopMargin);
722 GET_SHAPE_CONFIG(HEADER::TITLE_DISPLAY_HEIGHT_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), titleDisplayHeight);
726 GET_SHAPE_CONFIG(HEADER::TOP_MARGIN, __pToolbar->GetOrientation(), headerTopMargin);
727 GET_SHAPE_CONFIG(HEADER::TITLE_DISPLAY_HEIGHT, __pToolbar->GetOrientation(), titleDisplayHeight);
730 GET_SHAPE_CONFIG(HEADER::ICON_WIDTH, __pToolbar->GetOrientation(), iconWidth);
732 if (!__titleText.IsEmpty())
734 titleCharacterCount = __titleText.GetLength(); // alphabet count
736 if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
738 r = GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE_WITH_SEGMENTED, __pToolbar->GetOrientation(), fontSize);
740 else if (style == TOOLBAR_TITLE && __pToolbar->GetDescriptionText() != L""
741 && __pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) == ANIMATION_STOPPED)
743 r = GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE_WITH_DESCRIPTION, __pToolbar->GetOrientation(), fontSize);
747 r = GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE, __pToolbar->GetOrientation(), fontSize);
757 __fontSize = fontSize;
759 __pTitleTextFont = __pToolbar->GetFallbackFont();
761 SysTryReturnVoidResult(NID_UI_CTRL, __pTitleTextFont, r, "[%s] Propagating.", GetErrorMessage(r));
763 __pTitleTextObject->SetFont(__pTitleTextFont, 0, __pTitleTextObject->GetTextLength());
765 __pTitleTextFont->GetTextExtent(__titleText, titleCharacterCount, titleTextDimension);
767 totalWidth = titleTextDimension.width; // pixel
768 titleHeight = titleTextDimension.height; // pixel
770 __titleRect.height = _FontImpl::GetInstance(*__pTitleTextFont)->GetLeadingF();
774 pTitleIcon->Scale(FloatDimension(iconWidth, iconWidth));
779 totalWidth += (pTitleIcon->GetWidthF() + usableArea.x);
785 totalWidth += pTitleBadgeIcon->GetBoundsF().width + titleBadgeIconGap;
787 else if ((__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE)) != ANIMATION_STOPPED)
789 totalWidth += processingAnimationIconSize + processingAnimationIconGap;
792 if (totalWidth > usableArea.width)
794 __titleRect.width = titleTextDimension.width - (totalWidth - usableArea.width);
798 pCanvas->DrawBitmap(FloatPoint(usableArea.x, headerTopMargin + (titleDisplayHeight - pTitleIcon->GetHeightF()) / 2), *(pTitleIcon));
800 __titleRect.x = usableArea.x + pTitleIcon->GetWidthF() + usableArea.x;
801 __titleRect.y = headerTopMargin + (titleDisplayHeight - titleHeight) / 2;
803 if (__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
805 __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
806 usableArea.x + (pTitleIcon->GetWidthF() + processingAnimationIconGap) + __titleRect.width + processingAnimationIconGap,
807 headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
812 pTitleBadgeIcon->SetPosition(FloatPoint(usableArea.x + (pTitleIcon->GetWidthF() + processingAnimationIconGap) + __titleRect.width + titleBadgeIconGap,
813 titleBadgeIconTopMargin));
818 __titleRect.x = usableArea.x;
819 __titleRect.y = headerTopMargin + (titleDisplayHeight - titleHeight) / 2;
821 if (__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
823 __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
824 usableArea.x + __titleRect.width + processingAnimationIconGap,
825 headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
830 pTitleBadgeIcon->SetPosition(FloatPoint(usableArea.x + __titleRect.width + titleBadgeIconGap, titleBadgeIconTopMargin));
836 __titleRect.width = usableArea.width;
840 __titleRect.x = leftMargin + pTitleIcon->GetWidthF() + leftMargin;
841 __titleRect.y = headerTopMargin + (titleDisplayHeight - titleHeight) / 2;
843 if(__pTitleTextObject->GetAlignment() & TEXT_OBJECT_ALIGNMENT_CENTER)
845 leftMargin = (__titleRect.width - titleTextDimension.width) / 2 - leftMargin;
847 else if(__pTitleTextObject->GetAlignment() & TEXT_OBJECT_ALIGNMENT_RIGHT)
849 leftMargin = __titleRect.width - titleTextDimension.width - leftMargin * 3;
852 pCanvas->DrawBitmap(FloatPoint(leftMargin, headerTopMargin + (titleDisplayHeight - pTitleIcon->GetHeightF()) / 2), *(pTitleIcon));
854 if (__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
856 __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
857 usableArea.x + (pTitleIcon->GetWidthF() + processingAnimationIconGap) + titleTextDimension.width + processingAnimationIconGap,
858 headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
863 pTitleBadgeIcon->SetPosition(FloatPoint(usableArea.x + (pTitleIcon->GetWidthF() + processingAnimationIconGap) + titleTextDimension.width + titleBadgeIconGap,
864 titleBadgeIconTopMargin));
867 __titleRect.width -= (pTitleIcon->GetWidthF() + usableArea.x);
871 __titleRect.x = leftMargin;
872 __titleRect.y = headerTopMargin + (titleDisplayHeight - titleHeight) / 2;
874 if (__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
876 __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
877 leftMargin + titleTextDimension.width + processingAnimationIconGap,
878 headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
883 pTitleBadgeIcon->SetPosition(FloatPoint(leftMargin + titleTextDimension.width + titleBadgeIconGap, titleBadgeIconTopMargin));
890 if (pTitleIcon && __pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
892 pTitleIcon->Scale(FloatDimension(iconWidth, iconWidth));
894 if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_CENTER)
896 leftMargin = (leftMargin + usableArea.width - (pTitleIcon->GetWidthF() + processingAnimationIconGap + processingAnimationIconSize)) / 2;
898 else if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_RIGHT)
900 leftMargin = leftMargin + usableArea.width - (pTitleIcon->GetWidthF() + processingAnimationIconGap + processingAnimationIconSize);
903 pCanvas->DrawBitmap(FloatPoint(leftMargin, headerTopMargin + (titleDisplayHeight - pTitleIcon->GetHeightF()) / 2), *(pTitleIcon));
905 __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
906 leftMargin + processingAnimationIconGap + processingAnimationIconSize,
907 headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
911 pTitleBadgeIcon->SetPosition(FloatPoint(leftMargin + processingAnimationIconGap + titleBadgeIconGap, titleBadgeIconTopMargin));
916 pTitleIcon->Scale(FloatDimension(iconWidth, iconWidth));
918 if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_CENTER)
920 leftMargin = usableArea.width / 2;
922 else if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_RIGHT)
924 leftMargin = usableArea.width - pTitleIcon->GetWidthF();
927 pCanvas->DrawBitmap(FloatPoint(leftMargin, headerTopMargin + (titleDisplayHeight - pTitleIcon->GetHeightF()) / 2), *(pTitleIcon));
931 if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_CENTER)
933 leftMargin = (usableArea.width - (processingAnimationIconGap + processingAnimationIconSize))/ 2;
935 else if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_RIGHT)
937 leftMargin = usableArea.width - (processingAnimationIconGap + processingAnimationIconSize);
940 __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
941 leftMargin, headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
945 pTitleBadgeIcon->SetPosition(FloatPoint(leftMargin, titleBadgeIconTopMargin));
956 _ToolbarPresenter::DrawTitleText(Canvas* pCanvas)
958 TimerForTitleSlideInit();
960 if (__titleText.IsEmpty())
965 __pTitleTextObject->SetForegroundColor(__pToolbar->GetTitleTextColor(), 0, __pTitleTextObject->GetTextLength());
966 __pTitleTextObject->SetBounds(__titleRect);
967 //__pTitleTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
968 __pTitleTextObject->Compose();
970 if (__pTitleTextObject->IsActionOn() == true)
972 __pTitleTextObject->DrawWithOffset(*_CanvasImpl::GetInstance(*pCanvas));
974 DrawTitleTextDimBitmap();
976 TimerForTitleSlideStart();
980 __pTitleTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
987 _ToolbarPresenter::GetSelectedItemIndex(void) const
989 return __pToolbarModel->GetSelectedItemIndex();
993 _ToolbarPresenter::IsInitialDraw(void) const
995 return __initialDraw;
999 _ToolbarPresenter::IsTabEditModeEnabled(void) const
1001 return __tabEditEnabled;
1005 _ToolbarPresenter::SetDescriptionText(const String& description)
1007 result r = E_SUCCESS;
1009 float length = description.GetLength();
1010 float fontSize = 0.0f;
1012 wchar_t* tempString = const_cast<wchar_t*>(description.GetPointer());
1015 if (__pDescriptionTextObject != null)
1017 delete __pDescriptionTextObject;
1018 __pDescriptionTextObject = null;
1021 __pDescriptionTextObject = new (std::nothrow) TextObject();
1023 if (__pDescriptionTextObject == null)
1025 return E_OUT_OF_MEMORY;
1027 __pDescriptionTextObject->Construct();
1028 TextSimple* pSimpleText = new (std::nothrow) TextSimple(tempString, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1029 __pDescriptionTextObject->AppendElement(*pSimpleText);
1030 __pDescriptionTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1031 __pDescriptionTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER);
1033 GET_SHAPE_CONFIG(HEADER::DESCRIPTION_TEXT_FONT_SIZE, __pToolbar->GetOrientation(), fontSize);
1035 __fontSize = fontSize;
1037 __pTextFont = __pToolbar->GetFallbackFont();
1038 r = GetLastResult();
1039 SysTryReturn(NID_UI_CTRL, __pTextFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
1041 __pDescriptionTextObject->SetFont(__pTextFont, 0, __pDescriptionTextObject->GetTextLength());
1047 _ToolbarPresenter::SetItemSelected(int itemIndex, bool adjust)
1051 ToolbarStyle style = __pToolbar->GetStyle();
1053 if ((style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE) && __pToolbar->GetItemCount() > SEGMENTED_ITEM_MAX)
1055 if (itemIndex <= __pToolbar->GetItemCount() - SEGMENTED_ITEM_MAX)
1057 SetItemFit(itemIndex);
1061 SetItemFit(__pToolbar->GetItemCount() - SEGMENTED_ITEM_MAX);
1066 return __pToolbarModel->SetSelectedItemIndex(itemIndex);
1070 _ToolbarPresenter::SetInitialDrawState(bool state)
1072 //DrawBackground(); // remove since 2.1
1073 __initialDraw = state;
1075 __titlePressed = false;
1076 __titleSliding = false;
1077 __tabEditEnabled = false;
1079 __firstLoadedItemIndex = 0;
1080 __lastLoadedItemIndex = 0;
1086 _ToolbarPresenter::SetTabEditModeEnabled(bool enable)
1088 __tabEditEnabled = enable;
1094 _ToolbarPresenter::SetTitleText(const String& title, HorizontalAlignment alignment)
1096 result r = E_SUCCESS;
1098 float length = title.GetLength();
1100 __titleText = String(title);
1101 wchar_t* tempString = const_cast<wchar_t*>(__titleText.GetPointer());
1104 if (__pTitleTextObject != null)
1106 delete __pTitleTextObject;
1107 __pTitleTextObject = null;
1110 __pTitleTextObject = new (std::nothrow) TextObject();
1112 if (__pTitleTextObject == null)
1114 return E_OUT_OF_MEMORY;
1116 __pTitleTextObject->Construct();
1117 __pTitleTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
1118 TextSimple* pSimpleText = new (std::nothrow) TextSimple(tempString, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1119 __pTitleTextObject->AppendElement(*pSimpleText);
1121 __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1123 __titleSliding = false;
1127 case ALIGNMENT_LEFT:
1128 __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
1130 case ALIGNMENT_CENTER:
1131 __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER);
1133 case ALIGNMENT_RIGHT:
1134 __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_RIGHT);
1137 __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
1141 float fontSize = 0.0f;
1143 r = GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE, __pToolbar->GetOrientation(), fontSize);
1145 __fontSize = fontSize;
1147 __pTitleTextFont = __pToolbar->GetFallbackFont();
1148 r = GetLastResult();
1149 SysTryReturn(NID_UI_CTRL, __pTitleTextFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
1151 __pTitleTextObject->SetFont(__pTitleTextFont, 0, __pTitleTextObject->GetTextLength());
1153 //__pTitleTextObject->Compose();
1159 _ToolbarPresenter::SetUsableAreaBounds(const FloatRectangle& rect)
1161 __toolbarUsableArea = rect;
1167 _ToolbarPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1169 ResetFlickAnimationTimer();
1171 SetFirstLoadedItemIndex();
1172 SetLastLoadedItemIndex();
1174 __touchInitiatedInToolbar = true;
1176 __currentTouchPosition = touchinfo.GetCurrentPosition();
1178 ToolbarStyle style = __pToolbar->GetStyle();
1180 if (__titleRect.Contains(__currentTouchPosition)
1181 && (style == TOOLBAR_TITLE || style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE))
1183 __titlePressed = true;
1187 __titlePressed = false;
1190 __pressedItemIndex = __pToolbar->GetItemIndexFromPosition(__currentTouchPosition);
1192 if (__pressedItemIndex == -1)
1194 _Label* pLabel = dynamic_cast<_Label*>(const_cast<_Control*>(&source));
1198 if (__pToolbar->GetButton(LEFT_BUTTON) != null && __pToolbar->GetButton(LEFT_BUTTON)->GetButtonStatus() != _BUTTON_STATUS_DISABLED)
1200 _Label* pTempBadgeIcon = dynamic_cast<_Label*>(__pToolbar->GetButton(LEFT_BUTTON)->GetChild(0));
1202 if (pLabel == pTempBadgeIcon)
1204 __pToolbar->GetButton(LEFT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_PRESSED, false);
1208 if (__pToolbar->GetButton(RIGHT_BUTTON) != null && __pToolbar->GetButton(RIGHT_BUTTON)->GetButtonStatus() != _BUTTON_STATUS_DISABLED)
1210 _Label* pTempBadgeIcon = dynamic_cast<_Label*>(__pToolbar->GetButton(RIGHT_BUTTON)->GetChild(0));
1212 if (pLabel == pTempBadgeIcon)
1214 __pToolbar->GetButton(RIGHT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_PRESSED, false);
1221 _Button* pPressedButton = __pToolbar->GetItem(__pressedItemIndex);
1223 __initialPressesItemStatus = pPressedButton->GetButtonStatus();
1225 if (__initialPressesItemStatus == _BUTTON_STATUS_DISABLED)
1230 pPressedButton->SetButtonStatus(_BUTTON_STATUS_PRESSED);
1233 __pToolbar->Invalidate(true);
1239 _ToolbarPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1241 if (!__touchInitiatedInToolbar)
1246 FloatPoint touchPoint = touchinfo.GetCurrentPosition();
1248 if (__titlePressed && __titleRect.Contains(touchPoint))
1250 if (__titleSliding == true)
1252 __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1253 __pTitleTextObject->Compose();
1255 __titleSliding = false;
1259 __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT);
1260 __pTitleTextObject->Compose();
1262 __titleSliding = true;
1264 TimerForTitleSlideStart();
1268 SetFirstLoadedItemIndex();
1269 SetLastLoadedItemIndex();
1271 ToolbarStyle style = __pToolbar->GetStyle();
1273 __touchInitiatedInToolbar = false;
1275 int releasedItemIndex = __pToolbar->GetItemIndexFromPosition(touchPoint);
1276 float tabLeftMargin = 0.0f;
1278 GET_SHAPE_CONFIG(HEADER::TAB_LEFT_MARGIN, __pToolbar->GetOrientation(), tabLeftMargin);
1280 if ((style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE) && __beingEdited == true)
1282 __beingEdited = false;
1284 if (releasedItemIndex == -1)
1288 __pToolbar->DetachChild(*__pEditItem);
1294 if (__pressedItemIndex != -1)
1296 __pToolbar->GetItem(__pressedItemIndex)->SetButtonStatus(__initialPressesItemStatus);
1301 __pToolbar->MoveItem(__editItemIndex, releasedItemIndex);
1303 AdjustItemPositionX(-__pToolbar->GetItem(__firstLoadedItemIndex)->GetBoundsF().x + tabLeftMargin); // move auto focus
1307 __pToolbar->DetachChild(*__pEditItem);
1316 if ((style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE)
1317 && __pToolbar->GetItemCount() > SEGMENTED_ITEM_MAX)
1319 if (__pressedItemIndex != -1)
1321 if (releasedItemIndex == __pressedItemIndex)
1323 if (__initialPressesItemStatus != _BUTTON_STATUS_DISABLED && __tabMoved != true)
1325 __pToolbar->SetItemSelected(releasedItemIndex, true, false);
1329 __pToolbar->GetItem(__pressedItemIndex)->SetButtonStatus(__initialPressesItemStatus, false);
1334 __pToolbar->GetItem(__pressedItemIndex)->SetButtonStatus(__initialPressesItemStatus, false);
1340 if (__pressedItemIndex != -1 && (releasedItemIndex != __pressedItemIndex))
1342 __pToolbar->GetItem(__pressedItemIndex)->SetButtonStatus(__initialPressesItemStatus, false);
1346 if (__pressedItemIndex != -1 && __initialPressesItemStatus != _BUTTON_STATUS_DISABLED)
1348 if (style == TOOLBAR_HEADER_SEGMENTED || style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE
1349 || style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_SEGMENTED || style == TOOLBAR_TAB_LARGE)
1351 __pToolbar->SetItemSelected(releasedItemIndex, true, false);
1355 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pToolbar->GetItem(releasedItemIndex));
1356 __pToolbar->GetItem(releasedItemIndex)->SetButtonStatus(_BUTTON_STATUS_SELECTED, true);
1357 __pToolbar->GetItem(releasedItemIndex)->SetButtonStatus(_BUTTON_STATUS_NORMAL, false);
1362 _Label* pLabel = dynamic_cast<_Label*>(const_cast<_Control*>(&source));
1366 if (__pToolbar->GetButton(LEFT_BUTTON) != null && __pToolbar->GetButton(LEFT_BUTTON)->GetButtonStatus() != _BUTTON_STATUS_DISABLED)
1368 _Label* pTempBadgeIcon = dynamic_cast<_Label*>(__pToolbar->GetButton(LEFT_BUTTON)->GetChild(0));
1370 if (pLabel == pTempBadgeIcon)
1372 FloatRectangle buttonItemBounds = __pToolbar->GetButton(LEFT_BUTTON)->GetBoundsF();
1374 if (buttonItemBounds.Contains(touchPoint))
1376 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pToolbar->GetButton(LEFT_BUTTON));
1377 __pToolbar->GetButton(LEFT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_SELECTED, true);
1380 __pToolbar->GetButton(LEFT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_NORMAL, false);
1384 if (__pToolbar->GetButton(RIGHT_BUTTON) != null && __pToolbar->GetButton(RIGHT_BUTTON)->GetButtonStatus() != _BUTTON_STATUS_DISABLED)
1386 _Label* pTempBadgeIcon = dynamic_cast<_Label*>(__pToolbar->GetButton(RIGHT_BUTTON)->GetChild(0));
1388 if (pLabel == pTempBadgeIcon)
1390 FloatRectangle buttonItemBounds = __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF();
1392 if (buttonItemBounds.Contains(touchPoint))
1394 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pToolbar->GetButton(RIGHT_BUTTON));
1395 __pToolbar->GetButton(RIGHT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_SELECTED, true);
1398 __pToolbar->GetButton(RIGHT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_NORMAL, false);
1404 __pToolbar->Invalidate(true);
1413 // Restore status of other buttons to _BUTTON_STATUS_NORMAL // this can be removed
1414 int itemCount = __pToolbar->GetItemCount();
1416 for (int j = 0; j < itemCount; j++)
1418 if (__pToolbar->GetItem(j) != null && __pToolbar->GetItem(j)->GetButtonStatus() == _BUTTON_STATUS_PRESSED)
1420 __pToolbar->GetItem(j)->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1425 __pToolbar->Invalidate(true);
1431 _ToolbarPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1433 if (!__touchInitiatedInToolbar)
1438 SetFirstLoadedItemIndex();
1439 SetLastLoadedItemIndex();
1441 ToolbarStyle style = __pToolbar->GetStyle();
1442 FloatPoint touchPoint = touchinfo.GetCurrentPosition();
1444 if (__pressedItemIndex == -1)
1446 _Label* pLabel = dynamic_cast<_Label*>(const_cast<_Control*>(&source));
1450 if (__pToolbar->GetButton(LEFT_BUTTON) != null && __pToolbar->GetButton(LEFT_BUTTON)->GetButtonStatus() != _BUTTON_STATUS_DISABLED)
1452 _Label* pTempBadgeIcon = dynamic_cast<_Label*>(__pToolbar->GetButton(LEFT_BUTTON)->GetChild(0));
1454 if (pLabel == pTempBadgeIcon)
1456 FloatRectangle buttonItemBounds = __pToolbar->GetButton(LEFT_BUTTON)->GetBoundsF();
1458 if (buttonItemBounds.Contains(touchPoint))
1460 __pToolbar->GetButton(LEFT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_PRESSED);
1464 __pToolbar->GetButton(LEFT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1469 if (__pToolbar->GetButton(RIGHT_BUTTON) != null && __pToolbar->GetButton(RIGHT_BUTTON)->GetButtonStatus() != _BUTTON_STATUS_DISABLED)
1471 _Label* pTempBadgeIcon = dynamic_cast<_Label*>(__pToolbar->GetButton(RIGHT_BUTTON)->GetChild(0));
1473 if (pLabel == pTempBadgeIcon)
1475 FloatRectangle buttonItemBounds = __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF();
1477 if (buttonItemBounds.Contains(touchPoint))
1479 __pToolbar->GetButton(RIGHT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_PRESSED);
1483 __pToolbar->GetButton(RIGHT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1489 __pToolbar->Invalidate(true);
1494 _Button* pCurrentButton = __pToolbar->GetItem(__pressedItemIndex);
1496 if (pCurrentButton == null)
1501 FloatRectangle itemBounds = pCurrentButton->GetBoundsF();
1503 if ((style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE) && __pToolbar->GetItemCount() > SEGMENTED_ITEM_MAX)
1505 if (itemBounds.Contains(touchPoint))
1511 if ((style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE) && __beingEdited == true)
1513 DrawEditItem(touchinfo.GetCurrentPosition());
1519 pCurrentButton->SetButtonStatus(__initialPressesItemStatus, false);
1523 if (__initialPressesItemStatus == _BUTTON_STATUS_DISABLED)
1528 if (itemBounds.Contains(touchPoint))
1530 pCurrentButton->SetButtonStatus(_BUTTON_STATUS_PRESSED);
1534 pCurrentButton->SetButtonStatus(__initialPressesItemStatus, false);
1538 pCurrentButton->Invalidate(false);
1543 float distance = (touchinfo.GetCurrentPosition()).x - __currentTouchPosition.x;
1544 float sideMargin = 0.0f;
1546 GET_SHAPE_CONFIG(HEADER::TAB_LEFT_MARGIN, __pToolbar->GetOrientation(), sideMargin);
1548 FloatRectangle clientBounds = __pToolbar->GetBoundsF();
1550 __portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
1551 __landscapeSize = FloatDimension(__portraitSize.height, __portraitSize.width);
1553 if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
1555 if (clientBounds.width > __portraitSize.width)
1557 clientBounds.width = __portraitSize.width;
1562 if (clientBounds.width > __landscapeSize.width)
1564 clientBounds.width = __landscapeSize.width;
1568 __currentTouchPosition = touchinfo.GetCurrentPosition();
1570 _Button* pItem = null;
1571 FloatRectangle itemBounds;
1572 int itemCount = __pToolbar->GetItemCount();
1574 if (distance > 0) // right move
1576 pItem = __pToolbar->GetItem(0);
1582 itemBounds = pItem->GetBoundsF();
1584 if (itemBounds.x + distance >= sideMargin && !__beingEdited)
1586 distance = sideMargin - itemBounds.x;
1589 else if (distance < 0)
1591 pItem = __pToolbar->GetItem(itemCount - 1);
1598 itemBounds = pItem->GetBoundsF();
1600 if (itemBounds.x + itemBounds.width + distance <= clientBounds.width - sideMargin && !__beingEdited)
1602 distance = (clientBounds.width - sideMargin) - (itemBounds.x + itemBounds.width);
1607 float tabLeftMargin = 0.0f;
1609 GET_SHAPE_CONFIG(HEADER::TAB_LEFT_MARGIN, __pToolbar->GetOrientation(), tabLeftMargin);
1611 if (distance > 0) // right move
1613 __tabSlideRight = false;
1615 if (__pToolbar->GetItem(__lastLoadedItemIndex - 1)->GetBoundsF().x <= __pEditItem->GetBoundsF().x)
1617 __tabSlideLeft = true;
1620 if (__tabSlideLeft && __pToolbar->GetItem(itemCount-1)->GetBoundsF().x + __pToolbar->GetItem(itemCount-1)->GetBoundsF().width > clientBounds.width - tabLeftMargin)
1622 AdjustItemPositionX(-distance * 5); // move auto focus
1625 else if (distance < 0)
1627 __tabSlideLeft = false;
1629 if (__pToolbar->GetItem(__firstLoadedItemIndex + 1)->GetBoundsF().x >= __pEditItem->GetBoundsF().x)
1631 __tabSlideRight = true;
1634 if (__tabSlideRight && __pToolbar->GetItem(0)->GetBoundsF().x < tabLeftMargin)
1636 AdjustItemPositionX(-distance * 5); // move auto focus
1642 AdjustItemPositionX(distance);
1652 _ToolbarPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1654 __touchInitiatedInToolbar = false;
1655 __beingEdited = false;
1657 // Restore status of other buttons to _BUTTON_STATUS_NORMAL // this can be removed
1658 int itemCount = __pToolbar->GetItemCount();
1660 for (int i = 0; i < itemCount; i++)
1662 if (__pToolbar->GetItem(i) != null && __pToolbar->GetItem(i)->GetButtonStatus() == _BUTTON_STATUS_PRESSED)
1664 __pToolbar->GetItem(i)->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1670 __pToolbar->DetachChild(*__pEditItem);
1677 __pToolbar->Invalidate(true);
1683 _ToolbarPresenter::OnChangeLayout(Tizen::Ui::_ControlOrientation orientation)
1685 ResetFlickAnimationTimer();
1691 _ToolbarPresenter::OnLongPressGestureDetected(void)
1693 if (__pToolbar->IsTabEditModeEnabled() == true)
1695 int longPressedItemIndex = __pToolbar->GetItemIndexFromPosition(__currentTouchPosition);
1697 if (longPressedItemIndex == -1)
1702 _Button* pButton = null;
1703 pButton = __pToolbar->GetItem(longPressedItemIndex);
1704 SysTryReturn(NID_UI_CTRL, pButton, true, E_INVALID_STATE, "[E_INVALID_STATE] Unable to retrieve a button");
1706 if (pButton->GetButtonStatus() == _BUTTON_STATUS_DISABLED)
1711 __editItemIndex = longPressedItemIndex;
1712 __beingEdited = true;
1714 pButton->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1716 FloatRectangle itemBounds = pButton->GetBoundsF();
1720 __pToolbar->DetachChild(*__pEditItem);
1726 __pEditItem = _Label::CreateLabelN();
1727 SysTryCatch(NID_UI_CTRL, __pEditItem, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1729 Canvas* pCanvas = pButton->GetCanvasN();
1730 SysTryCatch(NID_UI_CTRL, pCanvas, , E_INVALID_STATE, "[E_INVALID_STATE] Unable to retrieve a Canvas.");
1732 Bitmap* pEditItemBitmap = new (std::nothrow) Bitmap();
1733 result r = pEditItemBitmap->Construct(*pCanvas, FloatRectangle(0.0f, 0.0f, itemBounds.width, itemBounds.height));
1737 delete pEditItemBitmap;
1738 pEditItemBitmap = null;
1745 __pEditItem->SetBounds(itemBounds);
1746 __pEditItem->SetBackgroundBitmap(*pEditItemBitmap);
1749 delete pEditItemBitmap;
1751 __pToolbar->AttachChild(*__pEditItem);
1752 __pToolbar->SetChildAlwaysOnTop(*__pEditItem);
1770 _ToolbarPresenter::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
1772 ToolbarStyle style = __pToolbar->GetStyle();
1774 if (!(style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE) || __pToolbar->GetItemCount() <= SEGMENTED_ITEM_MAX || __beingEdited == true || __tabMoved == false)
1779 if (gesture.GetDirection() != _FLICK_DIRECTION_RIGHT && gesture.GetDirection() != _FLICK_DIRECTION_LEFT)
1784 float distanceX = 0.0f;
1785 float distanceY = 0.0f;
1786 float xPosition = 0.0f;
1787 float itemsBeyondScreen = 0.0f;
1789 gesture.GetDistance(distanceX, distanceY);
1790 SetFirstLoadedItemIndex();
1791 SetLastLoadedItemIndex();
1792 int itemCount = __pToolbar->GetItemCount();
1793 float itemWidth = __pToolbar->GetItem(0)->GetBoundsF().width;
1795 if (distanceX < 0) //left
1797 itemsBeyondScreen = (itemCount - 1) - __lastLoadedItemIndex;
1798 xPosition = __pToolbar->GetItem(__lastLoadedItemIndex)->GetBoundsF().x;
1799 if (xPosition < (3 * itemWidth))
1801 __flickDistance = xPosition - (4 * itemWidth);
1806 itemsBeyondScreen = __firstLoadedItemIndex;
1807 xPosition = __pToolbar->GetItem(__firstLoadedItemIndex)->GetBoundsF().x;
1810 __flickDistance = -xPosition;
1815 int itemMaxCount = 4;
1817 if (itemsBeyondScreen >= (itemMaxCount - 1))
1819 __flickDistance = (3 * itemWidth);
1823 __flickDistance = (itemsBeyondScreen * itemWidth);
1826 if (distanceX < 0) //Left flick
1828 __flickMove = 0.006f;
1831 else if (distanceX > 0) //Right flick
1833 __flickMove = 0.006f;
1834 __flickDistance = -(__flickDistance);
1840 __flickDistance = 0.0f;
1842 __moveDistance = 0.0f;
1845 StartFlickAnimationTimer();
1851 _ToolbarPresenter::OnTimerExpired(Timer& timer)
1853 Timer* onTimer = &timer;
1855 if (onTimer == __pTitleSlideTimer)
1857 TimerForTitleSlideTimeout();
1860 if (onTimer == __pFlickAnimationTimer)
1862 StartFlickAnimation();
1869 _ToolbarPresenter::OnDrawFocus(void)
1875 _ToolbarPresenter::OnChildControlFocusMoved(const _Control& control)
1881 _ToolbarPresenter::IsChildControlFocusManage(void) const
1887 _ToolbarPresenter::OnFocusableStateChanged(bool focusalbeState)
1893 _ToolbarPresenter::OnFocusModeStateChanged(void)
1899 _ToolbarPresenter::OnFocusGained(const _Control& source)
1901 //__focusPrevStatus = __pButton->GetButtonStatus();
1902 //__pButton->SetButtonStatus(_BUTTON_STATUS_HIGHLIGHTED);
1903 //__pButton->Invalidate();
1909 _ToolbarPresenter::OnFocusLost(const _Control& source)
1911 //__pButton->SetButtonStatus(__focusPrevStatus);
1912 //__pButton->Invalidate();
1918 _ToolbarPresenter::TimerForTitleSlideInit(void)
1920 result r = E_SUCCESS;
1922 if (__pTitleSlideTimer != null)
1924 delete __pTitleSlideTimer;
1925 __pTitleSlideTimer = null;
1932 _ToolbarPresenter::TimerForTitleSlideStart(void)
1934 result r = E_SUCCESS;
1936 if (__pTitleSlideTimer == null)
1938 __pTitleSlideTimer = new (std::nothrow) Timer();
1939 if (__pTitleSlideTimer == null)
1941 r = E_OUT_OF_MEMORY;
1945 r = __pTitleSlideTimer->Construct(*this);
1949 delete __pTitleSlideTimer;
1954 r = __pTitleSlideTimer->Start(100);
1966 _ToolbarPresenter::TimerForTitleSlideTimeout(void)
1968 Canvas* pCanvas = __pToolbar->GetCanvasN();
1969 SysTryReturnResult(NID_UI_CTRL, pCanvas, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pCanvas is invalid!");
1971 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1972 pCanvas->Clear(__titleRect);
1974 if (__pTitleBackgroundBitmap)
1976 pCanvas->DrawBitmap(CoordinateSystem::AlignToDevice(__titleRect), *__pTitleBackgroundBitmap);
1979 if (__pTitleTextObject->IsChanged())
1981 DrawTitleText(pCanvas);
1984 if (__pTitleTextObject->IsActionOn() == true)
1986 __pTitleTextObject->DrawWithOffset(*_CanvasImpl::GetInstance(*pCanvas));
1988 DrawTitleTextDimBitmap();
1990 if (__pTitleTextObject->GetRepeatCount() < 3)
1992 TimerForTitleSlideStart();
1997 __pTitleTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
2006 _ToolbarPresenter::DrawTitleTextDimBitmap(void)
2008 if (__pToolbar->IsUserBackgroundBitmap())
2013 float textDimWidth = 0.0f;
2014 float textDimHeight = 0.0f;
2016 GET_SHAPE_CONFIG(HEADER::TAB_TEXT_DIM_WIDTH, __pToolbar->GetOrientation(), textDimWidth);
2018 ToolbarStyle style = __pToolbar->GetStyle();
2020 if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
2022 GET_SHAPE_CONFIG(HEADER::TITLE_HEIGHT_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), textDimHeight);
2026 if (__pToolbar->GetDescriptionText() != L"")
2028 textDimHeight = __titleRect.height;
2032 textDimHeight = __pToolbar->GetBoundsF().height;
2036 Color titleTextDimColor;
2037 GET_COLOR_CONFIG(HEADER::TITLE_TEXT_DIM_NORMAL, titleTextDimColor);
2039 Bitmap* pTitleTextDimLeftBitmap = null;
2040 GET_BITMAP_CONFIG_N(HEADER::TITLE_TEXT_DIM_EFFECT_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888, pTitleTextDimLeftBitmap);
2042 Bitmap* pReColorTitleTextDimLeftBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTitleTextDimLeftBitmap,
2043 Color::GetColor(COLOR_ID_MAGENTA), titleTextDimColor);
2045 if (pReColorTitleTextDimLeftBitmap)
2047 Canvas* pCanvas = __pToolbar->GetCanvasN();
2048 FloatRectangle bounds = FloatRectangle(0.0f, 0.0f, textDimWidth, textDimHeight);
2050 if (pCanvas == null)
2052 SysLog(NID_UI_CTRL, "Cannot get a canvas.");
2056 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReColorTitleTextDimLeftBitmap))
2058 pCanvas->DrawNinePatchedBitmap(bounds, *pReColorTitleTextDimLeftBitmap);
2062 pCanvas->DrawBitmap(bounds, *pReColorTitleTextDimLeftBitmap,
2063 FloatRectangle(0.0f, 0.0f, pReColorTitleTextDimLeftBitmap->GetWidthF(), pReColorTitleTextDimLeftBitmap->GetHeightF()));
2066 delete pTitleTextDimLeftBitmap;
2067 delete pReColorTitleTextDimLeftBitmap;
2071 Bitmap* pTitleTextDimRightBitmap = null;
2072 GET_BITMAP_CONFIG_N(HEADER::TITLE_TEXT_DIM_EFFECT_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888, pTitleTextDimRightBitmap);
2074 Bitmap* pReColorTitleTextDimRightBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTitleTextDimRightBitmap,
2075 Color::GetColor(COLOR_ID_MAGENTA), titleTextDimColor);
2077 if (pReColorTitleTextDimRightBitmap)
2079 Canvas* pCanvas = __pToolbar->GetCanvasN();
2080 FloatRectangle bounds = FloatRectangle(__titleRect.width, 0.0f, textDimWidth, textDimHeight);
2082 if (pCanvas == null)
2084 SysLog(NID_UI_CTRL, "Cannot get a canvas.");
2088 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReColorTitleTextDimRightBitmap))
2090 pCanvas->DrawNinePatchedBitmap(bounds, *pReColorTitleTextDimRightBitmap);
2094 pCanvas->DrawBitmap(bounds, *pReColorTitleTextDimRightBitmap,
2095 FloatRectangle(0.0f, 0.0f, pReColorTitleTextDimRightBitmap->GetWidthF(), pReColorTitleTextDimRightBitmap->GetHeightF()));
2098 delete pTitleTextDimRightBitmap;
2099 delete pReColorTitleTextDimRightBitmap;
2107 _ToolbarPresenter::AdjustItemPositionX(float distance)
2110 int itemCount = __pToolbar->GetItemCount();
2111 _Button* pItem = __pToolbar->GetItem(index);
2113 while (pItem != null)
2115 FloatRectangle bounds = pItem->GetBoundsF();
2116 bounds.x += distance;
2117 pItem->SetBounds(bounds);
2120 if (index < itemCount)
2122 pItem = __pToolbar->GetItem(index);
2134 _ToolbarPresenter::GetTitleTextBoundsF(void) const
2140 _ToolbarPresenter::GetDescriptionBoundsF(void) const
2142 return __descriptionRect;
2146 _ToolbarPresenter::_SetModel(const _ToolbarModel& toolbarModel)
2148 __pToolbarModel = const_cast<_ToolbarModel*>(&toolbarModel);
2154 _ToolbarPresenter::OnFontChanged(Font* pFont)
2156 __pTextFont = pFont;
2157 __pTitleTextFont = pFont;
2163 _ToolbarPresenter::OnFontInfoRequested(unsigned long& style, int& size)
2165 style = __fontStyle;
2166 size = _CoordinateSystemUtils::ConvertToInteger(__fontSize);
2172 _ToolbarPresenter::OnFontInfoRequested(unsigned long& style, float& size)
2174 style = __fontStyle;
2181 _ToolbarPresenter::OnAncestorVisibleStateChanged(const _Control& control)
2183 if (__pTitleTextObject != null)
2185 __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
2186 __pTitleTextObject->Compose();
2189 __titleSliding = false;
2195 _ToolbarPresenter::SetFontInfo(unsigned long style, float size)
2197 __fontStyle = style;
2204 _ToolbarPresenter::StartFlickAnimation(void)
2206 float distance = CalculateProgress(__flickMove);
2208 __moveDistance = -(__flickDistance * distance);
2209 __flickDistance = (__flickDistance + __moveDistance);
2210 __flickMove = __flickMove + 0.006;
2213 if (__flickFlag <= FLICK_ANIMATION_COUNT)
2215 StartFlickAnimationTimer();
2219 ResetFlickAnimationTimer();
2220 SetItemFit(__firstLoadedItemIndex);
2223 AdjustItemPositionX(__moveDistance);
2225 SetFirstLoadedItemIndex();
2226 SetLastLoadedItemIndex();
2234 _ToolbarPresenter::StartFlickAnimationTimer(void)
2236 result r = E_SUCCESS;
2238 if (__pFlickAnimationTimer == null)
2240 __pFlickAnimationTimer = new (std::nothrow) Timer();
2241 SysTryReturn(NID_UI_CTRL, (__pFlickAnimationTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2243 r = __pFlickAnimationTimer->Construct(*this);
2244 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2248 __pFlickAnimationTimer->Cancel();
2251 r = __pFlickAnimationTimer->Start(FLICK_ANIMATION_TIMER_PERIOD);
2252 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2257 ResetFlickAnimationTimer();
2262 _ToolbarPresenter::ResetFlickAnimationTimer(void)
2264 if (__pFlickAnimationTimer)
2266 delete __pFlickAnimationTimer;
2267 __pFlickAnimationTimer = null;
2270 __moveDistance = 0.0f;
2276 _ToolbarPresenter::SetFirstLoadedItemIndex(void)
2278 int itemCount = __pToolbar->GetItemCount();
2280 for (int i = 0; i < itemCount; i++)
2282 if (__pToolbar->GetItem(i)->GetBoundsF().x + (__pToolbar->GetItem(i)->GetBoundsF().width / 2) <= __pToolbar->GetItem(i)->GetBoundsF().width)
2284 __firstLoadedItemIndex = i;
2292 _ToolbarPresenter::GetFirstLoadedItemIndex(void)
2294 return __firstLoadedItemIndex;
2298 _ToolbarPresenter::SetLastLoadedItemIndex(void)
2301 int itemCount = __pToolbar->GetItemCount();
2303 if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
2305 width = __portraitSize.width;
2309 width = __landscapeSize.width;
2312 for (int i = 0; i < itemCount; i++)
2314 float X = __pToolbar->GetItem(i)->GetBoundsF().x;
2316 if ((X + (__pToolbar->GetItem(i)->GetBoundsF().width / 2)) < width)
2318 __lastLoadedItemIndex = i;
2326 _ToolbarPresenter::CalculateProgress(float timeProgress) const
2328 const float segments[3][3] = {{0.0f, 0.01f, 0.45f}, {0.45f, 0.80f, 0.908f}, {0.908f, 0.9999f, 1.0f}};
2329 float loc_5 = timeProgress / 1;
2330 int loc_6 = 3; //Length of the segments array
2331 int loc_9 = (int)floor(loc_6 * loc_5);
2338 float loc_7 = (loc_5 - loc_9 * (1.0 / loc_6)) * loc_6;
2341 for (int i = 0; i < 3; i++)
2343 loc_8[i] = segments[loc_9][i];
2346 float ret = 0 + 1 * (loc_8[0] + loc_7 * (2 * (1 - loc_7) * (loc_8[1] - loc_8[0]) + loc_7 * (loc_8[2] - loc_8[0])));
2352 _ToolbarPresenter::SetItemFit(int index)
2359 FloatPoint pt(0.0f, 0.0f);
2360 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
2362 float fitDistance = 0.0f;
2363 float tabLeftMargin = 0.0f;
2364 int itemCount = __pToolbar->GetItemCount();
2366 GET_SHAPE_CONFIG(HEADER::TAB_LEFT_MARGIN, __pToolbar->GetOrientation(), tabLeftMargin);
2368 _Button* pItem = __pToolbar->GetItem(index);
2369 SysTryReturnVoidResult(NID_UI_CTRL, pItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2371 bounds = pItem->GetBoundsF();
2373 fitDistance = -bounds.x + tabLeftMargin;
2375 for (int i = 0; i < itemCount; i++)
2377 pItem = __pToolbar->GetItem(i);
2378 SysTryReturnVoidResult(NID_UI_CTRL, pItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2380 bounds = pItem->GetBoundsF();
2381 bounds.x = bounds.x + fitDistance;
2382 pItem->SetBounds(bounds);
2385 SetFirstLoadedItemIndex();
2386 SetLastLoadedItemIndex();
2394 _ToolbarPresenter::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
2400 _ToolbarPresenter::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
2406 _ToolbarPresenter::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
2411 }}} // Tizen::Ui::Controls