f559788b40b9ca8b62d8e1a54947a20046a6310b
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_ToolbarPresenter.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FUiCtrl_ToolbarPresenter.cpp
19  * @brief               This is the implementation file for the _ToolbarPresenter class.
20  */
21
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"
37
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;
43
44 namespace Tizen { namespace Ui { namespace Controls
45 {
46
47 _ToolbarPresenter::_ToolbarPresenter(void)
48         : __pToolbar(null)
49         , __pToolbarModel(null)
50         , __initialDraw(true)
51         , __tabEditEnabled(false)
52         , __beingEdited(false)
53         , __touchInitiatedInToolbar(false)
54         , __editItemIndex(-1)
55         , __pressedItemIndex(-1)
56         , __initialPressesItemStatus(_BUTTON_STATUS_NORMAL)
57         , __pEditItem(null)
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))
63         , __titleText(L"")
64         , __pTitleTextFont(null)
65         , __pTextFont(null)
66         , __pDescriptionTextObject(null)
67         , __pTitleTextObject(null)
68         , __pBouncingEffectVe(null)
69         , __flickAnimation()
70         , __moveDistance(0.0f)
71         , __flickMove(0.0f)
72         , __flickDistance(0.0f)
73         , __flickFlag(0)
74         , __firstLoadedItemIndex(0)
75         , __lastLoadedItemIndex(0)
76         , __tabSlideLeft(false)
77         , __tabSlideRight(false)
78         , __portraitSize(FloatDimension(0.0f, 0.0f))
79         , __landscapeSize(FloatDimension(0.0f, 0.0f))
80         , __fontStyle(0)
81         , __fontSize(0.0f)
82         , __tabMoved(false)
83         , __titlePressed(false)
84         , __titleSliding(false)
85 {
86         __currentTouchPosition = FloatPoint(0.0f, 0.0f);
87 }
88
89 _ToolbarPresenter::~_ToolbarPresenter(void)
90 {
91         if (__pToolbarModel)
92         {
93                 delete __pToolbarModel;
94                 __pToolbarModel = null;
95         }
96
97         if (__pEditItem)
98         {
99                 __pToolbar->DetachChild(*__pEditItem);
100                 delete __pEditItem;
101                 __pEditItem = null;
102         }
103
104         if (__pTitleBackgroundBitmap)
105         {
106                 delete __pTitleBackgroundBitmap;
107                 __pTitleBackgroundBitmap = null;
108         }
109
110         if (__pTitleSlideTimer)
111         {
112                 delete __pTitleSlideTimer;
113                 __pTitleSlideTimer = null;
114         }
115
116         if (__pFlickAnimationTimer)
117         {
118                 delete __pFlickAnimationTimer;
119                 __pFlickAnimationTimer = null;
120         }
121
122         if (__pDescriptionTextObject)
123         {
124                 delete __pDescriptionTextObject;
125                 __pDescriptionTextObject = null;
126         }
127
128         if (__pTitleTextObject)
129         {
130                 delete __pTitleTextObject;
131                 __pTitleTextObject = null;
132         }
133
134         if (__pBouncingEffectVe)
135         {
136                 __pBouncingEffectVe->RemoveAllAnimations();
137                 __pBouncingEffectVe->Destroy();
138                 __pBouncingEffectVe = null;
139         }
140 }
141
142 result
143 _ToolbarPresenter::Construct(const _Toolbar& toolbar)
144 {
145         __pToolbar = const_cast<_Toolbar*>(&toolbar);
146
147         float width = 0.0f;
148         float height = 0.0f;
149
150         __fontStyle = FONT_STYLE_BOLD;
151
152         __portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
153         __landscapeSize = FloatDimension(__portraitSize.height, __portraitSize.width);
154
155         if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
156         {
157                 width = __portraitSize.width;
158                 height = __portraitSize.height;
159         }
160         else
161         {
162                 width = __landscapeSize.width;
163                 height = __landscapeSize.height;
164         }
165
166         __flickAnimation.SetSizeInformation(width, height, DEVICE_SIZE_HORIZONTAL, DEVICE_SIZE_VERTICAL);
167         __flickAnimation.SetSensitivity(FLICK_ANIMATION_FPS_TAB, FLICK_ANIMATION_SENSITIVITY_TAB);
168         __flickAnimation.SetDirection(FD_HORIZONTAL);
169
170         return E_SUCCESS;
171 }
172
173 result
174 _ToolbarPresenter::Install(void)
175 {
176         _ToolbarModel* pModel = new (std::nothrow) _ToolbarModel();
177
178         _SetModel(*pModel);
179
180         result r = pModel->Construct();
181
182         return r;
183 }
184
185 result
186 _ToolbarPresenter::Draw(void)
187 {
188         result r = E_SUCCESS;
189
190         ToolbarStyle style = __pToolbar->GetStyle();
191
192         DrawBackground();
193
194         DrawItems();
195
196         Canvas* pCanvas = __pToolbar->GetCanvasN();
197
198         if (pCanvas == null)
199         {
200                 SysLog(NID_UI_CTRL, "Cannot get a canvas.");
201
202                 return E_SYSTEM;
203         }
204
205         float fontSize = 0.0f;
206
207         if (style == TOOLBAR_TITLE || style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
208         {
209                 if (__pTitleBackgroundBitmap)
210                 {
211                         delete __pTitleBackgroundBitmap;
212                         __pTitleBackgroundBitmap = null;
213                 }
214
215                 if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
216                 {
217                         GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE_WITH_SEGMENTED, __pToolbar->GetOrientation(), fontSize);
218
219                         if (!__titleText.IsEmpty())
220                         {
221                                 __fontSize = fontSize;
222
223                                 __pTitleTextFont = __pToolbar->GetFallbackFont();
224                                 r = GetLastResult();
225                                 SysTryReturn(NID_UI_CTRL, __pTitleTextFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
226
227                                 __pTitleTextObject->SetFont(__pTitleTextFont, 0, __pTitleTextObject->GetTextLength());
228                         }
229                 }
230                 else if (style == TOOLBAR_TITLE && __pToolbar->GetDescriptionText() != L""
231                                 && __pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) == ANIMATION_STOPPED)
232                 {
233                         GET_SHAPE_CONFIG(HEADER::TITLE_TOP_MARGIN_WITH_DESCRIPTION, __pToolbar->GetOrientation(), __titleRect.y);
234                         __titleRect.height = _FontImpl::GetInstance(*__pTitleTextFont)->GetLeadingF();
235                         GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE_WITH_DESCRIPTION, __pToolbar->GetOrientation(), fontSize);
236
237                         DrawDescriptionText();
238
239                         if(!__titleText.IsEmpty())
240                         {
241                                 __fontSize = fontSize;
242
243                                 __pTitleTextFont = __pToolbar->GetFallbackFont();
244                                 r = GetLastResult();
245                                 SysTryReturn(NID_UI_CTRL, __pTitleTextFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
246
247                                 __pTitleTextObject->SetFont(__pTitleTextFont, 0, __pTitleTextObject->GetTextLength());
248                         }
249                 }
250
251                 __pTitleBackgroundBitmap = new (std::nothrow) Bitmap();
252                 __pTitleBackgroundBitmap->Construct(*pCanvas, __titleRect);
253
254                 DrawTitleText(pCanvas);
255         }
256
257         DrawDivider();
258
259         if (__initialDraw)
260         {
261                 if ((style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE
262                                 || style == TOOLBAR_SEGMENTED || style == TOOLBAR_HEADER_SEGMENTED || style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE)
263                                 && __pToolbar->GetItemCount() > 0 && __pToolbarModel->GetSelectedItemIndex() == -1)
264                 {
265                         int firstEnabledItemIndex = __pToolbar->GetFirstEnabledItemIndex();
266
267                         if(firstEnabledItemIndex != -1)
268                         {
269                                 __pToolbar->SetItemSelected(firstEnabledItemIndex, true, false);
270                         }
271                 }
272
273                 __initialDraw = false;
274         }
275
276         delete pCanvas;
277
278         return E_SUCCESS;
279 }
280
281 void
282 _ToolbarPresenter::DrawDivider(void)
283 {
284         ToolbarStyle style = __pToolbar->GetStyle();
285
286         if (style == TOOLBAR_SOFTKEY)
287         {
288                 return ;
289         }
290
291         float buttonItemGap = 0.0f;
292         float dividerBaseHeight = 0.0f;
293         float dividerHeight = 0.0f;
294         float dividerTopMargin = 0.0f;
295
296         int itemCount = __pToolbar->GetItemCount();
297
298         GET_SHAPE_CONFIG(HEADER::DIVIDER_WIDTH, __pToolbar->GetOrientation(), buttonItemGap);
299
300         if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
301         {
302                 GET_SHAPE_CONFIG(HEADER::SEGMENTED_ITEM_HEIGHT, __pToolbar->GetOrientation(), dividerBaseHeight);
303                 GET_SHAPE_CONFIG(HEADER::TITLE_HEIGHT_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), dividerTopMargin);
304         }
305         else
306         {
307                 GET_SHAPE_CONFIG(HEADER::HEIGHT, __pToolbar->GetOrientation(), dividerBaseHeight);
308         }
309
310         if (style == TOOLBAR_TAB_LARGE)
311         {
312                 GET_SHAPE_CONFIG(HEADER::TAB_LARGE_DIVIDER_HEIGHT, __pToolbar->GetOrientation(), dividerHeight);
313         }
314         else
315         {
316                 GET_SHAPE_CONFIG(HEADER::DIVIDER_HEIGHT, __pToolbar->GetOrientation(), dividerHeight);
317         }
318
319         FloatRectangle bounds(0.0f, 0.0f, __pToolbar->GetBoundsF().width, __pToolbar->GetBoundsF().height);
320
321         if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
322         {
323                 if (bounds.width > __portraitSize.width)
324                 {
325                         bounds.width = __portraitSize.width;
326                 }
327         }
328         else
329         {
330                 if (bounds.width > __landscapeSize.width)
331                 {
332                         bounds.width = __landscapeSize.width;
333                 }
334         }
335
336         Canvas * pCanvas = null;
337         int Z_ORDER_GROUP_CONTROL = 2001;
338
339         if (__pBouncingEffectVe == null)
340         {
341                 __pBouncingEffectVe = new (std::nothrow) VisualElement();
342                 SysTryReturnVoidResult(NID_UI_CTRL, __pBouncingEffectVe, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
343
344                 __pBouncingEffectVe->Construct();
345                 __pBouncingEffectVe->SetName(L"BouncingEffect");
346         }
347
348         __pBouncingEffectVe->SetBounds(FloatRectangle(0.0f, 0.0f, __pToolbar->GetBoundsF().width, __pToolbar->GetBoundsF().height));
349         __pBouncingEffectVe->SetShowState(true);
350         __pBouncingEffectVe->SetImplicitAnimationEnabled(false);
351
352         _VisualElementImpl::GetInstance(*__pBouncingEffectVe)->SetZOrderGroup(Z_ORDER_GROUP_CONTROL + 1);
353         __pToolbar->GetVisualElement()->AttachChild(*__pBouncingEffectVe);
354
355         pCanvas = __pBouncingEffectVe->GetCanvasN();
356
357         if (!pCanvas)
358         {
359                 __pBouncingEffectVe->Destroy();
360                 __pBouncingEffectVe = null;
361
362                 SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
363
364                 return;
365         }
366
367         Color backgroundColor(0, 0, 0, 0);
368         pCanvas->SetBackgroundColor(backgroundColor);
369         pCanvas->Clear();
370
371         if (style == TOOLBAR_TITLE || style == TOOLBAR_HEADER_SEGMENTED)
372         {
373                 if (__pToolbar->GetButton(RIGHT_BUTTON))
374                 {
375                         if (__pToolbar->GetButton(LEFT_BUTTON))
376                         {
377                                 DrawDividerLine(FloatPoint(bounds.width - __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF().width - buttonItemGap,
378                                                 (__pToolbar->GetBoundsF().height - dividerHeight) / 2), pCanvas);
379
380                                 DrawDividerLine(FloatPoint(bounds.width - __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF().width - buttonItemGap
381                                                 - __pToolbar->GetButton(LEFT_BUTTON)->GetBoundsF().width - buttonItemGap,
382                                                 (__pToolbar->GetBoundsF().height - dividerHeight) / 2), pCanvas);
383                         }
384                         else
385                         {
386                                 DrawDividerLine(FloatPoint(bounds.width - __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF().width - buttonItemGap,
387                                                 (__pToolbar->GetBoundsF().height - dividerHeight) / 2), pCanvas);
388                         }
389                 }
390                 else
391                 {
392                         if (__pToolbar->GetButton(LEFT_BUTTON))
393                         {
394                                 DrawDividerLine(FloatPoint(bounds.width - __pToolbar->GetButton(LEFT_BUTTON)->GetBoundsF().width - buttonItemGap,
395                                                 (__pToolbar->GetBoundsF().height - dividerHeight) / 2), pCanvas);
396                         }
397                 }
398         }
399         else if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE)
400         {
401                 if (__pToolbar->GetButton(RIGHT_BUTTON))
402                 {
403                         if (__pToolbar->GetButton(LEFT_BUTTON))
404                         {
405                                 DrawDividerLine(FloatPoint(bounds.width - __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF().width - buttonItemGap,
406                                                 dividerTopMargin + (dividerBaseHeight - dividerHeight) / 2), pCanvas);
407
408                                 DrawDividerLine(FloatPoint(bounds.width - __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF().width - buttonItemGap
409                                                 - __pToolbar->GetButton(LEFT_BUTTON)->GetBoundsF().width - buttonItemGap,
410                                                 dividerTopMargin + (dividerBaseHeight - dividerHeight) / 2), pCanvas);
411                         }
412                         else
413                         {
414                                 DrawDividerLine(FloatPoint(bounds.width - __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF().width - buttonItemGap,
415                                                 dividerTopMargin + (dividerBaseHeight - dividerHeight) / 2), pCanvas);
416                         }
417                 }
418                 else
419                 {
420                         if (__pToolbar->GetButton(LEFT_BUTTON))
421                         {
422                                 DrawDividerLine(FloatPoint(bounds.width - __pToolbar->GetButton(LEFT_BUTTON)->GetBoundsF().width - buttonItemGap,
423                                                 dividerTopMargin + (dividerBaseHeight - dividerHeight) / 2), pCanvas);
424                         }
425                 }
426         }
427         else if (style == TOOLBAR_SEGMENTED || style == TOOLBAR_TEXT || style == TOOLBAR_ICON || style == TOOLBAR_ICON_TEXT || style == TOOLBAR_COMMAND)
428         {
429                 if (__pToolbar->GetButton(RIGHT_BUTTON))
430                 {
431                         DrawDividerLine(FloatPoint(bounds.width - __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF().width - buttonItemGap,
432                                         (__pToolbar->GetBoundsF().height - dividerHeight) / 2), pCanvas);
433                 }
434
435                 if (__pToolbar->GetButton(LEFT_BUTTON))
436                 {
437                         DrawDividerLine(FloatPoint(__pToolbar->GetButton(LEFT_BUTTON)->GetBoundsF().width,
438                                         (__pToolbar->GetBoundsF().height - dividerHeight) / 2), pCanvas);
439                 }
440         }
441
442         if (itemCount == 1)
443         {
444                 ; // empty
445         }
446         else
447         {
448                 if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
449                 {
450                         for (int i = 0; i < itemCount - 1 ; i++)
451                         {
452                                 DrawDividerLine(FloatPoint(__pToolbar->GetItem(i)->GetBoundsF().x + __pToolbar->GetItem(i)->GetBoundsF().width,
453                                                 dividerTopMargin + (dividerBaseHeight - dividerHeight) / 2), pCanvas);
454                         }
455                 }
456                 else
457                 {
458                         for (int i = 0; i < itemCount - 1 ; i++)
459                         {
460                                 DrawDividerLine(FloatPoint(__pToolbar->GetItem(i)->GetBoundsF().x + __pToolbar->GetItem(i)->GetBoundsF().width,
461                                                 (__pToolbar->GetBoundsF().height - dividerHeight) / 2), pCanvas);
462                         }
463                 }
464         }
465
466         delete pCanvas;
467
468         return;
469 }
470
471 void
472 _ToolbarPresenter::DrawBackground(void)
473 {
474         Canvas* pCanvas = __pToolbar->GetCanvasN();
475
476         if (pCanvas == null)
477         {
478                 SysLog(NID_UI_CTRL, "Cannot get a canvas.");
479
480                 return;
481         }
482
483         ToolbarStyle style = __pToolbar->GetStyle();
484
485         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
486         pCanvas->Clear();
487
488         if (style == TOOLBAR_SOFTKEY)
489         {
490                 delete pCanvas;
491
492                 return;
493         }
494
495         Bitmap* pReplacementColorBackgroundBitmap = null;
496         Bitmap* pBackgroundBitmap = null;
497         //Bitmap* pBackgroundEffectBitmap = null;
498
499         FloatRectangle bounds(0.0f, 0.0f, __pToolbar->GetBoundsF().width, __pToolbar->GetBoundsF().height);
500
501         __portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
502         __landscapeSize = FloatDimension(__portraitSize.height, __portraitSize.width);
503
504         if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
505         {
506                 if (bounds.width > __portraitSize.width)
507                 {
508                         bounds.width = __portraitSize.width;
509                 }
510         }
511         else
512         {
513                 if (bounds.width > __landscapeSize.width)
514                 {
515                         bounds.width = __landscapeSize.width;
516                 }
517         }
518
519         pBackgroundBitmap = __pToolbar->GetBackgroundBitmap();
520         //pBackgroundEffectBitmap = __pToolbar->GetBackgroundEffectBitmap();
521
522         pReplacementColorBackgroundBitmap =
523                                 _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pToolbar->GetColor());
524
525         if (__pToolbar->IsUserBackgroundBitmap())
526         {
527                 if (pBackgroundBitmap)
528                 {
529                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
530                         {
531                                 pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
532                         }
533                         else
534                         {
535                                 pCanvas->DrawBitmap(bounds, *pBackgroundBitmap, FloatRectangle(0.0f, 0.0f, pBackgroundBitmap->GetWidthF(), pBackgroundBitmap->GetHeightF()));
536                         }
537                 }
538                 else
539                 {
540                         pCanvas->FillRectangle(__pToolbar->GetColor(), bounds);
541                 }
542         }
543         else
544         {
545                 if (pReplacementColorBackgroundBitmap)
546                 {
547                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
548                         {
549                                 pCanvas->DrawNinePatchedBitmap(bounds, *pReplacementColorBackgroundBitmap);
550                         }
551                         else
552                         {
553                                 pCanvas->DrawBitmap(bounds, *pReplacementColorBackgroundBitmap, FloatRectangle(0.0f, 0.0f, pReplacementColorBackgroundBitmap->GetWidthF(), pReplacementColorBackgroundBitmap->GetHeightF()));
554                         }
555                 }
556                 else
557                 {
558                         pCanvas->FillRectangle(__pToolbar->GetColor(), bounds);
559                 }
560
561                 //if (pBackgroundEffectBitmap)
562                 //{
563                 //      if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundEffectBitmap))
564                 //      {
565                 //              pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundEffectBitmap);
566                 //      }
567                 //      else
568                 //      {
569                 //              pCanvas->DrawBitmap(bounds, *pBackgroundEffectBitmap, FloatRectangle(0.0f, 0.0f, pBackgroundEffectBitmap->GetWidthF(), pBackgroundEffectBitmap->GetHeightF()));
570                 //      }
571                 //}
572         }
573
574         if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
575         {
576                 Bitmap* pSubTitleEffectBitmap = null;
577                 Color subTitleEffectColor;
578                 float topMargin = 0.0f;
579
580                 GET_BITMAP_CONFIG_N(HEADER::SUB_TITLE_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, pSubTitleEffectBitmap);
581                 GET_COLOR_CONFIG(HEADER::SUB_TITLE_EFFECT_NORMAL, subTitleEffectColor);
582                 GET_SHAPE_CONFIG(HEADER::TITLE_HEIGHT_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), topMargin);
583
584                 FloatRectangle subTitleEffectBounds(0.0f, topMargin, __pToolbar->GetBoundsF().width, __pToolbar->GetBoundsF().height - topMargin);
585
586                 Bitmap* pReColorSubTitleEffectBitmap = null;
587
588                 pReColorSubTitleEffectBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pSubTitleEffectBitmap, Color::GetColor(COLOR_ID_MAGENTA), subTitleEffectColor);
589
590                 if (pReColorSubTitleEffectBitmap)
591                 {
592                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReColorSubTitleEffectBitmap))
593                         {
594                                 pCanvas->DrawNinePatchedBitmap(subTitleEffectBounds, *pReColorSubTitleEffectBitmap);
595                         }
596                         else
597                         {
598                                 pCanvas->DrawBitmap(subTitleEffectBounds, *pReColorSubTitleEffectBitmap, FloatRectangle(0.0f, 0.0f, pReColorSubTitleEffectBitmap->GetWidthF(), pReColorSubTitleEffectBitmap->GetHeightF()));
599                         }
600                 }
601
602                 delete pReColorSubTitleEffectBitmap;
603         }
604
605         delete pCanvas;
606         delete pReplacementColorBackgroundBitmap;
607
608         return;
609 }
610
611 void
612 _ToolbarPresenter::DrawDescriptionText(void)
613 {
614         result r = E_SUCCESS;
615
616         float textAreaHeight = 0.0f;
617         float fontSize = 0.0f;
618         float titleIconWidth = 0.0f;
619
620         GET_SHAPE_CONFIG(HEADER::DESCRIPTION_TEXT_HEIGHT, __pToolbar->GetOrientation(), textAreaHeight);
621         GET_SHAPE_CONFIG(HEADER::DESCRIPTION_TEXT_FONT_SIZE, __pToolbar->GetOrientation(), fontSize);
622         GET_SHAPE_CONFIG(HEADER::ICON_WIDTH, __pToolbar->GetOrientation(), titleIconWidth);
623
624         __fontSize = fontSize;
625
626         __pTextFont = __pToolbar->GetFallbackFont();
627         r = GetLastResult();
628         SysTryReturnVoidResult(NID_UI_CTRL, __pTextFont, r, "[%s] Propagating.", GetErrorMessage(r));
629
630         if (__pToolbar->GetTitleIcon() != null)
631         {
632                 __descriptionRect.x = __toolbarUsableArea.x + titleIconWidth + __toolbarUsableArea.x;
633         }
634         else
635         {
636                 __descriptionRect.x = __toolbarUsableArea.x;
637         }
638
639         __descriptionRect.y = __titleRect.y + __titleRect.height;
640
641         if(__titleText.IsEmpty())
642         {
643                 __descriptionRect.width = __toolbarUsableArea.width;
644         }
645         else
646         {
647                 __descriptionRect.width = __titleRect.width;
648         }
649
650         __descriptionRect.height = textAreaHeight;
651
652         Canvas* pCanvas = __pToolbar->GetCanvasN();
653
654         if (__pDescriptionTextObject)
655         {
656                 __pDescriptionTextObject->SetFont(__pTextFont, 0, __pDescriptionTextObject->GetTextLength());
657                 __pDescriptionTextObject->SetForegroundColor(__pToolbar->GetDescriptionTextColor(), 0, __pDescriptionTextObject->GetTextLength());
658                 __pDescriptionTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
659                 __pDescriptionTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
660                 __pDescriptionTextObject->SetBounds(__descriptionRect);
661                 __pDescriptionTextObject->Compose();
662                 __pDescriptionTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
663         }
664
665         delete pCanvas;
666
667         return;
668 }
669
670 void
671 _ToolbarPresenter::DrawEditItem(const FloatPoint& point)
672 {
673         if (__pEditItem == null )
674         {
675                 return;
676         }
677
678         FloatPoint anchor = FloatPoint(0.0f, 0.0f);
679
680         anchor.x = point.x - (__pEditItem->GetSizeF().width / 2);
681         anchor.y = point.y - (__pEditItem->GetSizeF().height / 2);
682
683         __pEditItem->SetPosition(anchor);
684
685         __pToolbar->Invalidate(true);
686
687         return;
688 }
689
690 void
691 _ToolbarPresenter::DrawDividerLine(const FloatPoint& point, Canvas* pCanvas)
692 {
693         float dividerWidth = 0.0f;
694         float dividerHeight = 0.0f;
695         Color dividerLeftColor;
696         //Color dividerRightColor;
697
698         ToolbarStyle style = __pToolbar->GetStyle();
699
700         GET_SHAPE_CONFIG(HEADER::DIVIDER_WIDTH, __pToolbar->GetOrientation(), dividerWidth);
701
702         if (style == TOOLBAR_TAB_LARGE)
703         {
704                 GET_SHAPE_CONFIG(HEADER::TAB_LARGE_DIVIDER_HEIGHT, __pToolbar->GetOrientation(), dividerHeight);
705         }
706         else
707         {
708                 GET_SHAPE_CONFIG(HEADER::DIVIDER_HEIGHT, __pToolbar->GetOrientation(), dividerHeight);
709         }
710
711         if (__pToolbar->IsHeader() == true)
712         {
713                 if (!__pToolbar->IsTransparent())
714                 {
715                         GET_COLOR_CONFIG(HEADER::DIVIDER_LINE_LEFT_NORMAL, dividerLeftColor);
716                         //GET_COLOR_CONFIG(HEADER::DIVIDER_LINE_RIGHT_NORMAL, dividerRightColor);
717                 }
718                 else
719                 {
720                         GET_COLOR_CONFIG(HEADER::DIVIDER_LINE_LEFT_TRANSLUCENT_NORMAL, dividerLeftColor);
721                         //GET_COLOR_CONFIG(HEADER::DIVIDER_LINE_RIGHT_TRANSLUCENT_NORMAL, dividerRightColor);
722                 }
723         }
724         else
725         {
726                 if (!__pToolbar->IsTransparent())
727                 {
728                         GET_COLOR_CONFIG(FOOTER::DIVIDER_LINE_LEFT_NORMAL, dividerLeftColor);
729                         //GET_COLOR_CONFIG(FOOTER::DIVIDER_LINE_RIGHT_NORMAL, dividerRightColor);
730                 }
731                 else
732                 {
733                         GET_COLOR_CONFIG(FOOTER::DIVIDER_LINE_LEFT_TRANSLUCENT_NORMAL, dividerLeftColor);
734                         //GET_COLOR_CONFIG(FOOTER::DIVIDER_LINE_RIGHT_TRANSLUCENT_NORMAL, dividerRightColor);
735                 }
736         }
737
738         pCanvas->SetForegroundColor(dividerLeftColor);
739         pCanvas->SetLineWidth(dividerWidth);
740
741         pCanvas->DrawLine(FloatPoint(point.x, point.y), FloatPoint(point.x, point.y + dividerHeight));
742
743         return;
744 }
745
746 void
747 _ToolbarPresenter::DrawItems(void)
748 {
749         result r = E_SUCCESS;
750
751         Canvas* pCanvas = __pToolbar->GetCanvasN();
752
753         SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, E_INVALID_STATE, "[E_INVALID_STATE] System error occurred.");
754
755         ToolbarStyle style = __pToolbar->GetStyle();
756
757         FloatRectangle usableArea = __toolbarUsableArea;
758
759         Bitmap* pTitleIcon = __pToolbar->GetTitleIcon();
760
761         _Label* pTitleBadgeIcon = __pToolbar->GetTitleBadgeIcon();
762
763         float iconWidth = 0.0f;
764         float titleDisplayHeight = 0.0f;
765         float leftMargin = 0.0f;
766         float headerTopMargin = 0.0f;
767         float processingAnimationIconSize = 0.0f;
768         float processingAnimationIconGap = 0.0f;
769         float titleCharacterCount = 0.0f;
770         float titleBadgeIconGap = 0.0f;
771         float titleBadgeIconTopMargin = 0.0f;
772         float fontSize = 0.0f;
773         FloatDimension titleTextDimension(0.0f, 0.0f);
774         float totalWidth = 0.0f;
775         float titleHeight = 0.0f;
776
777         GET_SHAPE_CONFIG(HEADER::LEFT_MARGIN, __pToolbar->GetOrientation(), leftMargin);
778         GET_SHAPE_CONFIG(HEADER::PROCESSING_ANIMATION_ICON_SIZE, __pToolbar->GetOrientation(), processingAnimationIconSize);
779         GET_SHAPE_CONFIG(HEADER::PROCESSING_ANIMATION_ICON_GAP, __pToolbar->GetOrientation(), processingAnimationIconGap);
780
781         GET_SHAPE_CONFIG(HEADER::TITLE_BADGE_ICON_GAP, __pToolbar->GetOrientation(), titleBadgeIconGap);
782         GET_SHAPE_CONFIG(HEADER::TITLE_BADGE_TOP_MARGIN, __pToolbar->GetOrientation(), titleBadgeIconTopMargin);
783
784         if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
785         {
786                 GET_SHAPE_CONFIG(HEADER::TITLE_TOP_MARGIN_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), headerTopMargin);
787                 GET_SHAPE_CONFIG(HEADER::TITLE_DISPLAY_HEIGHT_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), titleDisplayHeight);
788         }
789         else
790         {
791                 GET_SHAPE_CONFIG(HEADER::TOP_MARGIN, __pToolbar->GetOrientation(), headerTopMargin);
792                 GET_SHAPE_CONFIG(HEADER::TITLE_DISPLAY_HEIGHT, __pToolbar->GetOrientation(), titleDisplayHeight);
793         }
794
795         GET_SHAPE_CONFIG(HEADER::ICON_WIDTH, __pToolbar->GetOrientation(), iconWidth);
796
797         if (!__titleText.IsEmpty())
798         {
799                 titleCharacterCount = __titleText.GetLength(); // alphabet count
800
801                 if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
802                 {
803                         r = GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE_WITH_SEGMENTED, __pToolbar->GetOrientation(), fontSize);
804                 }
805                 else if (style == TOOLBAR_TITLE && __pToolbar->GetDescriptionText() != L""
806                                 && __pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) == ANIMATION_STOPPED)
807                 {
808                         r = GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE_WITH_DESCRIPTION, __pToolbar->GetOrientation(), fontSize);
809                 }
810                 else
811                 {
812                         r = GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE, __pToolbar->GetOrientation(), fontSize);
813                 }
814
815                 if (IsFailed(r))
816                 {
817                         delete pCanvas;
818
819                         return;
820                 }
821
822                 __fontSize = fontSize;
823
824                 __pTitleTextFont = __pToolbar->GetFallbackFont();
825                 r = GetLastResult();
826                 SysTryReturnVoidResult(NID_UI_CTRL, __pTitleTextFont, r, "[%s] Propagating.", GetErrorMessage(r));
827
828                 __pTitleTextObject->SetFont(__pTitleTextFont, 0, __pTitleTextObject->GetTextLength());
829
830                 __pTitleTextFont->GetTextExtent(__titleText, titleCharacterCount, titleTextDimension);
831
832                 totalWidth = titleTextDimension.width; // pixel
833                 titleHeight = titleTextDimension.height; // pixel
834
835                 __titleRect.height = _FontImpl::GetInstance(*__pTitleTextFont)->GetLeadingF();
836
837                 if (pTitleIcon)
838                 {
839                         pTitleIcon->Scale(FloatDimension(iconWidth, iconWidth));
840                 }
841
842                 if (pTitleIcon)
843                 {
844                         totalWidth += (pTitleIcon->GetWidthF() + usableArea.x);
845                 }
846
847
848                 if (pTitleBadgeIcon)
849                 {
850                         totalWidth += pTitleBadgeIcon->GetBoundsF().width + titleBadgeIconGap;
851                 }
852                 else if ((__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE)) != ANIMATION_STOPPED)
853                 {
854                         totalWidth += processingAnimationIconSize + processingAnimationIconGap;
855                 }
856
857                 if (totalWidth > usableArea.width)
858                 {
859                         __titleRect.width = titleTextDimension.width - (totalWidth - usableArea.width);
860
861                         if (pTitleIcon)
862                         {
863                                 pCanvas->DrawBitmap(FloatPoint(usableArea.x, headerTopMargin + (titleDisplayHeight - pTitleIcon->GetHeightF()) / 2), *(pTitleIcon));
864
865                                 __titleRect.x = usableArea.x + pTitleIcon->GetWidthF() + usableArea.x;
866                                 __titleRect.y = headerTopMargin + (titleDisplayHeight - titleHeight) / 2;
867
868                                 if (__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
869                                 {
870                                         __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
871                                                         usableArea.x + (pTitleIcon->GetWidthF() + processingAnimationIconGap) + __titleRect.width + processingAnimationIconGap,
872                                                         headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
873                                 }
874
875                                 if (pTitleBadgeIcon)
876                                 {
877                                         pTitleBadgeIcon->SetPosition(FloatPoint(usableArea.x + (pTitleIcon->GetWidthF() + processingAnimationIconGap) + __titleRect.width + titleBadgeIconGap,
878                                                         titleBadgeIconTopMargin));
879                                 }
880                         }
881                         else
882                         {
883                                 __titleRect.x = usableArea.x;
884                                 __titleRect.y = headerTopMargin + (titleDisplayHeight - titleHeight) / 2;
885
886                                 if (__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
887                                 {
888                                         __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
889                                                         usableArea.x + __titleRect.width + processingAnimationIconGap,
890                                                         headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
891                                 }
892
893                                 if (pTitleBadgeIcon)
894                                 {
895                                         pTitleBadgeIcon->SetPosition(FloatPoint(usableArea.x + __titleRect.width + titleBadgeIconGap, titleBadgeIconTopMargin));
896                                 }
897                         }
898                 }
899                 else
900                 {
901                         __titleRect.width = usableArea.width;
902
903                         if (pTitleIcon)
904                         {
905                                 __titleRect.x = leftMargin + pTitleIcon->GetWidthF() + leftMargin;
906                                 __titleRect.y = headerTopMargin + (titleDisplayHeight - titleHeight) / 2;
907
908                                 if(__pTitleTextObject->GetAlignment() & TEXT_OBJECT_ALIGNMENT_CENTER)
909                                 {
910                                         leftMargin = (__titleRect.width - titleTextDimension.width) / 2 - leftMargin;
911                                 }
912                                 else if(__pTitleTextObject->GetAlignment() & TEXT_OBJECT_ALIGNMENT_RIGHT)
913                                 {
914                                         leftMargin = __titleRect.width - titleTextDimension.width - leftMargin * 3;
915                                 }
916
917                                 pCanvas->DrawBitmap(FloatPoint(leftMargin, headerTopMargin + (titleDisplayHeight - pTitleIcon->GetHeightF()) / 2), *(pTitleIcon));
918
919                                 if (__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
920                                 {
921                                         __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
922                                                         usableArea.x + (pTitleIcon->GetWidthF() + processingAnimationIconGap) + titleTextDimension.width + processingAnimationIconGap,
923                                                         headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
924                                 }
925
926                                 if (pTitleBadgeIcon)
927                                 {
928                                         pTitleBadgeIcon->SetPosition(FloatPoint(usableArea.x + (pTitleIcon->GetWidthF() + processingAnimationIconGap) + titleTextDimension.width + titleBadgeIconGap,
929                                                         titleBadgeIconTopMargin));
930                                 }
931
932                                 __titleRect.width -= (pTitleIcon->GetWidthF() + usableArea.x);
933                         }
934                         else
935                         {
936                                 __titleRect.x = leftMargin;
937                                 __titleRect.y = headerTopMargin + (titleDisplayHeight - titleHeight) / 2;
938
939                                 if (__pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
940                                 {
941                                         __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
942                                                         leftMargin + titleTextDimension.width + processingAnimationIconGap,
943                                                         headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
944                                 }
945
946                                 if (pTitleBadgeIcon)
947                                 {
948                                         pTitleBadgeIcon->SetPosition(FloatPoint(leftMargin + titleTextDimension.width + titleBadgeIconGap, titleBadgeIconTopMargin));
949                                 }
950                         }
951                 }
952         }
953         else // empty title
954         {
955                 if (pTitleIcon && __pToolbar->GetWaitingAnimationStatus(TOOLBAR_ANIMATION_POSITION_TITLE) != ANIMATION_STOPPED)
956                 {
957                         pTitleIcon->Scale(FloatDimension(iconWidth, iconWidth));
958
959                         if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_CENTER)
960                         {
961                                 leftMargin = (leftMargin + usableArea.width - (pTitleIcon->GetWidthF() + processingAnimationIconGap + processingAnimationIconSize)) / 2;
962                         }
963                         else if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_RIGHT)
964                         {
965                                 leftMargin = leftMargin + usableArea.width - (pTitleIcon->GetWidthF() + processingAnimationIconGap + processingAnimationIconSize);
966                         }
967
968                         pCanvas->DrawBitmap(FloatPoint(leftMargin, headerTopMargin + (titleDisplayHeight - pTitleIcon->GetHeightF()) / 2), *(pTitleIcon));
969
970                         __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
971                                         leftMargin + processingAnimationIconGap + processingAnimationIconSize,
972                                         headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
973
974                         if (pTitleBadgeIcon)
975                         {
976                                 pTitleBadgeIcon->SetPosition(FloatPoint(leftMargin + processingAnimationIconGap + titleBadgeIconGap, titleBadgeIconTopMargin));
977                         }
978                 }
979                 else if (pTitleIcon)
980                 {
981                         pTitleIcon->Scale(FloatDimension(iconWidth, iconWidth));
982
983                         if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_CENTER)
984                         {
985                                 leftMargin = usableArea.width / 2;
986                         }
987                         else if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_RIGHT)
988                         {
989                                 leftMargin = usableArea.width - pTitleIcon->GetWidthF();
990                         }
991
992                         pCanvas->DrawBitmap(FloatPoint(leftMargin, headerTopMargin + (titleDisplayHeight - pTitleIcon->GetHeightF()) / 2), *(pTitleIcon));
993                 }
994                 else
995                 {
996                         if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_CENTER)
997                         {
998                                 leftMargin = (usableArea.width - (processingAnimationIconGap + processingAnimationIconSize))/ 2;
999                         }
1000                         else if(__pToolbar->GetTitleTextHorizontalAlignment() == ALIGNMENT_RIGHT)
1001                         {
1002                                 leftMargin = usableArea.width - (processingAnimationIconGap + processingAnimationIconSize);
1003                         }
1004
1005                         __pToolbar->SetWaitingAnimationPosition(TOOLBAR_ANIMATION_POSITION_TITLE,
1006                                         leftMargin, headerTopMargin + (titleDisplayHeight - processingAnimationIconSize) / 2);
1007
1008                         if (pTitleBadgeIcon)
1009                         {
1010                                 pTitleBadgeIcon->SetPosition(FloatPoint(leftMargin, titleBadgeIconTopMargin));
1011                         }
1012                 }
1013         }
1014
1015         delete pCanvas;
1016
1017         return;
1018 }
1019
1020 result
1021 _ToolbarPresenter::DrawTitleText(Canvas* pCanvas)
1022 {
1023         TimerForTitleSlideInit();
1024
1025         if (__titleText.IsEmpty())
1026         {
1027                 return E_SUCCESS;
1028         }
1029
1030         __pTitleTextObject->SetForegroundColor(__pToolbar->GetTitleTextColor(), 0, __pTitleTextObject->GetTextLength());
1031         __pTitleTextObject->SetBounds(__titleRect);
1032         //__pTitleTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
1033         __pTitleTextObject->Compose();
1034
1035         if (__pTitleTextObject->IsActionOn() == true)
1036         {
1037                 __pTitleTextObject->DrawWithOffset(*_CanvasImpl::GetInstance(*pCanvas));
1038
1039                 DrawTitleTextDimBitmap();
1040
1041                 TimerForTitleSlideStart();
1042         }
1043         else
1044         {
1045                 __pTitleTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
1046         }
1047
1048         return E_SUCCESS;
1049 }
1050
1051 int
1052 _ToolbarPresenter::GetSelectedItemIndex(void) const
1053 {
1054         return __pToolbarModel->GetSelectedItemIndex();
1055 }
1056
1057 bool
1058 _ToolbarPresenter::IsInitialDraw(void) const
1059 {
1060         return __initialDraw;
1061 }
1062
1063 bool
1064 _ToolbarPresenter::IsTabEditModeEnabled(void) const
1065 {
1066         return __tabEditEnabled;
1067 }
1068
1069 result
1070 _ToolbarPresenter::SetDescriptionText(const String& description)
1071 {
1072         result r = E_SUCCESS;
1073
1074         float length = description.GetLength();
1075         float fontSize = 0.0f;
1076
1077         wchar_t* tempString = const_cast<wchar_t*>(description.GetPointer());
1078
1079         // description text
1080         if (__pDescriptionTextObject != null)
1081         {
1082                 delete __pDescriptionTextObject;
1083                 __pDescriptionTextObject = null;
1084         }
1085
1086         __pDescriptionTextObject = new (std::nothrow) TextObject();
1087
1088         if (__pDescriptionTextObject == null)
1089         {
1090                 return E_OUT_OF_MEMORY;
1091         }
1092         __pDescriptionTextObject->Construct();
1093         TextSimple* pSimpleText = new (std::nothrow) TextSimple(tempString, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1094         __pDescriptionTextObject->AppendElement(*pSimpleText);
1095         __pDescriptionTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1096         __pDescriptionTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER);
1097
1098         GET_SHAPE_CONFIG(HEADER::DESCRIPTION_TEXT_FONT_SIZE, __pToolbar->GetOrientation(), fontSize);
1099
1100         __fontSize = fontSize;
1101
1102         __pTextFont = __pToolbar->GetFallbackFont();
1103         r = GetLastResult();
1104         SysTryReturn(NID_UI_CTRL, __pTextFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
1105
1106         __pDescriptionTextObject->SetFont(__pTextFont, 0, __pDescriptionTextObject->GetTextLength());
1107
1108         return r;
1109 }
1110
1111 result
1112 _ToolbarPresenter::SetItemSelected(int itemIndex, bool adjust)
1113 {
1114         if (adjust == true)
1115         {
1116                 ToolbarStyle style = __pToolbar->GetStyle();
1117
1118                 if ((style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE) && __pToolbar->GetItemCount() > SEGMENTED_ITEM_MAX)
1119                 {
1120                         if (itemIndex <= __pToolbar->GetItemCount() - SEGMENTED_ITEM_MAX)
1121                         {
1122                                 SetItemFit(itemIndex);
1123                         }
1124                         else
1125                         {
1126                                 SetItemFit(__pToolbar->GetItemCount() - SEGMENTED_ITEM_MAX);
1127                         }
1128                 }
1129         }
1130
1131         return __pToolbarModel->SetSelectedItemIndex(itemIndex);
1132 }
1133
1134 result
1135 _ToolbarPresenter::SetInitialDrawState(bool state)
1136 {
1137         //DrawBackground(); // remove since 2.1
1138         __initialDraw = state;
1139         __titleText = L"";
1140         __titlePressed = false;
1141         __titleSliding = false;
1142         __tabEditEnabled = false;
1143
1144         __firstLoadedItemIndex = 0;
1145         __lastLoadedItemIndex = 0;
1146
1147         return E_SUCCESS;
1148 }
1149
1150 result
1151 _ToolbarPresenter::SetTabEditModeEnabled(bool enable)
1152 {
1153         __tabEditEnabled = enable;
1154
1155         return E_SUCCESS;
1156 }
1157
1158 result
1159 _ToolbarPresenter::SetTitleText(const String& title, HorizontalAlignment alignment)
1160 {
1161         result r = E_SUCCESS;
1162
1163         float length = title.GetLength();
1164
1165         __titleText = String(title);
1166         wchar_t* tempString = const_cast<wchar_t*>(__titleText.GetPointer());
1167
1168         // title text
1169         if (__pTitleTextObject != null)
1170         {
1171                 delete __pTitleTextObject;
1172                 __pTitleTextObject = null;
1173         }
1174
1175         __pTitleTextObject = new (std::nothrow) TextObject();
1176
1177         if (__pTitleTextObject == null)
1178         {
1179                 return E_OUT_OF_MEMORY;
1180         }
1181         __pTitleTextObject->Construct();
1182         __pTitleTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
1183         TextSimple* pSimpleText = new (std::nothrow) TextSimple(tempString, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1184         __pTitleTextObject->AppendElement(*pSimpleText);
1185
1186         __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1187
1188         __titleSliding = false;
1189
1190         switch (alignment)
1191         {
1192                 case ALIGNMENT_LEFT:
1193                         __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
1194                         break;
1195                 case ALIGNMENT_CENTER:
1196                         __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER);
1197                         break;
1198                 case ALIGNMENT_RIGHT:
1199                         __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_RIGHT);
1200                         break;
1201                 default:
1202                         __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
1203                         break;
1204         }
1205
1206         float fontSize = 0.0f;
1207
1208         r = GET_SHAPE_CONFIG(HEADER::TITLE_FONT_SIZE, __pToolbar->GetOrientation(), fontSize);
1209
1210         __fontSize = fontSize;
1211
1212         __pTitleTextFont = __pToolbar->GetFallbackFont();
1213         r = GetLastResult();
1214         SysTryReturn(NID_UI_CTRL, __pTitleTextFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
1215
1216         __pTitleTextObject->SetFont(__pTitleTextFont, 0, __pTitleTextObject->GetTextLength());
1217
1218         //__pTitleTextObject->Compose();
1219
1220         return r;
1221 }
1222
1223 result
1224 _ToolbarPresenter::SetUsableAreaBounds(const FloatRectangle& rect)
1225 {
1226         __toolbarUsableArea = rect;
1227
1228         return E_SUCCESS;
1229 }
1230
1231 bool
1232 _ToolbarPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1233 {
1234         ResetFlickAnimationTimer();
1235
1236         SetFirstLoadedItemIndex();
1237         SetLastLoadedItemIndex();
1238
1239         __touchInitiatedInToolbar = true;
1240
1241         __currentTouchPosition = touchinfo.GetCurrentPosition();
1242
1243         ToolbarStyle style = __pToolbar->GetStyle();
1244
1245         if (__titleRect.Contains(__currentTouchPosition)
1246                         && (style == TOOLBAR_TITLE || style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE))
1247         {
1248                 __titlePressed = true;
1249         }
1250         else
1251         {
1252                 __titlePressed = false;
1253         }
1254
1255         __pressedItemIndex = __pToolbar->GetItemIndexFromPosition(__currentTouchPosition);
1256
1257         if (__pressedItemIndex == -1)
1258         {
1259                 _Label* pLabel = dynamic_cast<_Label*>(const_cast<_Control*>(&source));
1260
1261                 if (pLabel != null)
1262                 {
1263                         if (__pToolbar->GetButton(LEFT_BUTTON) != null && __pToolbar->GetButton(LEFT_BUTTON)->GetButtonStatus() != _BUTTON_STATUS_DISABLED)
1264                         {
1265                                 _Label* pTempBadgeIcon = dynamic_cast<_Label*>(__pToolbar->GetButton(LEFT_BUTTON)->GetChild(0));
1266
1267                                 if (pLabel == pTempBadgeIcon)
1268                                 {
1269                                         __pToolbar->GetButton(LEFT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_PRESSED, false);
1270                                 }
1271                         }
1272
1273                         if (__pToolbar->GetButton(RIGHT_BUTTON) != null && __pToolbar->GetButton(RIGHT_BUTTON)->GetButtonStatus() != _BUTTON_STATUS_DISABLED)
1274                         {
1275                                 _Label* pTempBadgeIcon = dynamic_cast<_Label*>(__pToolbar->GetButton(RIGHT_BUTTON)->GetChild(0));
1276
1277                                 if (pLabel == pTempBadgeIcon)
1278                                 {
1279                                         __pToolbar->GetButton(RIGHT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_PRESSED, false);
1280                                 }
1281                         }
1282                 }
1283         }
1284         else
1285         {
1286                 _Button* pPressedButton = __pToolbar->GetItem(__pressedItemIndex);
1287
1288                 __initialPressesItemStatus = pPressedButton->GetButtonStatus();
1289
1290                 if (__initialPressesItemStatus == _BUTTON_STATUS_DISABLED)
1291                 {
1292                         return true;
1293                 }
1294
1295                 pPressedButton->SetButtonStatus(_BUTTON_STATUS_PRESSED);
1296         }
1297
1298         __pToolbar->Invalidate(true);
1299
1300         return true;
1301 }
1302
1303 bool
1304 _ToolbarPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1305 {
1306         if (!__touchInitiatedInToolbar)
1307         {
1308                 return false;
1309         }
1310
1311         FloatPoint touchPoint = touchinfo.GetCurrentPosition();
1312
1313         if (__titlePressed && __titleRect.Contains(touchPoint))
1314         {
1315                 if (__titleSliding == true)
1316                 {
1317                         __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1318                         __pTitleTextObject->Compose();
1319
1320                         __titleSliding = false;
1321                 }
1322                 else
1323                 {
1324                         __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT);
1325                         __pTitleTextObject->Compose();
1326
1327                         __titleSliding = true;
1328
1329                         TimerForTitleSlideStart();
1330                 }
1331         }
1332
1333         SetFirstLoadedItemIndex();
1334         SetLastLoadedItemIndex();
1335
1336         ToolbarStyle style = __pToolbar->GetStyle();
1337
1338         __touchInitiatedInToolbar = false;
1339
1340         int releasedItemIndex = __pToolbar->GetItemIndexFromPosition(touchPoint);
1341         float tabLeftMargin = 0.0f;
1342
1343         GET_SHAPE_CONFIG(HEADER::TAB_LEFT_MARGIN, __pToolbar->GetOrientation(), tabLeftMargin);
1344
1345         if ((style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE) && __beingEdited == true)
1346         {
1347                 __beingEdited = false;
1348
1349                 if (releasedItemIndex == -1)
1350                 {
1351                         if (__pEditItem)
1352                         {
1353                                 __pToolbar->DetachChild(*__pEditItem);
1354
1355                                 delete __pEditItem;
1356                                 __pEditItem = null;
1357                         }
1358
1359                         if (__pressedItemIndex != -1)
1360                         {
1361                                 __pToolbar->GetItem(__pressedItemIndex)->SetButtonStatus(__initialPressesItemStatus);
1362                         }
1363                 }
1364                 else
1365                 {
1366                         __pToolbar->MoveItem(__editItemIndex, releasedItemIndex);
1367
1368                         AdjustItemPositionX(-__pToolbar->GetItem(__firstLoadedItemIndex)->GetBoundsF().x + tabLeftMargin); // move auto focus
1369
1370                         if (__pEditItem)
1371                         {
1372                                 __pToolbar->DetachChild(*__pEditItem);
1373
1374                                 delete __pEditItem;
1375                                 __pEditItem = null;
1376                         }
1377                 }
1378         }
1379         else
1380         {
1381                 if ((style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE)
1382                                 && __pToolbar->GetItemCount() > SEGMENTED_ITEM_MAX)
1383                 {
1384                         if (__pressedItemIndex != -1)
1385                         {
1386                                 if (releasedItemIndex == __pressedItemIndex)
1387                                 {
1388                                         if (__initialPressesItemStatus != _BUTTON_STATUS_DISABLED && __tabMoved != true)
1389                                         {
1390                                                 __pToolbar->SetItemSelected(releasedItemIndex, true, false);
1391                                         }
1392                                         else
1393                                         {
1394                                                 __pToolbar->GetItem(__pressedItemIndex)->SetButtonStatus(__initialPressesItemStatus, false);
1395                                         }
1396                                 }
1397                                 else
1398                                 {
1399                                         __pToolbar->GetItem(__pressedItemIndex)->SetButtonStatus(__initialPressesItemStatus, false);
1400                                 }
1401                         }
1402                 }
1403                 else
1404                 {
1405                         if (__pressedItemIndex != -1 && (releasedItemIndex != __pressedItemIndex))
1406                         {
1407                                 __pToolbar->GetItem(__pressedItemIndex)->SetButtonStatus(__initialPressesItemStatus, false);
1408                         }
1409                         else
1410                         {
1411                                 if (__pressedItemIndex != -1 && __initialPressesItemStatus != _BUTTON_STATUS_DISABLED)
1412                                 {
1413                                         if (style == TOOLBAR_HEADER_SEGMENTED || style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE
1414                                                         || style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_SEGMENTED || style == TOOLBAR_TAB_LARGE)
1415                                         {
1416                                                 __pToolbar->SetItemSelected(releasedItemIndex, true, false);
1417                                         }
1418                                         else
1419                                         {
1420                                                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pToolbar->GetItem(releasedItemIndex));
1421                                                 __pToolbar->GetItem(releasedItemIndex)->SetButtonStatus(_BUTTON_STATUS_SELECTED, true);
1422                                                 __pToolbar->GetItem(releasedItemIndex)->SetButtonStatus(_BUTTON_STATUS_NORMAL, false);
1423                                         }
1424                                 }
1425                                 else
1426                                 {
1427                                         _Label* pLabel = dynamic_cast<_Label*>(const_cast<_Control*>(&source));
1428
1429                                         if (pLabel != null)
1430                                         {
1431                                                 if (__pToolbar->GetButton(LEFT_BUTTON) != null && __pToolbar->GetButton(LEFT_BUTTON)->GetButtonStatus() != _BUTTON_STATUS_DISABLED)
1432                                                 {
1433                                                         _Label* pTempBadgeIcon = dynamic_cast<_Label*>(__pToolbar->GetButton(LEFT_BUTTON)->GetChild(0));
1434
1435                                                         if (pLabel == pTempBadgeIcon)
1436                                                         {
1437                                                                 FloatRectangle buttonItemBounds = __pToolbar->GetButton(LEFT_BUTTON)->GetBoundsF();
1438
1439                                                                 if (buttonItemBounds.Contains(touchPoint))
1440                                                                 {
1441                                                                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pToolbar->GetButton(LEFT_BUTTON));
1442                                                                         __pToolbar->GetButton(LEFT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_SELECTED, true);
1443                                                                 }
1444
1445                                                                 __pToolbar->GetButton(LEFT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_NORMAL, false);
1446                                                         }
1447                                                 }
1448
1449                                                 if (__pToolbar->GetButton(RIGHT_BUTTON) != null && __pToolbar->GetButton(RIGHT_BUTTON)->GetButtonStatus() != _BUTTON_STATUS_DISABLED)
1450                                                 {
1451                                                         _Label* pTempBadgeIcon = dynamic_cast<_Label*>(__pToolbar->GetButton(RIGHT_BUTTON)->GetChild(0));
1452
1453                                                         if (pLabel == pTempBadgeIcon)
1454                                                         {
1455                                                                 FloatRectangle buttonItemBounds = __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF();
1456
1457                                                                 if (buttonItemBounds.Contains(touchPoint))
1458                                                                 {
1459                                                                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pToolbar->GetButton(RIGHT_BUTTON));
1460                                                                         __pToolbar->GetButton(RIGHT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_SELECTED, true);
1461                                                                 }
1462
1463                                                                 __pToolbar->GetButton(RIGHT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_NORMAL, false);
1464                                                         }
1465                                                 }
1466                                         }
1467                                 }
1468
1469                                 __pToolbar->Invalidate(true);
1470
1471                                 return true;
1472                         }
1473                 }
1474         }
1475
1476         __tabMoved = false;
1477
1478         // Restore status of other buttons to _BUTTON_STATUS_NORMAL             // this can be removed
1479         int itemCount = __pToolbar->GetItemCount();
1480
1481         for (int j = 0; j < itemCount; j++)
1482         {
1483                 if (__pToolbar->GetItem(j) != null && __pToolbar->GetItem(j)->GetButtonStatus() == _BUTTON_STATUS_PRESSED)
1484                 {
1485                         __pToolbar->GetItem(j)->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1486                 }
1487         }
1488
1489         // Update children
1490         __pToolbar->Invalidate(true);
1491
1492         return true;
1493 }
1494
1495 bool
1496 _ToolbarPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1497 {
1498         if (!__touchInitiatedInToolbar)
1499         {
1500                 return false;
1501         }
1502
1503         SetFirstLoadedItemIndex();
1504         SetLastLoadedItemIndex();
1505
1506         ToolbarStyle style = __pToolbar->GetStyle();
1507         FloatPoint touchPoint = touchinfo.GetCurrentPosition();
1508
1509         if (__pressedItemIndex == -1)
1510         {
1511                 _Label* pLabel = dynamic_cast<_Label*>(const_cast<_Control*>(&source));
1512
1513                 if (pLabel != null)
1514                 {
1515                         if (__pToolbar->GetButton(LEFT_BUTTON) != null && __pToolbar->GetButton(LEFT_BUTTON)->GetButtonStatus() != _BUTTON_STATUS_DISABLED)
1516                         {
1517                                 _Label* pTempBadgeIcon = dynamic_cast<_Label*>(__pToolbar->GetButton(LEFT_BUTTON)->GetChild(0));
1518
1519                                 if (pLabel == pTempBadgeIcon)
1520                                 {
1521                                         FloatRectangle buttonItemBounds = __pToolbar->GetButton(LEFT_BUTTON)->GetBoundsF();
1522
1523                                         if (buttonItemBounds.Contains(touchPoint))
1524                                         {
1525                                                 __pToolbar->GetButton(LEFT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_PRESSED);
1526                                         }
1527                                         else
1528                                         {
1529                                                 __pToolbar->GetButton(LEFT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1530                                         }
1531                                 }
1532                         }
1533
1534                         if (__pToolbar->GetButton(RIGHT_BUTTON) != null && __pToolbar->GetButton(RIGHT_BUTTON)->GetButtonStatus() != _BUTTON_STATUS_DISABLED)
1535                         {
1536                                 _Label* pTempBadgeIcon = dynamic_cast<_Label*>(__pToolbar->GetButton(RIGHT_BUTTON)->GetChild(0));
1537
1538                                 if (pLabel == pTempBadgeIcon)
1539                                 {
1540                                         FloatRectangle buttonItemBounds = __pToolbar->GetButton(RIGHT_BUTTON)->GetBoundsF();
1541
1542                                         if (buttonItemBounds.Contains(touchPoint))
1543                                         {
1544                                                 __pToolbar->GetButton(RIGHT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_PRESSED);
1545                                         }
1546                                         else
1547                                         {
1548                                                 __pToolbar->GetButton(RIGHT_BUTTON)->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1549                                         }
1550                                 }
1551                         }
1552                 }
1553
1554                 __pToolbar->Invalidate(true);
1555
1556                 return true;
1557         }
1558
1559         _Button* pCurrentButton = __pToolbar->GetItem(__pressedItemIndex);
1560
1561         if (pCurrentButton == null)
1562         {
1563                 return true;
1564         }
1565
1566         FloatRectangle itemBounds = pCurrentButton->GetBoundsF();
1567
1568         if ((style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE) && __pToolbar->GetItemCount() > SEGMENTED_ITEM_MAX)
1569         {
1570                 if (itemBounds.Contains(touchPoint))
1571                 {
1572                         __tabMoved = true;
1573                 }
1574         }
1575
1576         if ((style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE) && __beingEdited == true)
1577         {
1578                 DrawEditItem(touchinfo.GetCurrentPosition());
1579         }
1580         else
1581         {
1582                 if (__tabMoved)
1583                 {
1584                         pCurrentButton->SetButtonStatus(__initialPressesItemStatus, false);
1585                 }
1586                 else
1587                 {
1588                         if (__initialPressesItemStatus == _BUTTON_STATUS_DISABLED)
1589                         {
1590                                 return false;
1591                         }
1592
1593                         if (itemBounds.Contains(touchPoint))
1594                         {
1595                                 pCurrentButton->SetButtonStatus(_BUTTON_STATUS_PRESSED);
1596                         }
1597                         else
1598                         {
1599                                 pCurrentButton->SetButtonStatus(__initialPressesItemStatus, false);
1600                         }
1601                 }
1602
1603                 pCurrentButton->Invalidate(false);
1604         }
1605
1606         if (__tabMoved)
1607         {
1608                 float distance = (touchinfo.GetCurrentPosition()).x - __currentTouchPosition.x;
1609                 float sideMargin = 0.0f;
1610
1611                 GET_SHAPE_CONFIG(HEADER::TAB_LEFT_MARGIN, __pToolbar->GetOrientation(), sideMargin);
1612
1613                 FloatRectangle clientBounds = __pToolbar->GetBoundsF();
1614
1615                 __portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
1616                 __landscapeSize = FloatDimension(__portraitSize.height, __portraitSize.width);
1617
1618                 if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
1619                 {
1620                         if (clientBounds.width > __portraitSize.width)
1621                         {
1622                                 clientBounds.width = __portraitSize.width;
1623                         }
1624                 }
1625                 else
1626                 {
1627                         if (clientBounds.width > __landscapeSize.width)
1628                         {
1629                                 clientBounds.width = __landscapeSize.width;
1630                         }
1631                 }
1632
1633                 __currentTouchPosition = touchinfo.GetCurrentPosition();
1634
1635                 _Button* pItem = null;
1636                 FloatRectangle itemBounds;
1637                 int itemCount = __pToolbar->GetItemCount();
1638
1639                 if (distance > 0) // right move
1640                 {
1641                         pItem = __pToolbar->GetItem(0);
1642                         if (pItem == null)
1643                         {
1644                                 return true;
1645                         }
1646
1647                         itemBounds = pItem->GetBoundsF();
1648
1649                         if (itemBounds.x + distance >= sideMargin && !__beingEdited)
1650                         {
1651                                 distance = sideMargin - itemBounds.x;
1652                         }
1653                 }
1654                 else if (distance < 0)
1655                 {
1656                         pItem = __pToolbar->GetItem(itemCount - 1);
1657
1658                         if (pItem == null)
1659                         {
1660                                 return true;
1661                         }
1662
1663                         itemBounds = pItem->GetBoundsF();
1664
1665                         if (itemBounds.x + itemBounds.width + distance <= clientBounds.width - sideMargin && !__beingEdited)
1666                         {
1667                                 distance = (clientBounds.width - sideMargin) - (itemBounds.x + itemBounds.width);
1668                         }
1669                 }
1670                 if (__beingEdited)
1671                 {
1672                         float tabLeftMargin = 0.0f;
1673
1674                         GET_SHAPE_CONFIG(HEADER::TAB_LEFT_MARGIN, __pToolbar->GetOrientation(), tabLeftMargin);
1675
1676                         if (distance > 0) // right move
1677                         {
1678                                 __tabSlideRight = false;
1679
1680                                 if (__pToolbar->GetItem(__lastLoadedItemIndex - 1)->GetBoundsF().x <= __pEditItem->GetBoundsF().x)
1681                                 {
1682                                         __tabSlideLeft = true;
1683                                 }
1684
1685                                 if (__tabSlideLeft && __pToolbar->GetItem(itemCount-1)->GetBoundsF().x + __pToolbar->GetItem(itemCount-1)->GetBoundsF().width > clientBounds.width - tabLeftMargin)
1686                                 {
1687                                         AdjustItemPositionX(-distance * 5); // move auto focus
1688                                 }
1689                         }
1690                         else if (distance < 0)
1691                         {
1692                                 __tabSlideLeft = false;
1693
1694                                 if (__pToolbar->GetItem(__firstLoadedItemIndex + 1)->GetBoundsF().x >= __pEditItem->GetBoundsF().x)
1695                                 {
1696                                         __tabSlideRight = true;
1697                                 }
1698
1699                                 if (__tabSlideRight     && __pToolbar->GetItem(0)->GetBoundsF().x < tabLeftMargin)
1700                                 {
1701                                         AdjustItemPositionX(-distance * 5); // move auto focus
1702                                 }
1703                         }
1704                 }
1705                 else
1706                 {
1707                         AdjustItemPositionX(distance);
1708                 }
1709
1710                 Draw();
1711         }
1712
1713         return false;
1714 }
1715
1716 bool
1717 _ToolbarPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1718 {
1719         __touchInitiatedInToolbar = false;
1720         __beingEdited = false;
1721
1722         // Restore status of other buttons to _BUTTON_STATUS_NORMAL             // this can be removed
1723         int itemCount = __pToolbar->GetItemCount();
1724
1725         for (int i = 0; i < itemCount; i++)
1726         {
1727                 if (__pToolbar->GetItem(i) != null && __pToolbar->GetItem(i)->GetButtonStatus() == _BUTTON_STATUS_PRESSED)
1728                 {
1729                         __pToolbar->GetItem(i)->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1730                 }
1731         }
1732
1733         if (__pEditItem)
1734         {
1735                 __pToolbar->DetachChild(*__pEditItem);
1736
1737                 delete __pEditItem;
1738                 __pEditItem = null;
1739         }
1740
1741         // Update children
1742         __pToolbar->Invalidate(true);
1743
1744         return true;
1745 }
1746
1747 void
1748 _ToolbarPresenter::OnChangeLayout(Tizen::Ui::_ControlOrientation orientation)
1749 {
1750         ResetFlickAnimationTimer();
1751
1752         return;
1753 }
1754
1755 bool
1756 _ToolbarPresenter::OnLongPressGestureDetected(void)
1757 {
1758         if (__pToolbar->IsTabEditModeEnabled() == true)
1759         {
1760                 int longPressedItemIndex = __pToolbar->GetItemIndexFromPosition(__currentTouchPosition);
1761
1762                 if (longPressedItemIndex == -1)
1763                 {
1764                         return false;
1765                 }
1766
1767                 _Button* pButton = null;
1768                 pButton = __pToolbar->GetItem(longPressedItemIndex);
1769                 SysTryReturn(NID_UI_CTRL, pButton, true, E_INVALID_STATE, "[E_INVALID_STATE] Unable to retrieve a button");
1770
1771                 if (pButton->GetButtonStatus() == _BUTTON_STATUS_DISABLED)
1772                 {
1773                         return false;
1774                 }
1775
1776                 __editItemIndex = longPressedItemIndex;
1777                 __beingEdited = true;
1778
1779                 pButton->SetButtonStatus(_BUTTON_STATUS_NORMAL);
1780
1781                 FloatRectangle itemBounds = pButton->GetBoundsF();
1782
1783                 if (__pEditItem)
1784                 {
1785                         __pToolbar->DetachChild(*__pEditItem);
1786
1787                         delete __pEditItem;
1788                         __pEditItem = null;
1789                 }
1790
1791                 __pEditItem = _Label::CreateLabelN();
1792                 SysTryCatch(NID_UI_CTRL, __pEditItem, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1793
1794                 Canvas* pCanvas = pButton->GetCanvasN();
1795                 SysTryCatch(NID_UI_CTRL, pCanvas, , E_INVALID_STATE, "[E_INVALID_STATE] Unable to retrieve a Canvas.");
1796
1797                 Bitmap* pEditItemBitmap = new (std::nothrow) Bitmap();
1798                 result r = pEditItemBitmap->Construct(*pCanvas, FloatRectangle(0.0f, 0.0f, itemBounds.width, itemBounds.height));
1799
1800                 if (IsFailed(r))
1801                 {
1802                         delete pEditItemBitmap;
1803                         pEditItemBitmap = null;
1804
1805                         delete pCanvas;
1806
1807                         goto CATCH;
1808                 }
1809
1810                 __pEditItem->SetBounds(itemBounds);
1811                 __pEditItem->SetBackgroundBitmap(*pEditItemBitmap);
1812
1813                 delete pCanvas;
1814                 delete pEditItemBitmap;
1815
1816                 __pToolbar->AttachChild(*__pEditItem);
1817                 __pToolbar->SetChildAlwaysOnTop(*__pEditItem);
1818
1819                 __pToolbar->Draw();
1820         }
1821
1822     return true;
1823
1824 CATCH:
1825         if (__pEditItem)
1826         {
1827                 delete __pEditItem;
1828                 __pEditItem = null;
1829         }
1830
1831         return true;
1832 }
1833
1834 bool
1835 _ToolbarPresenter::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
1836 {
1837         ToolbarStyle style = __pToolbar->GetStyle();
1838
1839         if (!(style == TOOLBAR_TAB || style == TOOLBAR_TAB_WITH_TITLE || style == TOOLBAR_TAB_LARGE) || __pToolbar->GetItemCount() <= SEGMENTED_ITEM_MAX || __beingEdited == true || __tabMoved == false)
1840         {
1841                 return true;
1842         }
1843
1844         if (gesture.GetDirection() != _FLICK_DIRECTION_RIGHT && gesture.GetDirection() != _FLICK_DIRECTION_LEFT)
1845         {
1846                 return false;
1847         }
1848
1849         float distanceX = 0.0f;
1850         float distanceY = 0.0f;
1851         float xPosition = 0.0f;
1852         float itemsBeyondScreen = 0.0f;
1853
1854         gesture.GetDistance(distanceX, distanceY);
1855         SetFirstLoadedItemIndex();
1856         SetLastLoadedItemIndex();
1857         int itemCount = __pToolbar->GetItemCount();
1858         float itemWidth = __pToolbar->GetItem(0)->GetBoundsF().width;
1859
1860         if (distanceX < 0)  //left
1861         {
1862                 itemsBeyondScreen = (itemCount - 1) - __lastLoadedItemIndex;
1863                 xPosition = __pToolbar->GetItem(__lastLoadedItemIndex)->GetBoundsF().x;
1864                 if (xPosition < (3 * itemWidth))
1865                 {
1866                         __flickDistance = xPosition - (4 * itemWidth);
1867                 }
1868         }
1869         else //Right
1870         {
1871                 itemsBeyondScreen = __firstLoadedItemIndex;
1872                 xPosition = __pToolbar->GetItem(__firstLoadedItemIndex)->GetBoundsF().x;
1873                 if (xPosition < 0)
1874                 {
1875                         __flickDistance = -xPosition;
1876                 }
1877
1878         }
1879
1880         int itemMaxCount = 4;
1881
1882         if (itemsBeyondScreen >= (itemMaxCount - 1))
1883         {
1884                 __flickDistance = (3 * itemWidth);
1885         }
1886         else
1887         {
1888                 __flickDistance = (itemsBeyondScreen * itemWidth);
1889         }
1890
1891         if (distanceX < 0) //Left flick
1892         {
1893                 __flickMove = 0.006f;
1894                 __flickFlag = 0;
1895         }
1896         else if (distanceX > 0) //Right flick
1897         {
1898                 __flickMove = 0.006f;
1899                 __flickDistance = -(__flickDistance);
1900                 __flickFlag = 0;
1901         }
1902         else
1903         {
1904                 __flickMove = 0.0f;
1905                 __flickDistance = 0.0f;
1906                 __flickFlag = 0;
1907                 __moveDistance = 0.0f;
1908         }
1909
1910         StartFlickAnimationTimer();
1911
1912         return true;
1913 }
1914
1915 void
1916 _ToolbarPresenter::OnTimerExpired(Timer& timer)
1917 {
1918         Timer* onTimer = &timer;
1919
1920         if (onTimer == __pTitleSlideTimer)
1921         {
1922                 TimerForTitleSlideTimeout();
1923         }
1924
1925         if (onTimer == __pFlickAnimationTimer)
1926         {
1927                 StartFlickAnimation();
1928         }
1929
1930         return;
1931 }
1932
1933 void
1934 _ToolbarPresenter::OnDrawFocus(void)
1935 {
1936         return;
1937 }
1938
1939 void
1940 _ToolbarPresenter::OnChildControlFocusMoved(const _Control& control)
1941 {
1942         return;
1943 }
1944
1945 bool
1946 _ToolbarPresenter::IsChildControlFocusManage(void) const
1947 {
1948         return true;
1949 }
1950
1951 void
1952 _ToolbarPresenter::OnFocusableStateChanged(bool focusalbeState)
1953 {
1954         return;
1955 }
1956
1957 void
1958 _ToolbarPresenter::OnFocusModeStateChanged(void)
1959 {
1960         return;
1961 }
1962
1963 bool
1964 _ToolbarPresenter::OnFocusGained(const _Control& source)
1965 {
1966         //__focusPrevStatus = __pButton->GetButtonStatus();
1967         //__pButton->SetButtonStatus(_BUTTON_STATUS_HIGHLIGHTED);
1968         //__pButton->Invalidate();
1969
1970         return false;
1971 }
1972
1973 bool
1974 _ToolbarPresenter::OnFocusLost(const _Control& source)
1975 {
1976         //__pButton->SetButtonStatus(__focusPrevStatus);
1977         //__pButton->Invalidate();
1978
1979         return true;
1980 }
1981
1982 result
1983 _ToolbarPresenter::TimerForTitleSlideInit(void)
1984 {
1985         result r = E_SUCCESS;
1986
1987         if (__pTitleSlideTimer != null)
1988         {
1989                 delete __pTitleSlideTimer;
1990                 __pTitleSlideTimer = null;
1991         }
1992
1993         return r;
1994 }
1995
1996 result
1997 _ToolbarPresenter::TimerForTitleSlideStart(void)
1998 {
1999         result r = E_SUCCESS;
2000
2001         if (__pTitleSlideTimer == null)
2002         {
2003                 __pTitleSlideTimer = new (std::nothrow) Timer();
2004                 if (__pTitleSlideTimer == null)
2005                 {
2006                         r = E_OUT_OF_MEMORY;
2007                         goto CATCH;
2008                 }
2009
2010                 r = __pTitleSlideTimer->Construct(*this);
2011
2012                 if (IsFailed(r))
2013                 {
2014                         delete __pTitleSlideTimer;
2015                         goto CATCH;
2016                 }
2017         }
2018
2019         r = __pTitleSlideTimer->Start(100);
2020
2021         if (IsFailed(r))
2022         {
2023                 goto CATCH;
2024         }
2025
2026 CATCH:
2027         return r;
2028 }
2029
2030 result
2031 _ToolbarPresenter::TimerForTitleSlideTimeout(void)
2032 {
2033         Canvas* pCanvas = __pToolbar->GetCanvasN();
2034         SysTryReturnResult(NID_UI_CTRL, pCanvas, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pCanvas is invalid!");
2035
2036         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
2037         pCanvas->Clear(__titleRect);
2038
2039         if (__pTitleBackgroundBitmap)
2040         {
2041                 pCanvas->DrawBitmap(CoordinateSystem::AlignToDevice(__titleRect), *__pTitleBackgroundBitmap);
2042         }
2043
2044         if (__pTitleTextObject->IsChanged())
2045         {
2046                 DrawTitleText(pCanvas);
2047         }
2048
2049         if (__pTitleTextObject->IsActionOn() == true)
2050         {
2051                 __pTitleTextObject->DrawWithOffset(*_CanvasImpl::GetInstance(*pCanvas));
2052
2053                 DrawTitleTextDimBitmap();
2054
2055                 if (__pTitleTextObject->GetRepeatCount() < 3)
2056                 {
2057                         TimerForTitleSlideStart();
2058                 }
2059         }
2060         else
2061         {
2062                 __pTitleTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
2063         }
2064
2065         delete pCanvas;
2066
2067         return E_SUCCESS;
2068 }
2069
2070 void
2071 _ToolbarPresenter::DrawTitleTextDimBitmap(void)
2072 {
2073         if (__pToolbar->IsUserBackgroundBitmap())
2074         {
2075                 return;
2076         }
2077
2078         float textDimWidth = 0.0f;
2079         float textDimHeight = 0.0f;
2080         float leftMargin = 0.0f;
2081
2082         GET_SHAPE_CONFIG(HEADER::TAB_TEXT_DIM_WIDTH, __pToolbar->GetOrientation(), textDimWidth);
2083         GET_SHAPE_CONFIG(HEADER::LEFT_MARGIN, __pToolbar->GetOrientation(), leftMargin);
2084
2085         ToolbarStyle style = __pToolbar->GetStyle();
2086
2087         if (style == TOOLBAR_HEADER_SEGMENTED_WITH_TITLE || style == TOOLBAR_TAB_WITH_TITLE)
2088         {
2089                 GET_SHAPE_CONFIG(HEADER::TITLE_HEIGHT_WITH_SEGMENTED_ITEM, __pToolbar->GetOrientation(), textDimHeight);
2090         }
2091         else
2092         {
2093                 if (__pToolbar->GetDescriptionText() != L"")
2094                 {
2095                         textDimHeight = __titleRect.height + __titleRect.y;
2096                 }
2097                 else
2098                 {
2099                         textDimHeight = __pToolbar->GetBoundsF().height;
2100                 }
2101         }
2102
2103         //Color titleTextDimColor;
2104         //GET_COLOR_CONFIG(HEADER::TITLE_TEXT_DIM_NORMAL, titleTextDimColor);
2105
2106         Bitmap* pTitleTextDimLeftBitmap = null;
2107         GET_BITMAP_CONFIG_N(HEADER::TITLE_TEXT_DIM_EFFECT_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888, pTitleTextDimLeftBitmap);
2108
2109         Bitmap* pReColorTitleTextDimLeftBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTitleTextDimLeftBitmap,
2110                         Color::GetColor(COLOR_ID_MAGENTA), __pToolbar->GetColor());
2111
2112         if (pReColorTitleTextDimLeftBitmap)
2113         {
2114                 Canvas* pCanvas = __pToolbar->GetCanvasN();
2115                 FloatRectangle bounds = FloatRectangle(0.0f, 0.0f, textDimWidth, textDimHeight);
2116
2117                 if (__pToolbar->GetTitleIcon() != null)
2118                 {
2119                         bounds.x += __titleRect.x;
2120                 }
2121
2122                 if (pCanvas == null)
2123                 {
2124                         SysLog(NID_UI_CTRL, "Cannot get a canvas.");
2125
2126                         delete pReColorTitleTextDimLeftBitmap;
2127
2128                         return;
2129                 }
2130
2131                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReColorTitleTextDimLeftBitmap))
2132                 {
2133                         pCanvas->DrawNinePatchedBitmap(bounds, *pReColorTitleTextDimLeftBitmap);
2134                 }
2135                 else
2136                 {
2137                         pCanvas->DrawBitmap(bounds, *pReColorTitleTextDimLeftBitmap,
2138                                         FloatRectangle(0.0f, 0.0f, pReColorTitleTextDimLeftBitmap->GetWidthF(), pReColorTitleTextDimLeftBitmap->GetHeightF()));
2139                 }
2140
2141                 delete pReColorTitleTextDimLeftBitmap;
2142                 delete pCanvas;
2143         }
2144
2145         Bitmap* pTitleTextDimRightBitmap = null;
2146         GET_BITMAP_CONFIG_N(HEADER::TITLE_TEXT_DIM_EFFECT_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888, pTitleTextDimRightBitmap);
2147
2148         Bitmap* pReColorTitleTextDimRightBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTitleTextDimRightBitmap,
2149                         Color::GetColor(COLOR_ID_MAGENTA), __pToolbar->GetColor());
2150
2151         if (pReColorTitleTextDimRightBitmap)
2152         {
2153                 Canvas* pCanvas = __pToolbar->GetCanvasN();
2154                 FloatRectangle bounds = FloatRectangle(__titleRect.width, 0.0f, textDimWidth, textDimHeight);
2155
2156                 if (__pToolbar->GetTitleIcon() != null)
2157                 {
2158                         bounds.x += (__titleRect.x - leftMargin);
2159                 }
2160
2161                 if (pCanvas == null)
2162                 {
2163                         SysLog(NID_UI_CTRL, "Cannot get a canvas.");
2164
2165                         delete pReColorTitleTextDimRightBitmap;
2166                         return;
2167                 }
2168
2169                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReColorTitleTextDimRightBitmap))
2170                 {
2171                         pCanvas->DrawNinePatchedBitmap(bounds, *pReColorTitleTextDimRightBitmap);
2172                 }
2173                 else
2174                 {
2175                         pCanvas->DrawBitmap(bounds, *pReColorTitleTextDimRightBitmap,
2176                                         FloatRectangle(0.0f, 0.0f, pReColorTitleTextDimRightBitmap->GetWidthF(), pReColorTitleTextDimRightBitmap->GetHeightF()));
2177                 }
2178
2179                 delete pReColorTitleTextDimRightBitmap;
2180                 delete pCanvas;
2181         }
2182
2183         return;
2184 }
2185
2186 result
2187 _ToolbarPresenter::AdjustItemPositionX(float distance)
2188 {
2189         int index = 0;
2190         int itemCount = __pToolbar->GetItemCount();
2191         _Button* pItem = __pToolbar->GetItem(index);
2192
2193         while (pItem != null)
2194         {
2195                 FloatRectangle bounds = pItem->GetBoundsF();
2196                 bounds.x += distance;
2197                 pItem->SetBounds(bounds);
2198                 index++;
2199
2200                 if (index < itemCount)
2201                 {
2202                         pItem = __pToolbar->GetItem(index);
2203                 }
2204                 else
2205                 {
2206                         break;
2207                 }
2208         }
2209
2210         return E_SUCCESS;
2211 }
2212
2213 FloatRectangle
2214 _ToolbarPresenter::GetTitleTextBoundsF(void) const
2215 {
2216         return __titleRect;
2217 }
2218
2219 FloatRectangle
2220 _ToolbarPresenter::GetDescriptionBoundsF(void) const
2221 {
2222         return __descriptionRect;
2223 }
2224
2225 result
2226 _ToolbarPresenter::_SetModel(const _ToolbarModel& toolbarModel)
2227 {
2228         __pToolbarModel = const_cast<_ToolbarModel*>(&toolbarModel);
2229
2230         return E_SUCCESS;
2231 }
2232
2233 void
2234 _ToolbarPresenter::OnFontChanged(Font* pFont)
2235 {
2236         __pTextFont = pFont;
2237         __pTitleTextFont = pFont;
2238
2239         return;
2240 }
2241
2242 void
2243 _ToolbarPresenter::OnFontInfoRequested(unsigned long& style, int& size)
2244 {
2245         style = __fontStyle;
2246         size = _CoordinateSystemUtils::ConvertToInteger(__fontSize);
2247
2248         return;
2249 }
2250
2251 void
2252 _ToolbarPresenter::OnFontInfoRequested(unsigned long& style, float& size)
2253 {
2254         style = __fontStyle;
2255         size =  __fontSize;
2256
2257         return;
2258 }
2259
2260 void
2261 _ToolbarPresenter::OnAncestorVisibleStateChanged(const _Control& control)
2262 {
2263         if (__pTitleTextObject != null)
2264         {
2265                 __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
2266                 __pTitleTextObject->Compose();
2267         }
2268
2269         __titleSliding = false;
2270
2271         return ;
2272 }
2273
2274 void
2275 _ToolbarPresenter::SetFontInfo(unsigned long style, float size)
2276 {
2277         __fontStyle = style;
2278         __fontSize = size;
2279
2280         return;
2281 }
2282
2283 void
2284 _ToolbarPresenter::StartFlickAnimation(void)
2285 {
2286         float distance = CalculateProgress(__flickMove);
2287
2288         __moveDistance = -(__flickDistance * distance);
2289         __flickDistance = (__flickDistance + __moveDistance);
2290         __flickMove = __flickMove + 0.006;
2291         __flickFlag++;
2292
2293         if (__flickFlag <= FLICK_ANIMATION_COUNT)
2294         {
2295                 StartFlickAnimationTimer();
2296         }
2297         else
2298         {
2299                 ResetFlickAnimationTimer();
2300                 SetItemFit(__firstLoadedItemIndex);
2301         }
2302
2303         AdjustItemPositionX(__moveDistance);
2304
2305         SetFirstLoadedItemIndex();
2306         SetLastLoadedItemIndex();
2307
2308         Draw();
2309
2310         return;
2311 }
2312
2313 result
2314 _ToolbarPresenter::StartFlickAnimationTimer(void)
2315 {
2316         result r = E_SUCCESS;
2317
2318         if (__pFlickAnimationTimer == null)
2319         {
2320                 __pFlickAnimationTimer = new (std::nothrow) Timer();
2321                 SysTryReturn(NID_UI_CTRL, (__pFlickAnimationTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2322
2323                 r = __pFlickAnimationTimer->Construct(*this);
2324                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2325         }
2326         else
2327         {
2328                 __pFlickAnimationTimer->Cancel();
2329         }
2330
2331         r = __pFlickAnimationTimer->Start(FLICK_ANIMATION_TIMER_PERIOD);
2332         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2333
2334         return r;
2335
2336 CATCH:
2337         ResetFlickAnimationTimer();
2338         return r;
2339 }
2340
2341 result
2342 _ToolbarPresenter::ResetFlickAnimationTimer(void)
2343 {
2344         if (__pFlickAnimationTimer)
2345         {
2346                 delete __pFlickAnimationTimer;
2347                 __pFlickAnimationTimer = null;
2348         }
2349
2350         __moveDistance = 0.0f;
2351
2352         return E_SUCCESS;
2353 }
2354
2355 void
2356 _ToolbarPresenter::SetFirstLoadedItemIndex(void)
2357 {
2358         int itemCount = __pToolbar->GetItemCount();
2359
2360         for (int i = 0; i < itemCount; i++)
2361         {
2362                 if (__pToolbar->GetItem(i)->GetBoundsF().x + (__pToolbar->GetItem(i)->GetBoundsF().width / 2) <= __pToolbar->GetItem(i)->GetBoundsF().width)
2363                 {
2364                         __firstLoadedItemIndex = i;
2365                 }
2366         }
2367
2368         return;
2369 }
2370
2371 int
2372 _ToolbarPresenter::GetFirstLoadedItemIndex(void)
2373 {
2374         return __firstLoadedItemIndex;
2375 }
2376
2377 void
2378 _ToolbarPresenter::SetLastLoadedItemIndex(void)
2379 {
2380         float width = 0.0f;
2381         int itemCount = __pToolbar->GetItemCount();
2382
2383         if (__pToolbar->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
2384         {
2385                 width = __portraitSize.width;
2386         }
2387         else
2388         {
2389                 width = __landscapeSize.width;
2390         }
2391
2392         for (int i = 0; i < itemCount; i++)
2393         {
2394                 float X = __pToolbar->GetItem(i)->GetBoundsF().x;
2395
2396                 if ((X + (__pToolbar->GetItem(i)->GetBoundsF().width / 2)) < width)
2397                 {
2398                         __lastLoadedItemIndex = i;
2399                 }
2400         }
2401
2402         return;
2403 }
2404
2405 float
2406 _ToolbarPresenter::CalculateProgress(float timeProgress) const
2407 {
2408         const float segments[3][3] = {{0.0f, 0.01f, 0.45f}, {0.45f, 0.80f, 0.908f}, {0.908f, 0.9999f, 1.0f}};
2409         float loc_5 = timeProgress / 1;
2410         int loc_6 = 3;  //Length of the segments array
2411         int loc_9 = (int)floor(loc_6 * loc_5);
2412
2413         if (loc_9 >= loc_6)
2414         {
2415                 loc_9 = loc_6 - 1;
2416         }
2417
2418         float loc_7 = (loc_5 - loc_9 * (1.0 / loc_6)) * loc_6;
2419         float loc_8[3];
2420
2421         for (int i = 0; i < 3; i++)
2422         {
2423                  loc_8[i] = segments[loc_9][i];
2424         }
2425
2426         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])));
2427
2428         return ret;
2429 }
2430
2431 void
2432 _ToolbarPresenter::SetItemFit(int index)
2433 {
2434         if (index < 0)
2435         {
2436                 return;
2437         }
2438
2439         FloatPoint pt(0.0f, 0.0f);
2440         FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
2441
2442         float fitDistance = 0.0f;
2443         float tabLeftMargin = 0.0f;
2444         int itemCount = __pToolbar->GetItemCount();
2445
2446         GET_SHAPE_CONFIG(HEADER::TAB_LEFT_MARGIN, __pToolbar->GetOrientation(), tabLeftMargin);
2447
2448         _Button* pItem = __pToolbar->GetItem(index);
2449         SysTryReturnVoidResult(NID_UI_CTRL, pItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2450
2451         bounds = pItem->GetBoundsF();
2452
2453         fitDistance = -bounds.x + tabLeftMargin;
2454
2455         for (int i = 0; i < itemCount; i++)
2456         {
2457                 pItem = __pToolbar->GetItem(i);
2458                 SysTryReturnVoidResult(NID_UI_CTRL, pItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2459
2460                 bounds = pItem->GetBoundsF();
2461                 bounds.x = bounds.x + fitDistance;
2462                 pItem->SetBounds(bounds);
2463         }
2464
2465         SetFirstLoadedItemIndex();
2466         SetLastLoadedItemIndex();
2467
2468         Draw();
2469
2470         return;
2471 }
2472
2473 void
2474 _ToolbarPresenter::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
2475 {
2476         return;
2477 }
2478
2479 void
2480 _ToolbarPresenter::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
2481 {
2482         return;
2483 }
2484
2485 void
2486 _ToolbarPresenter::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
2487 {
2488         return;
2489 }
2490
2491 }}} // Tizen::Ui::Controls