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