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