2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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 <FGrp_BitmapImpl.h>
24 #include <FGrp_CanvasImpl.h>
25 #include <FGrp_FontImpl.h>
26 #include <FGrp_TextCommon.h>
27 #include <FGrp_TextTextSimple.h>
28 #include "FUi_UiTouchEvent.h"
29 #include "FUi_ResourceManager.h"
30 #include "FUiCtrl_Label.h"
31 #include "FUiCtrl_ToolbarPresenter.h"
32 #include "FUiCtrl_ToolbarModel.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Runtime;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Graphics::_Text;
39 namespace Tizen { namespace Ui { namespace Controls
42 _ToolbarPresenter::_ToolbarPresenter(void)
44 , __pToolbarModel(null)
46 , __tabEditEnabled(false)
47 , __beingEdited(false)
48 , __touchInitiatedInToolbar(false)
50 , __initialPressedItemIndex(-1)
51 , __initialPressesItemStatus(_BUTTON_STATUS_NORMAL)
53 , __pTitleBackgroundBitmap(null)
54 , __pTitleSlideTimer(null)
55 , __titleRect(Rectangle(0, 0, 0, 0))
56 , __descriptionRect(Rectangle(0, 0, 0, 0))
58 , __pTitleTextFont(null)
60 , __pDescriptionTextObject(null)
61 , __pTitleTextObject(null)
62 , __titleSlidingAction(TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT)
65 , __touchMoveHandled(false)
67 __currentTouchPosition = Point(0, 0);
70 _ToolbarPresenter::~_ToolbarPresenter(void)
74 delete __pToolbarModel;
75 __pToolbarModel = null;
80 __pToolbar->DetachChild(*__pEditItem);
85 if (__pTitleBackgroundBitmap)
87 delete __pTitleBackgroundBitmap;
88 __pTitleBackgroundBitmap = null;
91 if (__pTitleSlideTimer)
93 delete __pTitleSlideTimer;
94 __pTitleSlideTimer = null;
97 if (__pDescriptionTextObject)
99 delete __pDescriptionTextObject;
100 __pDescriptionTextObject = null;
103 if (__pTitleTextObject)
105 delete __pTitleTextObject;
106 __pTitleTextObject = null;
111 _ToolbarPresenter::Construct(const _Toolbar& toolbar)
113 __pToolbar = const_cast<_Toolbar*>(&toolbar);
115 __fontStyle = FONT_STYLE_BOLD;
121 _ToolbarPresenter::Install(void)
123 _ToolbarModel* pModel = new (std::nothrow) _ToolbarModel();
127 result r = pModel->Construct();
133 _ToolbarPresenter::Draw(void)
135 result r = E_SUCCESS;
137 ToolbarStyle toolbarStyle = __pToolbar->GetStyle();
143 Canvas* pCanvas = __pToolbar->GetCanvasN();
147 SysLog(NID_UI_CTRL, "Cannot get a canvas.");
152 int buttonItemGap = 0;
153 int headerButtonItemHeight = 0;
154 int separatorHeight = 0;
157 int footerButtonItemWidth = 0;
158 int footerButtonItemHeight = 0;
161 Rectangle bounds(0, 0, __pToolbar->GetBounds().width, __pToolbar->GetBounds().height);
163 const Dimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSize();
164 const Dimension landscapeSize = Dimension(portraitSize.height, portraitSize.width);
166 if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
168 if (bounds.width > portraitSize.width)
170 bounds.width = portraitSize.width;
175 if (bounds.width > landscapeSize.width)
177 bounds.width = landscapeSize.width;
181 int segmentedTitleTextAreaHeight = 0;
183 if (toolbarStyle == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || toolbarStyle == TOOLBAR_TAB_WITH_TITLE)
185 GET_SHAPE_CONFIG(HEADER::SEGMENTED_ITEM_HEIGHT, __pToolbar->GetOrientation(), headerButtonItemHeight);
186 GET_SHAPE_CONFIG(HEADER::TITLE_HEIGHT_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), segmentedTitleTextAreaHeight);
190 GET_SHAPE_CONFIG(HEADER::BUTTON_ITEM_HEIGHT, __pToolbar->GetOrientation(), headerButtonItemHeight);
191 GET_SHAPE_CONFIG(HEADER::BUTTON_ITEM_TOP_MARGIN, __pToolbar->GetOrientation(), segmentedTitleTextAreaHeight);
194 GET_SHAPE_CONFIG(HEADER::SEPARATOR_WIDTH, __pToolbar->GetOrientation(), buttonItemGap);
195 GET_SHAPE_CONFIG(HEADER::SEPARATOR_HEIGHT, __pToolbar->GetOrientation(), separatorHeight);
196 GET_SHAPE_CONFIG(HEADER::RIGHT_MARGIN, __pToolbar->GetOrientation(), rightMargin);
198 GET_SHAPE_CONFIG(FOOTER::BUTTON_ITEM_WIDTH, __pToolbar->GetOrientation(), footerButtonItemWidth);
199 GET_SHAPE_CONFIG(FOOTER::BUTTON_ITEM_HEIGHT, __pToolbar->GetOrientation(), footerButtonItemHeight);
201 if ((toolbarStyle == TOOLBAR_TITLE || toolbarStyle == TOOLBAR_HEADER_SEGMENTED || toolbarStyle == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE
202 || toolbarStyle == TOOLBAR_TAB || toolbarStyle == TOOLBAR_TAB_WITH_TITLE || toolbarStyle == TOOLBAR_TEXT))
204 if (__pTitleBackgroundBitmap)
206 delete __pTitleBackgroundBitmap;
207 __pTitleBackgroundBitmap = null;
210 if (toolbarStyle == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || toolbarStyle == TOOLBAR_TAB_WITH_TITLE)
212 GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE_WITH_SEGMENTED, __pToolbar->GetOrientation(), fontSize);
214 if (!__titleText.IsEmpty())
216 __fontSize = fontSize;
218 __pTitleTextFont = __pToolbar->GetFallbackFont();
220 SysTryReturn(NID_UI_CTRL, __pTitleTextFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
222 __pTitleTextObject->SetFont(__pTitleTextFont, 0, __pTitleTextObject->GetTextLength());
225 else if (toolbarStyle == TOOLBAR_TITLE && __pToolbar->GetDescriptionText() != L""
226 && __pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) == ANIMATION_STOPPED)
228 GET_SHAPE_CONFIG(HEADER::TITLE_TOP_MARGIN_WITH_DESCRIPTION, __pToolbar->GetOrientation(), __titleRect.y);
229 GET_SHAPE_CONFIG(HEADER::TITLE_DISPLAY_HEIGHT_WITH_DESCRIPTION, __pToolbar->GetOrientation(), __titleRect.height);
230 GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE_WITH_DESCRIPTION, __pToolbar->GetOrientation(), fontSize);
232 DrawDescriptionText();
234 if(!__titleText.IsEmpty())
236 __fontSize = fontSize;
238 __pTitleTextFont = __pToolbar->GetFallbackFont();
240 SysTryReturn(NID_UI_CTRL, __pTitleTextFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
242 __pTitleTextObject->SetFont(__pTitleTextFont, 0, __pTitleTextObject->GetTextLength());
246 __pTitleBackgroundBitmap = new (std::nothrow) Bitmap();
247 __pTitleBackgroundBitmap->Construct(*pCanvas, __titleRect);
249 DrawTitleText(pCanvas);
252 if (toolbarStyle == TOOLBAR_TITLE || toolbarStyle == TOOLBAR_HEADER_SEGMENTED || toolbarStyle == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE)
254 if (__pToolbar->GetButton(RIGHT_BUTTON))
256 if (__pToolbar->GetButton(LEFT_BUTTON))
258 if (__pToolbar->GetButton(LEFT_BUTTON)->GetText() != L"" && __pToolbar->GetButton(RIGHT_BUTTON)->GetText() != L"")
260 DrawSeparator(TOOLBAR_SEPARATOR_HEADER_BUTTON, Point(bounds.width - __pToolbar->GetButton(RIGHT_BUTTON)->GetBounds().width - buttonItemGap - rightMargin,
261 segmentedTitleTextAreaHeight + (headerButtonItemHeight - separatorHeight) / 2), pCanvas);
268 int itemCount = __pToolbar->GetItemCount();
272 //DrawSeparator(TOOLBAR_SEPARATOR_FOOTER_BUTTON, Point(__pToolbar->GetItem(0)->GetBounds().x + __pToolbar->GetItem(0)->GetBounds().width,
273 // (__pToolbar->GetBounds().height - separatorHeight) / 2), pCanvas);
277 if (toolbarStyle == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || toolbarStyle == TOOLBAR_TAB_WITH_TITLE)
279 for (int i = 0; i < itemCount - 1 ; i++)
281 DrawSeparator(TOOLBAR_SEPARATOR_FOOTER_BUTTON, Point(__pToolbar->GetItem(i)->GetBounds().x + __pToolbar->GetItem(i)->GetBounds().width,
282 segmentedTitleTextAreaHeight + (headerButtonItemHeight - separatorHeight) / 2), pCanvas);
287 for (int i = 0; i < itemCount - 1 ; i++)
289 if (!(toolbarStyle == TOOLBAR_TEXT || toolbarStyle == TOOLBAR_ICON || toolbarStyle == TOOLBAR_ICON_TEXT))
291 DrawSeparator(TOOLBAR_SEPARATOR_FOOTER_BUTTON, Point(__pToolbar->GetItem(i)->GetBounds().x + __pToolbar->GetItem(i)->GetBounds().width,
292 (__pToolbar->GetBounds().height - separatorHeight) / 2), pCanvas);
301 if ((toolbarStyle == TOOLBAR_TAB || toolbarStyle == TOOLBAR_TAB_WITH_TITLE
302 || toolbarStyle == TOOLBAR_SEGMENTED || toolbarStyle == TOOLBAR_HEADER_SEGMENTED || toolbarStyle == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE)
303 && __pToolbar->GetItemCount() > 0 && __pToolbarModel->GetSelectedItemIndex() == -1)
305 int firstEnabledItemIndex = __pToolbar->GetFirstEnabledItemIndex();
307 if(firstEnabledItemIndex != -1)
309 __pToolbar->SetItemSelected(firstEnabledItemIndex, true);
313 __initialDraw = false;
322 _ToolbarPresenter::DrawBackground(void)
324 Canvas* pCanvas = __pToolbar->GetCanvasN();
328 SysLog(NID_UI_CTRL, "Cannot get a canvas.");
333 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
336 ToolbarStyle style = __pToolbar->GetStyle();
338 if (style == TOOLBAR_SOFTKEY)
345 Bitmap* pReplacementColorBackgroundBitmap = null;
346 Bitmap* pBackgroundBitmap = null;
348 Rectangle bounds(0, 0, __pToolbar->GetBounds().width, __pToolbar->GetBounds().height);
350 const Dimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSize();
351 const Dimension landscapeSize = Dimension(portraitSize.height, portraitSize.width);
353 if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
355 if (bounds.width > portraitSize.width)
357 bounds.width = portraitSize.width;
362 if (bounds.width > landscapeSize.width)
364 bounds.width = landscapeSize.width;
368 pBackgroundBitmap = __pToolbar->GetBackgroundBitmap();
370 pReplacementColorBackgroundBitmap =
371 _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pToolbar->GetColor());
373 if (__pToolbar->IsUserBackgroundBitmap())
375 if (pBackgroundBitmap)
377 if (pBackgroundBitmap->IsNinePatchedBitmap())
379 pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
383 pCanvas->DrawBitmap(bounds, *pBackgroundBitmap, Rectangle(0, 0, pBackgroundBitmap->GetWidth(), pBackgroundBitmap->GetHeight()));
388 pCanvas->FillRectangle(__pToolbar->GetColor(), bounds);
393 if (pReplacementColorBackgroundBitmap)
395 if (pReplacementColorBackgroundBitmap->IsNinePatchedBitmap())
397 pCanvas->DrawNinePatchedBitmap(bounds, *pReplacementColorBackgroundBitmap);
401 pCanvas->DrawBitmap(bounds, *pReplacementColorBackgroundBitmap, Rectangle(0, 0, pReplacementColorBackgroundBitmap->GetWidth(),
402 pReplacementColorBackgroundBitmap->GetHeight()));
407 pCanvas->FillRectangle(__pToolbar->GetColor(), bounds);
412 delete pReplacementColorBackgroundBitmap;
418 _ToolbarPresenter::DrawDescriptionText(void)
420 result r = E_SUCCESS;
422 int textAreaHeight = 0;
424 int titleIconWidth = 0;
426 GET_SHAPE_CONFIG(HEADER::DESCRIPTION_TEXT_HEIGHT, __pToolbar->GetOrientation(), textAreaHeight);
427 GET_SHAPE_CONFIG(HEADER::DESCRIPTION_TEXT_FONT_SIZE, __pToolbar->GetOrientation(), fontSize);
428 GET_SHAPE_CONFIG(HEADER::ICON_WIDTH, __pToolbar->GetOrientation(), titleIconWidth);
430 __fontSize = fontSize;
432 __pTextFont = __pToolbar->GetFallbackFont();
434 SysTryReturnVoidResult(NID_UI_CTRL, __pTextFont, r, "[%s] Propagating.", GetErrorMessage(r));
436 if (__pToolbar->GetTitleIcon() != null)
438 __descriptionRect.x = __toolbarUsableArea.x + titleIconWidth + __toolbarUsableArea.x;
442 __descriptionRect.x = __toolbarUsableArea.x;
445 __descriptionRect.y = __titleRect.y + __titleRect.height;
447 if(__titleText.IsEmpty())
449 __descriptionRect.width = __toolbarUsableArea.width;
453 __descriptionRect.width = __titleRect.width;
456 __descriptionRect.height = textAreaHeight;
458 Canvas* pCanvas = __pToolbar->GetCanvasN();
460 if (__pDescriptionTextObject)
462 __pDescriptionTextObject->SetFont(__pTextFont, 0, __pDescriptionTextObject->GetTextLength());
463 __pDescriptionTextObject->SetForegroundColor(__pToolbar->GetDescriptionTextColor(), 0, __pDescriptionTextObject->GetTextLength());
464 __pDescriptionTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
465 __pDescriptionTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
466 __pDescriptionTextObject->SetBounds(__descriptionRect);
467 __pDescriptionTextObject->Compose();
468 __pDescriptionTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
477 _ToolbarPresenter::DrawEditItem(const Point& point)
479 if (__pEditItem == null )
484 Point anchor = Point(0,0);
486 anchor.x = point.x - (__pEditItem->GetSize().width / 2);
487 anchor.y = point.y - (__pEditItem->GetSize().width / 2);
489 __pEditItem->SetPosition(anchor);
491 __pToolbar->Invalidate(true);
497 _ToolbarPresenter::DrawSeparator(ToolbarSeparatorType type, const Point& point, Canvas* pCanvas)
499 if (__pToolbar->GetStyle() == TOOLBAR_SOFTKEY)
504 int separatorWidth = 0;
505 int separatorHeight = 0;
507 GET_SHAPE_CONFIG(HEADER::SEPARATOR_WIDTH, __pToolbar->GetOrientation(), separatorWidth);
508 GET_SHAPE_CONFIG(HEADER::SEPARATOR_HEIGHT, __pToolbar->GetOrientation(), separatorHeight);
510 if (!__pToolbar->IsTransparent())
512 Bitmap* pSeparatorBitmap = null;
513 GET_BITMAP_CONFIG_N(HEADER::DIVIDER_LINE_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pSeparatorBitmap);
515 if (pSeparatorBitmap)
517 if (pSeparatorBitmap->IsNinePatchedBitmap())
519 pCanvas->DrawNinePatchedBitmap(Rectangle(point.x, point.y, separatorWidth, separatorHeight), *pSeparatorBitmap);
523 pCanvas->DrawBitmap(Point(point.x, point.y), *pSeparatorBitmap);
526 delete pSeparatorBitmap;
531 Bitmap* pTranslucentSeparatorBitmap = null;
532 GET_BITMAP_CONFIG_N(HEADER::DIVIDER_LINE_TRANSLUCENT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pTranslucentSeparatorBitmap);
534 if (pTranslucentSeparatorBitmap)
536 if (pTranslucentSeparatorBitmap->IsNinePatchedBitmap())
538 pCanvas->DrawNinePatchedBitmap(Rectangle(point.x, point.y, separatorWidth, separatorHeight), *pTranslucentSeparatorBitmap);
542 pCanvas->DrawBitmap(Point(point.x, point.y), *pTranslucentSeparatorBitmap);
545 delete pTranslucentSeparatorBitmap;
553 _ToolbarPresenter::DrawItems(void)
555 result r = E_SUCCESS;
557 Canvas* pCanvas = __pToolbar->GetCanvasN();
559 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, E_INVALID_STATE, "[E_INVALID_STATE] System error occurred.");
561 Rectangle usableArea = __toolbarUsableArea;
563 Bitmap* pTitleIcon = __pToolbar->GetTitleIcon();
566 int titleDisplayHeight = 0;
567 int iconAreaHeight = 0;
569 int headerTopMargin = 0;
570 int processingAnimationIconSize = 0;
571 int processingAnimationIconGap = 0;
572 int titleCharacterCount = 0;
574 Dimension titleTextDimension(0, 0);
578 ToolbarStyle toolbarStyle = __pToolbar->GetStyle();
580 GET_SHAPE_CONFIG(HEADER::LEFT_MARGIN, __pToolbar->GetOrientation(), leftMargin); // 16
581 GET_SHAPE_CONFIG(HEADER::PROCESSING_ANIMATION_ICON_SIZE, __pToolbar->GetOrientation(), processingAnimationIconSize); // 32
582 GET_SHAPE_CONFIG(HEADER::PROCESSING_ANIMATION_ICON_GAP, __pToolbar->GetOrientation(), processingAnimationIconGap); // 32
584 if (__pToolbar->GetStyle() == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || __pToolbar->GetStyle() == TOOLBAR_TAB_WITH_TITLE)
586 GET_SHAPE_CONFIG(HEADER::TITLE_TOP_MARGIN_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), headerTopMargin); // 18, 17
587 GET_SHAPE_CONFIG(HEADER::TITLE_DISPLAY_HEIGHT_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), titleDisplayHeight); // 60
591 GET_SHAPE_CONFIG(HEADER::TOP_MARGIN, __pToolbar->GetOrientation(), headerTopMargin); // 34, 17
592 GET_SHAPE_CONFIG(HEADER::TITLE_DISPLAY_HEIGHT, __pToolbar->GetOrientation(), titleDisplayHeight); //64, 64
595 GET_SHAPE_CONFIG(HEADER::ICON_WIDTH, __pToolbar->GetOrientation(), iconWidth); // 38
597 GET_SHAPE_CONFIG(HEADER::TITLE_DISPLAY_HEIGHT_WITH_DESCRIPTION, __pToolbar->GetOrientation(), iconAreaHeight);//50, 42
600 if (!__titleText.IsEmpty())
602 titleCharacterCount = __titleText.GetLength(); // alphabet count
604 if (toolbarStyle == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || toolbarStyle == TOOLBAR_TAB_WITH_TITLE)
606 r = GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE_WITH_SEGMENTED, __pToolbar->GetOrientation(), fontSize);
608 else if (toolbarStyle == TOOLBAR_TITLE && __pToolbar->GetDescriptionText() != L""
609 && __pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) == ANIMATION_STOPPED)
611 r = GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE_WITH_DESCRIPTION, __pToolbar->GetOrientation(), fontSize);
615 r = GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE, __pToolbar->GetOrientation(), fontSize);
625 __fontSize = fontSize;
627 __pTitleTextFont = __pToolbar->GetFallbackFont();
629 SysTryReturnVoidResult(NID_UI_CTRL, __pTitleTextFont, r, "[%s] Propagating.", GetErrorMessage(r));
631 __pTitleTextObject->SetFont(__pTitleTextFont, 0, __pTitleTextObject->GetTextLength());
633 __pTitleTextFont->GetTextExtent(__titleText, titleCharacterCount, titleTextDimension);
635 totalWidth = titleTextDimension.width; // pixel
636 titleHeight = titleTextDimension.height; // pixel
638 __titleRect.height = _FontImpl::GetInstance(*__pTitleTextFont)->GetLeading();
643 pTitleIcon->Scale(Dimension(iconWidth, iconWidth));
648 totalWidth += (pTitleIcon->GetWidth() + usableArea.x);
651 if ((__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE)) != ANIMATION_STOPPED)
653 totalWidth += processingAnimationIconSize + processingAnimationIconGap;
656 if (totalWidth > usableArea.width)
658 __titleRect.width = titleTextDimension.width - (totalWidth - usableArea.width);;
662 pCanvas->DrawBitmap(Point(usableArea.x, headerTopMargin + (titleDisplayHeight - pTitleIcon->GetHeight()) / 2), *(pTitleIcon));
664 __titleRect.x = usableArea.x + pTitleIcon->GetWidth() + usableArea.x;
665 __titleRect.y = headerTopMargin + (titleDisplayHeight - titleHeight) / 2;
667 if (__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
669 __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
670 usableArea.x + (pTitleIcon->GetWidth() + processingAnimationIconGap) + __titleRect.width + processingAnimationIconGap,
671 headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
676 __titleRect.x = usableArea.x;
677 __titleRect.y = headerTopMargin + (titleDisplayHeight - titleHeight) / 2;
679 if (__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
681 __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
682 usableArea.x + __titleRect.width + processingAnimationIconGap,
683 headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
689 __titleRect.width = usableArea.width;
693 __titleRect.x = leftMargin + pTitleIcon->GetWidth() + leftMargin;
694 __titleRect.y = headerTopMargin + (titleDisplayHeight - titleHeight) / 2;
696 if(__pTitleTextObject->GetAlignment() & TEXT_OBJECT_ALIGNMENT_CENTER)
698 leftMargin = (__titleRect.width - titleTextDimension.width) / 2;
700 else if(__pTitleTextObject->GetAlignment() & TEXT_OBJECT_ALIGNMENT_RIGHT)
702 leftMargin = __titleRect.width - titleTextDimension.width - leftMargin * 2;
705 pCanvas->DrawBitmap(Point(leftMargin, headerTopMargin + (titleDisplayHeight - pTitleIcon->GetHeight()) / 2), *(pTitleIcon));
707 if (__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
709 __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
710 usableArea.x + (pTitleIcon->GetWidth() + processingAnimationIconGap) + titleTextDimension.width + processingAnimationIconGap,
711 headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
714 __titleRect.width -= (pTitleIcon->GetWidth() + usableArea.x);
718 __titleRect.x = leftMargin;
719 __titleRect.y = headerTopMargin + (titleDisplayHeight - titleHeight) / 2;
721 if (__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
723 __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
724 leftMargin + titleTextDimension.width + processingAnimationIconGap,
725 headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
732 if (pTitleIcon && __pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
734 pTitleIcon->Scale(Dimension(iconWidth, iconWidth));
736 if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_CENTER)
738 leftMargin = (leftMargin + usableArea.width - (pTitleIcon->GetWidth() + processingAnimationIconGap + processingAnimationIconSize)) / 2;
740 else if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_RIGHT)
742 leftMargin = leftMargin + usableArea.width - (pTitleIcon->GetWidth() + processingAnimationIconGap + processingAnimationIconSize);
745 pCanvas->DrawBitmap(Point(leftMargin, headerTopMargin + (titleDisplayHeight - pTitleIcon->GetHeight()) / 2), *(pTitleIcon));
747 __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
748 leftMargin + processingAnimationIconGap + processingAnimationIconSize,
749 headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
753 pTitleIcon->Scale(Dimension(iconWidth, iconWidth));
755 if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_CENTER)
757 leftMargin = usableArea.width / 2;
759 else if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_RIGHT)
761 leftMargin = usableArea.width - pTitleIcon->GetWidth();
764 pCanvas->DrawBitmap(Point(leftMargin, headerTopMargin + (titleDisplayHeight - pTitleIcon->GetHeight()) / 2), *(pTitleIcon));
768 if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_CENTER)
770 leftMargin = (usableArea.width - (processingAnimationIconGap + processingAnimationIconSize))/ 2;
772 else if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_RIGHT)
774 leftMargin = usableArea.width - (processingAnimationIconGap + processingAnimationIconSize);
777 __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
778 leftMargin, headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
788 _ToolbarPresenter::DrawTitleText(Canvas* pCanvas)
790 TimerForTitleSlideInit();
792 if (__titleText.IsEmpty())
797 __pTitleTextObject->SetForegroundColor(__pToolbar->GetTitleTextColor(), 0, __pTitleTextObject->GetTextLength());
798 __pTitleTextObject->SetBounds(__titleRect);
799 __pTitleTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
800 __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT);
801 __pTitleTextObject->Compose();
802 __pTitleTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
804 if (__pTitleTextObject->IsActionOn() == true)
806 TimerForTitleSlideStart();
813 _ToolbarPresenter::GetSelectedItemIndex(void) const
815 return __pToolbarModel->GetSelectedItemIndex();
819 _ToolbarPresenter::IsInitialDraw(void) const
821 return __initialDraw;
825 _ToolbarPresenter::IsTabEditModeEnabled(void) const
827 return __tabEditEnabled;
831 _ToolbarPresenter::SetDescriptionText(const String& description)
833 result r = E_SUCCESS;
835 int length = description.GetLength();
838 wchar_t* tempString = const_cast<wchar_t*>(description.GetPointer());
841 if (__pDescriptionTextObject != null)
843 delete __pDescriptionTextObject;
844 __pDescriptionTextObject = null;
847 __pDescriptionTextObject = new (std::nothrow) TextObject();
849 if (__pDescriptionTextObject == null)
851 return E_OUT_OF_MEMORY;
853 __pDescriptionTextObject->Construct();
854 TextSimple* pSimpleText = new (std::nothrow) TextSimple(tempString, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
855 __pDescriptionTextObject->AppendElement(*pSimpleText);
856 __pDescriptionTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
857 __pDescriptionTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER);
859 GET_SHAPE_CONFIG(HEADER::DESCRIPTION_TEXT_FONT_SIZE, __pToolbar->GetOrientation(), fontSize);
861 __fontSize = fontSize;
863 __pTextFont = __pToolbar->GetFallbackFont();
865 SysTryReturn(NID_UI_CTRL, __pTextFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
867 __pDescriptionTextObject->SetFont(__pTextFont, 0, __pDescriptionTextObject->GetTextLength());
873 _ToolbarPresenter::SetItemSelected(int itemIndex)
875 return __pToolbarModel->SetSelectedItemIndex(itemIndex);
879 _ToolbarPresenter::SetInitialDrawState(bool state)
882 __initialDraw = state;
889 _ToolbarPresenter::SetTabEditModeEnabled(bool enable)
891 __tabEditEnabled = enable;
897 _ToolbarPresenter::SetTitleText(const String& title, HorizontalAlignment alignment)
899 result r = E_SUCCESS;
901 int length = title.GetLength();
903 __titleText = String(title);
904 wchar_t* tempString = const_cast<wchar_t*>(__titleText.GetPointer());
907 if (__pTitleTextObject != null)
909 delete __pTitleTextObject;
910 __pTitleTextObject = null;
913 __pTitleTextObject = new (std::nothrow) TextObject();
915 if (__pTitleTextObject == null)
917 return E_OUT_OF_MEMORY;
919 __pTitleTextObject->Construct();
920 TextSimple* pSimpleText = new (std::nothrow) TextSimple(tempString, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
921 __pTitleTextObject->AppendElement(*pSimpleText);
923 __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT);
928 __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
930 case ALIGNMENT_CENTER:
931 __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER);
933 case ALIGNMENT_RIGHT:
934 __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_RIGHT);
937 __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
943 r = GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE, __pToolbar->GetOrientation(), fontSize);
945 __fontSize = fontSize;
947 __pTitleTextFont = __pToolbar->GetFallbackFont();
949 SysTryReturn(NID_UI_CTRL, __pTitleTextFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
951 __pTitleTextObject->SetFont(__pTitleTextFont, 0, __pTitleTextObject->GetTextLength());
957 _ToolbarPresenter::SetUsableAreaBounds(const Rectangle& rect)
959 __toolbarUsableArea = rect;
965 _ToolbarPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
967 __touchInitiatedInToolbar = true;
969 __currentTouchPosition = touchinfo.GetCurrentPosition();
971 __initialPressedItemIndex = __pToolbar->GetItemIndexFromPosition(__currentTouchPosition);
973 if (__initialPressedItemIndex == -1)
979 _Button* pPressedButton = __pToolbar->GetItem(__initialPressedItemIndex);
981 __initialPressesItemStatus = pPressedButton->GetButtonStatus();
983 if (__initialPressesItemStatus == _BUTTON_STATUS_DISABLED)
988 pPressedButton->SetButtonStatus(_BUTTON_STATUS_PRESSED);
991 __pToolbar->Invalidate(true);
997 _ToolbarPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
999 if (!__touchInitiatedInToolbar)
1004 __touchInitiatedInToolbar = false;
1006 Point touchPoint = touchinfo.GetCurrentPosition();
1008 int currentItemIndex = __pToolbar->GetItemIndexFromPosition(touchPoint);
1010 if ((__pToolbar->GetStyle() == TOOLBAR_TAB || __pToolbar->GetStyle() == TOOLBAR_TAB_WITH_TITLE)&& __beingEdited == true)
1012 __beingEdited = false;
1014 if (currentItemIndex == -1)
1018 __pToolbar->DetachChild(*__pEditItem);
1023 if (__initialPressedItemIndex != -1)
1025 __pToolbar->GetItem(__initialPressedItemIndex)->SetButtonStatus(__initialPressesItemStatus);
1030 __pToolbar->MoveItem(__editItemIndex, currentItemIndex);
1034 __pToolbar->DetachChild(*__pEditItem);
1042 if ((__pToolbar->GetStyle() == TOOLBAR_TAB || __pToolbar->GetStyle() == TOOLBAR_TAB_WITH_TITLE)
1043 && __pToolbar->GetItemCount() > 4)// && pMoreButton != null)
1045 if (__initialPressedItemIndex != -1)
1047 if (currentItemIndex == __initialPressedItemIndex)
1049 if (__initialPressesItemStatus != _BUTTON_STATUS_DISABLED && __touchMoveHandled != true)
1051 __pToolbar->SetItemSelected(currentItemIndex, true);
1055 __pToolbar->GetItem(__initialPressedItemIndex)->SetButtonStatus(__initialPressesItemStatus, false);
1060 __pToolbar->GetItem(__initialPressedItemIndex)->SetButtonStatus(__initialPressesItemStatus, false);
1066 if (__initialPressedItemIndex != -1 && (currentItemIndex != __initialPressedItemIndex))
1068 __pToolbar->GetItem(__initialPressedItemIndex)->SetButtonStatus(__initialPressesItemStatus, false);
1072 if (__initialPressedItemIndex != -1 && __initialPressesItemStatus != _BUTTON_STATUS_DISABLED)
1074 __pToolbar->SetItemSelected(currentItemIndex, true);
1082 __touchMoveHandled = false;
1084 // Restore status of other buttons to _BUTTON_STATUS_NORMAL // this can be removed
1085 int itemCount = __pToolbar->GetItemCount();
1087 for (int j = 0; j < itemCount; j++)
1089 if (__pToolbar->GetItem(j) != null && __pToolbar->GetItem(j)->GetButtonStatus() == _BUTTON_STATUS_PRESSED)
1091 __pToolbar->GetItem(j)->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1096 __pToolbar->Invalidate(true);
1102 _ToolbarPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1104 if (!__touchInitiatedInToolbar)
1109 if ((__pToolbar->GetStyle() == TOOLBAR_TAB || __pToolbar->GetStyle() == TOOLBAR_TAB_WITH_TITLE)
1110 && __pToolbar->GetItemCount() > 4)
1112 __touchMoveHandled = true;
1115 Point touchPoint = touchinfo.GetCurrentPosition();
1117 if ((__pToolbar->GetStyle() == TOOLBAR_TAB || __pToolbar->GetStyle() == TOOLBAR_TAB_WITH_TITLE)
1118 && __beingEdited == true)
1120 DrawEditItem(touchinfo.GetCurrentPosition());
1122 else if (__initialPressedItemIndex != -1)
1124 if (__initialPressesItemStatus == _BUTTON_STATUS_DISABLED)
1129 _Button* pCurrentButton = __pToolbar->GetItem(__initialPressedItemIndex);
1131 if (pCurrentButton == null)
1136 Rectangle itemBounds = pCurrentButton->GetBounds();
1138 if (__touchMoveHandled)
1140 pCurrentButton->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1142 else if (itemBounds.Contains(touchPoint))
1144 pCurrentButton->SetButtonStatus(_BUTTON_STATUS_PRESSED);
1148 pCurrentButton->SetButtonStatus(__initialPressesItemStatus, false);
1151 pCurrentButton->Invalidate(false);
1154 if ((__pToolbar->GetStyle() == TOOLBAR_TAB || __pToolbar->GetStyle() == TOOLBAR_TAB_WITH_TITLE)
1155 && __pToolbar->GetItemCount() > 4)
1157 int distance = (touchinfo.GetCurrentPosition()).x - __currentTouchPosition.x;
1160 GET_SHAPE_CONFIG(HEADER::TAB_LEFT_MARGIN, __pToolbar->GetOrientation(), sideMargin);
1162 Rectangle clientBounds = __pToolbar->GetBounds();
1164 const Dimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSize();
1165 const Dimension landscapeSize = Dimension(portraitSize.height, portraitSize.width);
1167 if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
1169 if (clientBounds.width > portraitSize.width)
1171 clientBounds.width = portraitSize.width;
1176 if (clientBounds.width > landscapeSize.width)
1178 clientBounds.width = landscapeSize.width;
1182 __currentTouchPosition = touchinfo.GetCurrentPosition();
1184 _Button* pItem = null;
1185 Rectangle itemBounds;
1186 int itemCount = __pToolbar->GetItemCount();
1188 if (distance > 0) // right move
1190 pItem = __pToolbar->GetItem(0);
1196 itemBounds = pItem->GetBounds();
1198 if (itemBounds.x == 0)
1203 if (itemBounds.x + distance >= sideMargin)
1205 distance = sideMargin - itemBounds.x;
1210 pItem = __pToolbar->GetItem(itemCount - 1);
1217 itemBounds = pItem->GetBounds();
1219 if (itemBounds.x + itemBounds.width == clientBounds.width - sideMargin)
1224 if (itemBounds.x + itemBounds.width + distance <= clientBounds.width - sideMargin)
1226 distance = (clientBounds.width - sideMargin) - (itemBounds.x + itemBounds.width);
1230 AdjustItemPositionX(distance);
1239 _ToolbarPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1241 __touchInitiatedInToolbar = false;
1243 // Restore status of other buttons to _BUTTON_STATUS_NORMAL // this can be removed
1244 int itemCount = __pToolbar->GetItemCount();
1246 for (int i = 0; i < itemCount; i++)
1248 if (__pToolbar->GetItem(i) != null && __pToolbar->GetItem(i)->GetButtonStatus() == _BUTTON_STATUS_PRESSED)
1250 __pToolbar->GetItem(i)->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1255 __pToolbar->Invalidate(true);
1261 _ToolbarPresenter::OnLongPressGestureDetected(void)
1263 if (__pToolbar->IsTabEditModeEnabled() == true)
1265 int longPressedItemIndex = __pToolbar->GetItemIndexFromPosition(__currentTouchPosition);
1267 if (longPressedItemIndex == -1)
1272 __editItemIndex = longPressedItemIndex;
1274 __beingEdited = true;
1276 _Button* pButton = null;
1277 pButton = __pToolbar->GetItem(__editItemIndex);
1278 SysTryReturn(NID_UI_CTRL, pButton, true, E_INVALID_STATE, "[E_INVALID_STATE] Unable to retrieve a button");
1280 pButton->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1282 Rectangle itemBounds = pButton->GetBounds();
1286 __pToolbar->DetachChild(*__pEditItem);
1291 __pEditItem = _Label::CreateLabelN();
1292 SysTryCatch(NID_UI_CTRL, __pEditItem, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1294 Canvas* pCanvas = pButton->GetCanvasN();
1295 SysTryCatch(NID_UI_CTRL, pCanvas, , E_INVALID_STATE, "[E_INVALID_STATE] Unable to retrieve a Canvas.");
1297 Bitmap* pEditItemBitmap = new (std::nothrow) Bitmap();
1298 result r = pEditItemBitmap->Construct(*pCanvas, Rectangle(0, 0, itemBounds.width, itemBounds.height));
1302 delete pEditItemBitmap;
1303 pEditItemBitmap = null;
1310 __pEditItem->SetBounds(itemBounds);
1311 __pEditItem->SetBackgroundBitmap(*pEditItemBitmap);
1314 delete pEditItemBitmap;
1316 __pToolbar->AttachChild(*__pEditItem);
1317 __pToolbar->SetChildAlwaysOnTop(*__pEditItem);
1335 _ToolbarPresenter::OnTimerExpired(Timer& timer)
1337 Timer* onTimer = &timer;
1339 if (onTimer == __pTitleSlideTimer)
1341 TimerForTitleSlideTimeout();
1348 _ToolbarPresenter::TimerForTitleSlideInit(void)
1350 result r = E_SUCCESS;
1352 if (__pTitleSlideTimer != null)
1354 delete __pTitleSlideTimer;
1355 __pTitleSlideTimer = null;
1362 _ToolbarPresenter::TimerForTitleSlideStart(void)
1364 result r = E_SUCCESS;
1366 if (__pTitleSlideTimer == null)
1368 __pTitleSlideTimer = new (std::nothrow) Timer();
1369 if (__pTitleSlideTimer == null)
1371 r = E_OUT_OF_MEMORY;
1375 r = __pTitleSlideTimer->Construct(*this);
1378 delete __pTitleSlideTimer;
1383 r = __pTitleSlideTimer->Start(100);
1394 _ToolbarPresenter::TimerForTitleSlideTimeout(void)
1396 result r = E_SUCCESS;
1398 Canvas* pCanvas = __pToolbar->GetCanvasN();
1399 SysTryReturnResult(NID_UI_CTRL, pCanvas, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pCanvas is invalid!");
1401 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1402 pCanvas->Clear(__titleRect);
1404 if (__pTitleBackgroundBitmap)
1406 pCanvas->DrawBitmap(__titleRect, *__pTitleBackgroundBitmap);
1409 if (__pTitleTextObject->IsChanged())
1411 DrawTitleText(pCanvas);
1414 __pTitleTextObject->DrawWithOffset(*_CanvasImpl::GetInstance(*pCanvas));
1418 r = TimerForTitleSlideStart();
1424 _ToolbarPresenter::AdjustItemPositionX(int distance)
1427 int itemCount = __pToolbar->GetItemCount();
1428 _Button* pItem = __pToolbar->GetItem(index);
1430 while (pItem != null)
1432 Rectangle bounds = pItem->GetBounds();
1433 bounds.x += distance;
1434 pItem->SetBounds(bounds);
1437 if (index < itemCount)
1439 pItem = __pToolbar->GetItem(index);
1451 _ToolbarPresenter::GetTitleTextBounds(void) const
1457 _ToolbarPresenter::GetDescriptionBounds(void) const
1459 return __descriptionRect;
1463 _ToolbarPresenter::_SetModel(const _ToolbarModel& toolbarModel)
1465 __pToolbarModel = const_cast<_ToolbarModel*>(&toolbarModel);
1471 _ToolbarPresenter::OnFontChanged(Font* pFont)
1473 __pTextFont = pFont;
1474 __pTitleTextFont = pFont;
1480 _ToolbarPresenter::OnFontInfoRequested(unsigned long& style, int& size)
1482 style = __fontStyle;
1489 _ToolbarPresenter::SetFontInfo(unsigned long style, int size)
1491 __fontStyle = style;
1497 }}} // Tizen::Ui::Controls