Resolved issue N_SE-39048
[apps/osp/Calendar.git] / src / ClMonthPanel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        ClMonthPanel.cpp
19  * @brief       This is the implementation file for the MonthPanel class.
20  */
21
22 #include <FBase.h>
23 #include <FSocial.h>
24 #include "ClEventListPresentationModel.h"
25 #include "ClEventItem.h"
26 #include "ClGoToDatePopup.h"
27 #include "ClMainForm.h"
28 #include "ClMonthPanel.h"
29 #include "ClPanningAnimationManager.h"
30 #include "ClResourceManager.h"
31 #include "ClSharePopup.h"
32 #include "ClThreeButtonPopup.h"
33 #include "ClTwoButtonPopup.h"
34 #include "ClTypes.h"
35
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Social;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Ui::Animations;
42 using namespace Tizen::Ui::Controls;
43 using namespace Tizen::Ui::Scenes;
44
45 enum ItemElementId
46 {
47         ID_ITEM_ELEMENT_COLOR_BAR,
48         ID_ITEM_ELEMENT_SUBJECT,
49         ID_ITEM_ELEMENT_DURATION,
50         ID_ITEM_ELEMENT_LOCATION,
51         ID_ITEM_ELEMENT_REPEAT_ICON,
52         ID_ITEM_ELEMENT_ALARM_ICON
53 };
54
55 static const RecordId ID_DEFAULT_BIRTHDAY_CALENDAR = 3;
56
57 static const int IDA_MONTH_PANEL_CONTEXT_MENU_EDIT = 11311;
58 static const int IDA_MONTH_PANEL_CONTEXT_MENU_SHARE = 11312;
59 static const int IDA_MONTH_PANEL_CONTEXT_MENU_DELETE = 11313;
60
61 static const int Y_CALENDAR = 18;
62 static const int X_WEEK = 17;
63 static const int Y_WEEK = 0;
64 static const int W_WEEK = 98;
65 static const int H_WEEK = 38;
66 static const int FONT_SIZE_WEEK = 24;
67 static const unsigned int COLOR_WEEK = Color32<57, 57, 57>::Value;
68 static const unsigned int COLOR_WEEK_SUN = Color32<171, 60, 60>::Value;
69 static const int X_DAY = 17;
70 static const int Y_DAY = 38;
71 static const int W_DAY = 98;
72 static const int H_DAY = 107;
73 static const int H_DAY_BUTTON = 100;
74 static const int X_DAY_BITMAP = 0;
75 static const int Y_DAY_BITMAP = 0;
76 static const int FONT_SIZE_DAY = 45;
77 static const unsigned int COLOR_DAY = Color32<57, 57, 57>::Value;
78 static const unsigned int COLOR_DAY_DIM = Color32<186, 186, 186>::Value;
79 static const unsigned int COLOR_DAY_SUN = Color32<171, 60, 60>::Value;
80 static const unsigned int COLOR_DAY_SUN_DIM = Color32<224, 185, 180>::Value;
81 static const unsigned int COLOR_DAY_FOCUS = Color32<255, 255, 255>::Value;
82 static const unsigned int COLOR_EVENT_LIST_BACKGROUND = Color32<248, 246, 239>::Value;
83 static const unsigned int COLOR_EVENT_LIST_DIVIDER = Color32<169, 169, 169>::Value;
84 static const unsigned int COLOR_ITEM_DELETE_TEXT = Color32<255, 255, 255>::Value;
85 static const unsigned int COLOR_ITEM_DELETE_BACKGROUND = Color32<208, 82, 82>::Value;
86 static const unsigned int COLOR_ITEM_DELETE_PRESSED_BACKGROUND = Color32<194, 71, 71>::Value;
87
88 static const int WEEKDAY_COUNT = 7;
89 static const int HALF_ALPHA = 128;
90 static const int FULL_ALPHA = 255;
91
92 class DayButton
93         : public Button
94         , public virtual IActionEventListener
95 {
96 public:
97         const DateTime& GetDate(void) const;
98         void Initialize(const EventListPresentationModel& pm, Bitmap* pBitmapEvent, Bitmap* pBitmapEventFocus, Bitmap* pBitmapFocus, Bitmap* pBitmapToday);
99         void SetDate(const DateTime& date);
100         void SetDateFocusEventListener(IDateFocusEventListener& listener);
101         void SetDayFocus(bool focus);
102         void UpdateEvent(void);
103
104         DayButton(void);
105         virtual ~DayButton(void);
106
107         virtual result OnInitializing(void);
108         virtual result OnTerminating(void);
109
110         virtual void OnActionPerformed(const Control& source, int actionId);
111
112 private:
113         const EventListPresentationModel* __pPm;
114         DateTime __date;
115         IDateFocusEventListener* __pDateFocusEventListener;
116         Bitmap* __pBitmapEvent;
117         Bitmap* __pBitmapEventFocus;
118         Bitmap* __pBitmapFocus;
119         Bitmap* __pBitmapToday;
120         bool __isFocused;
121 };
122
123 DayButton::DayButton(void)
124         : __pPm(null)
125         , __pDateFocusEventListener(null)
126         , __pBitmapEvent(null)
127         , __pBitmapEventFocus(null)
128         , __pBitmapFocus(null)
129         , __pBitmapToday(null)
130         , __isFocused(false)
131 {
132 }
133
134 DayButton::~DayButton(void)
135 {
136 }
137
138 const DateTime&
139 DayButton::GetDate(void) const
140 {
141         return __date;
142 }
143
144 void
145 DayButton::Initialize(const EventListPresentationModel& pm, Bitmap* pBitmapEvent, Bitmap* pBitmapEventFocus, Bitmap* pBitmapFocus, Bitmap* pBitmapToday)
146 {
147         Construct(Rectangle(0, 0, W_DAY, H_DAY_BUTTON), L"");
148         __pPm = &pm;
149         __pBitmapEvent = pBitmapEvent;
150         __pBitmapEventFocus = pBitmapEventFocus;
151         __pBitmapFocus = pBitmapFocus;
152         __pBitmapToday = pBitmapToday;
153 }
154
155 void
156 DayButton::SetDate(const DateTime& date)
157 {
158         __date = date;
159
160         Bitmap* pBitmap = null;
161         if (__isFocused == true)
162         {
163                 if (__pPm->GetWholeEventCount(__date) > 0)
164                 {
165                         pBitmap = __pBitmapEventFocus;
166                 }
167                 else
168                 {
169                         pBitmap = __pBitmapFocus;
170                 }
171         }
172         else
173         {
174                 if (EventListPresentationModel::IsToday(__date) == true)
175                 {
176                         pBitmap = __pBitmapToday;
177                 }
178                 else if (__pPm->GetWholeEventCount(__date) > 0)
179                 {
180                         pBitmap = __pBitmapEvent;
181                 }
182                 else
183                 {
184                         pBitmap = ResourceManager::GetBlankBitmap();
185                 }
186         }
187         if (pBitmap != null)
188         {
189                 Point position(X_DAY_BITMAP, Y_DAY_BITMAP);
190                 if (pBitmap != ResourceManager::GetBlankBitmap())
191                 {
192                         pBitmap->SetAlphaConstant(HALF_ALPHA);
193                         SetDisabledBitmap(position, *pBitmap);
194                         pBitmap->SetAlphaConstant(FULL_ALPHA);
195                         SetNormalBitmap(position, *pBitmap);
196                 }
197                 else
198                 {
199                         SetNormalBitmap(position, *pBitmap);
200                         SetDisabledBitmap(position, *pBitmap);
201                 }
202         }
203
204         SetText(Integer::ToString(__date.GetDay()));
205         int dayOfWeek = (__pPm->GetStartDayOfWeek(__date.GetYear(), __date.GetMonth()) + __date.GetDay() - 1) % WEEKDAY_COUNT;
206         if (dayOfWeek == 0)
207         {
208                 SetTextColor(Color((__isFocused == true) ? COLOR_DAY_FOCUS : COLOR_DAY_SUN));
209                 SetDisabledTextColor(Color(COLOR_DAY_SUN_DIM));
210         }
211         else
212         {
213                 SetTextColor(Color((__isFocused == true) ? COLOR_DAY_FOCUS : COLOR_DAY));
214                 SetDisabledTextColor(Color(COLOR_DAY_DIM));
215         }
216 }
217
218 void
219 DayButton::SetDateFocusEventListener(IDateFocusEventListener& listener)
220 {
221         __pDateFocusEventListener = &listener;
222 }
223
224 void
225 DayButton::SetDayFocus(bool focus)
226 {
227         if (__isFocused != focus)
228         {
229                 __isFocused = focus;
230                 Bitmap* pBitmap = null;
231                 if (__isFocused == true)
232                 {
233                         if (__pPm->GetWholeEventCount(__date) > 0)
234                         {
235                                 pBitmap = __pBitmapEventFocus;
236                         }
237                         else
238                         {
239                                 pBitmap = __pBitmapFocus;
240                         }
241                 }
242                 else
243                 {
244                         if (EventListPresentationModel::IsToday(__date) == true)
245                         {
246                                 pBitmap = __pBitmapToday;
247                         }
248                         else if (__pPm->GetWholeEventCount(__date) > 0)
249                         {
250                                 pBitmap = __pBitmapEvent;
251                         }
252                         else
253                         {
254                                 pBitmap = ResourceManager::GetBlankBitmap();
255                         }
256                 }
257                 if (pBitmap != null)
258                 {
259                         SetNormalBitmap(Point(X_DAY_BITMAP, Y_DAY_BITMAP), *pBitmap);
260                         SetDisabledBitmap(Point(X_DAY_BITMAP, Y_DAY_BITMAP), *pBitmap);
261                 }
262         }
263
264         int dayOfWeek = (__pPm->GetStartDayOfWeek(__date.GetYear(), __date.GetMonth()) + __date.GetDay() - 1) % WEEKDAY_COUNT;
265         if (dayOfWeek == 0)
266         {
267                 SetTextColor(Color((__isFocused == true) ? COLOR_DAY_FOCUS : COLOR_DAY_SUN));
268                 SetDisabledTextColor(Color(COLOR_DAY_SUN_DIM));
269         }
270         else
271         {
272                 SetTextColor(Color((__isFocused == true) ? COLOR_DAY_FOCUS : COLOR_DAY));
273                 SetDisabledTextColor(Color(COLOR_DAY_DIM));
274         }
275 }
276
277 void
278 DayButton::UpdateEvent(void)
279 {
280         Bitmap* pBitmap = null;
281         if (__isFocused == true)
282         {
283                 if (__pPm->GetWholeEventCount(__date) > 0)
284                 {
285                         pBitmap = __pBitmapEventFocus;
286                 }
287                 else
288                 {
289                         pBitmap = __pBitmapFocus;
290                 }
291         }
292         else
293         {
294                 if (EventListPresentationModel::IsToday(__date) == true)
295                 {
296                         pBitmap = __pBitmapToday;
297                 }
298                 else if (__pPm->GetWholeEventCount(__date) > 0)
299                 {
300                         pBitmap = __pBitmapEvent;
301                 }
302                 else
303                 {
304                         pBitmap = ResourceManager::GetBlankBitmap();
305                 }
306         }
307         if (pBitmap != null)
308         {
309                 Point position(X_DAY_BITMAP, Y_DAY_BITMAP);
310                 if (pBitmap != ResourceManager::GetBlankBitmap())
311                 {
312                         pBitmap->SetAlphaConstant(HALF_ALPHA);
313                         SetDisabledBitmap(position, *pBitmap);
314                         pBitmap->SetAlphaConstant(FULL_ALPHA);
315                         SetNormalBitmap(position, *pBitmap);
316                 }
317                 else
318                 {
319                         SetNormalBitmap(position, *pBitmap);
320                         SetDisabledBitmap(position, *pBitmap);
321                 }
322         }
323         Invalidate(false);
324 }
325
326 result
327 DayButton::OnInitializing(void)
328 {
329         SetNormalBackgroundBitmap(*ResourceManager::GetBlankBitmap());
330         SetPressedBackgroundBitmap(*ResourceManager::GetBlankBitmap());
331         SetHighlightedBackgroundBitmap(*ResourceManager::GetBlankBitmap());
332
333         Bitmap* pPressedBitmap = ResourceManager::GetBitmapN(IDB_MONTH_VIEW_DAY_PRESS);
334         if (pPressedBitmap != null)
335         {
336                 SetPressedBitmap(Point(X_DAY_BITMAP, Y_DAY_BITMAP), *pPressedBitmap);
337                 delete pPressedBitmap;
338         }
339
340         SetTextSize(FONT_SIZE_DAY);
341         SetTextColor(Color(COLOR_DAY));
342         SetPressedTextColor(Color(COLOR_DAY_FOCUS));
343         SetHighlightedTextColor(Color(COLOR_DAY_FOCUS));
344         SetDisabledTextColor(Color(COLOR_DAY_DIM));
345
346         AddActionEventListener(*this);
347         return E_SUCCESS;
348 }
349
350 result
351 DayButton::OnTerminating(void)
352 {
353         return E_SUCCESS;
354 }
355
356 void
357 DayButton::OnActionPerformed(const Control& source, int actionId)
358 {
359         SetDayFocus(true);
360         Invalidate(false);
361         if (__pDateFocusEventListener != null)
362         {
363                 __pDateFocusEventListener->OnDateFocused(__date);
364         }
365 }
366
367 class MonthCalendarPanel
368         : public Panel
369         , public virtual IDateFocusEventListener
370 {
371 public:
372         const DateTime& GetDate(void) const;
373         int GetViewHeight(void) const;
374         result Initialize(const Rectangle& bounds, const DateTime& date, const EventListPresentationModel& pm);
375         void SetDate(const DateTime& date);
376         void SetDateFocusEventListener(IDateFocusEventListener& listener);
377         void SetFocusEnabled(bool enable = true);
378         void UpdateEvent(void);
379
380         MonthCalendarPanel(void);
381         virtual ~MonthCalendarPanel(void);
382
383         virtual void OnClearBackground(void);
384         virtual result OnInitializing(void);
385         virtual result OnTerminating(void);
386
387         virtual void OnDateFocused(const DateTime& focusedDate);
388
389 private:
390         static const int MONTH_CALENDAR_ROW_COUNT = 6;
391         static const int MONTH_CALENDAR_WEEKDAY_COUNT = 7;
392
393         DateTime __date;
394         const EventListPresentationModel* __pPm;
395         IDateFocusEventListener* __pDateFocusEventListener;
396         int __firstDayOfWeek;
397         int __startDayColumn;
398         Label* __pLabelWeekText[MONTH_CALENDAR_WEEKDAY_COUNT];
399         DayButton* __pDayCalendars[MONTH_CALENDAR_ROW_COUNT][MONTH_CALENDAR_WEEKDAY_COUNT];
400         Bitmap* __pBitmapEvent;
401         Bitmap* __pBitmapEventFocus;
402         Bitmap* __pBitmapFocus;
403         Bitmap* __pBitmapToday;
404         bool __focusEnabled;
405 };
406
407 MonthCalendarPanel::MonthCalendarPanel(void)
408         : __pPm(null)
409         , __pDateFocusEventListener(null)
410         , __firstDayOfWeek(-1)
411         , __startDayColumn(-1)
412         , __pBitmapEvent(null)
413         , __pBitmapEventFocus(null)
414         , __pBitmapFocus(null)
415         , __pBitmapToday(null)
416         , __focusEnabled(false)
417 {
418         memset((void *)__pLabelWeekText, 0, sizeof(Label*) * MONTH_CALENDAR_WEEKDAY_COUNT);
419         memset((void *)__pDayCalendars, 0, sizeof(DayButton*) * MONTH_CALENDAR_ROW_COUNT * MONTH_CALENDAR_WEEKDAY_COUNT);
420 }
421
422 MonthCalendarPanel::~MonthCalendarPanel(void)
423 {
424 }
425
426 const DateTime&
427 MonthCalendarPanel::GetDate(void) const
428 {
429         return __date;
430 }
431
432 int
433 MonthCalendarPanel::GetViewHeight(void) const
434 {
435         int maxDay;
436         DateTime::GetDaysInMonth(__date.GetYear(), __date.GetMonth(), maxDay);
437         return Y_DAY + ((maxDay + __startDayColumn - 1) / MONTH_CALENDAR_WEEKDAY_COUNT  + 1) * H_DAY;
438 }
439
440 result
441 MonthCalendarPanel::Initialize(const Rectangle& bounds, const DateTime& date, const EventListPresentationModel& pm)
442 {
443         __date = date;
444         __pPm = &pm;
445         __startDayColumn = __pPm->GetStartDayOfWeek(__date.GetYear(), __date.GetMonth()) - EventListPresentationModel::GetFirstDayOfWeek();
446         if (__startDayColumn < 0)
447         {
448                 __startDayColumn += MONTH_CALENDAR_WEEKDAY_COUNT;
449         }
450
451         return Construct(bounds);
452 }
453
454 void
455 MonthCalendarPanel::SetDate(const DateTime& date)
456 {
457         int firstDayOfWeek = EventListPresentationModel::GetFirstDayOfWeek();
458         if (EventListPresentationModel::IsSameDay(__date, date) == false || firstDayOfWeek != __firstDayOfWeek)
459         {
460                 if (date.GetYear() != __date.GetYear() || date.GetMonth() != __date.GetMonth() || firstDayOfWeek != __firstDayOfWeek)
461                 {
462                         if (firstDayOfWeek != __firstDayOfWeek)
463                         {
464                                 __firstDayOfWeek = firstDayOfWeek;
465                                 for (int col = 0; col < MONTH_CALENDAR_WEEKDAY_COUNT; ++col)
466                                 {
467                                         int dayOfWeek = (col + firstDayOfWeek) % MONTH_CALENDAR_WEEKDAY_COUNT;
468                                         __pLabelWeekText[col]->SetText(ResourceManager::GetWeekShortString(dayOfWeek));
469                                         __pLabelWeekText[col]->SetTextColor(Color((dayOfWeek == 0) ? COLOR_WEEK_SUN : COLOR_WEEK));
470                                         __pLabelWeekText[col]->Invalidate(false);
471                                 }
472                         }
473                         __startDayColumn = __pPm->GetStartDayOfWeek(date.GetYear(), date.GetMonth()) - __firstDayOfWeek;
474                         if (__startDayColumn < 0)
475                         {
476                                 __startDayColumn += MONTH_CALENDAR_WEEKDAY_COUNT;
477                         }
478                 }
479                 else
480                 {
481                         int prevIndex = __date.GetDay() + __startDayColumn - 1;
482                         int prevRow = prevIndex / MONTH_CALENDAR_WEEKDAY_COUNT;
483                         int prevCol = prevIndex % MONTH_CALENDAR_WEEKDAY_COUNT;
484                         __pDayCalendars[prevRow][prevCol]->SetDayFocus(false);
485                         __pDayCalendars[prevRow][prevCol]->Invalidate(false);
486
487                         int nextIndex = date.GetDay() + __startDayColumn - 1;
488                         int nextRow = nextIndex / MONTH_CALENDAR_WEEKDAY_COUNT;
489                         int nextCol = nextIndex % MONTH_CALENDAR_WEEKDAY_COUNT;
490                         __pDayCalendars[nextRow][nextCol]->SetDayFocus(true);
491                         __pDayCalendars[nextRow][nextCol]->Invalidate(false);
492                 }
493         }
494         __date = date;
495 }
496
497 void
498 MonthCalendarPanel::SetDateFocusEventListener(IDateFocusEventListener& listener)
499 {
500         __pDateFocusEventListener = &listener;
501 }
502
503 void
504 MonthCalendarPanel::SetFocusEnabled(bool enable)
505 {
506         __focusEnabled = enable;
507 }
508
509 void
510 MonthCalendarPanel::UpdateEvent(void)
511 {
512         for (int row = 0; row < MONTH_CALENDAR_ROW_COUNT; ++row)
513         {
514                 for (int col = 0; col < MONTH_CALENDAR_WEEKDAY_COUNT; ++col)
515                 {
516                         __pDayCalendars[row][col]->UpdateEvent();
517                 }
518         }
519 }
520
521 void
522 MonthCalendarPanel::OnClearBackground(void)
523 {
524         // Draw background
525         Canvas* pCanvas = GetCanvasN();
526         Bitmap* pBitmapBackground = ResourceManager::GetBitmapN(IDB_MONTH_VIEW_CALENDAR_BG);
527         if (pBitmapBackground != null)
528         {
529                 pCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, GetWidth(), GetHeight()), *pBitmapBackground);
530                 delete pBitmapBackground;
531         }
532         delete pCanvas;
533
534         int firstDayOfWeek = EventListPresentationModel::GetFirstDayOfWeek();
535         if (firstDayOfWeek != __firstDayOfWeek)
536         {
537                 for (int col = 0; col < MONTH_CALENDAR_WEEKDAY_COUNT; ++col)
538                 {
539                         int dayOfWeek = (col + firstDayOfWeek) % MONTH_CALENDAR_WEEKDAY_COUNT;
540                         __pLabelWeekText[col]->SetText(ResourceManager::GetWeekShortString(dayOfWeek));
541                         __pLabelWeekText[col]->SetTextColor(Color((dayOfWeek == 0) ? COLOR_WEEK_SUN : COLOR_WEEK));
542                         __pLabelWeekText[col]->Invalidate(false);
543                 }
544                 __startDayColumn = __pPm->GetStartDayOfWeek(__date.GetYear(), __date.GetMonth()) - firstDayOfWeek;
545                 if (__startDayColumn < 0)
546                 {
547                         __startDayColumn += MONTH_CALENDAR_WEEKDAY_COUNT;
548                 }
549                 __firstDayOfWeek = firstDayOfWeek;
550         }
551
552         DateTime date = __pDayCalendars[0][__startDayColumn]->GetDate();
553         if (date.GetYear() != __date.GetYear() || date.GetMonth() != __date.GetMonth() || date.GetDay() != 1)
554         {
555                 date = __date;
556                 date.AddDays(1 - __startDayColumn - date.GetDay());
557                 for (int row = 0; row < MONTH_CALENDAR_ROW_COUNT; ++row)
558                 {
559                         for (int col = 0; col < MONTH_CALENDAR_WEEKDAY_COUNT; ++col)
560                         {
561                                 __pDayCalendars[row][col]->SetDate(date);
562                                 __pDayCalendars[row][col]->SetDayFocus(EventListPresentationModel::IsSameDay(date, __date) == true);
563                                 __pDayCalendars[row][col]->SetEnabled(date.GetMonth() == __date.GetMonth());
564                                 __pDayCalendars[row][col]->SetShowState(true);
565                                 __pDayCalendars[row][col]->Invalidate(false);
566                                 date.AddDays(1);
567                         }
568                 }
569         }
570 }
571
572 result
573 MonthCalendarPanel::OnInitializing(void)
574 {
575         // Create week label
576         for (int week = 0; week < MONTH_CALENDAR_WEEKDAY_COUNT; ++week)
577         {
578                 Label* pLabel = new (std::nothrow) Label();
579                 pLabel->Construct(Rectangle(X_WEEK + W_DAY * week, Y_WEEK, W_WEEK, H_WEEK), L"");
580                 pLabel->SetTextConfig(FONT_SIZE_WEEK, LABEL_TEXT_STYLE_NORMAL);
581                 AddControl(pLabel);
582                 __pLabelWeekText[week] = pLabel;
583         }
584
585         // Load day bitmaps
586         __pBitmapEvent = ResourceManager::GetBitmapN(IDB_MONTH_VIEW_DAY_EVENT);
587         __pBitmapEventFocus = ResourceManager::GetBitmapN(IDB_MONTH_VIEW_DAY_EVENT_FOCUS);
588         __pBitmapFocus = ResourceManager::GetBitmapN(IDB_MONTH_VIEW_DAY_FOCUS);
589         __pBitmapToday = ResourceManager::GetBitmapN(IDB_MONTH_VIEW_TODAY);
590
591         // Create day button
592         for (int row = 0; row < MONTH_CALENDAR_ROW_COUNT; ++row)
593         {
594                 for (int col = 0; col < MONTH_CALENDAR_WEEKDAY_COUNT; ++col)
595                 {
596                         DayButton* pButtonDay = new (std::nothrow) DayButton();
597                         pButtonDay->Initialize(*__pPm, __pBitmapEvent, __pBitmapEventFocus, __pBitmapFocus, __pBitmapToday);
598                         pButtonDay->SetPosition(X_DAY + col * W_DAY, Y_DAY + row * H_DAY);
599                         pButtonDay->SetDateFocusEventListener(*this);
600                         AddControl(pButtonDay);
601                         __pDayCalendars[row][col] = pButtonDay;
602                 }
603         }
604
605         return E_SUCCESS;
606 }
607
608 result
609 MonthCalendarPanel::OnTerminating(void)
610 {
611         delete __pBitmapEvent;
612         delete __pBitmapEventFocus;
613         delete __pBitmapFocus;
614         delete __pBitmapToday;
615         return E_SUCCESS;
616 }
617
618 void
619 MonthCalendarPanel::OnDateFocused(const DateTime& focusedDate)
620 {
621         if (EventListPresentationModel::IsSameDay(__date, focusedDate) == false)
622         {
623                 int index = __date.GetDay() + __startDayColumn - 1;
624                 int row = index / MONTH_CALENDAR_WEEKDAY_COUNT;
625                 int col = index % MONTH_CALENDAR_WEEKDAY_COUNT;
626                 __pDayCalendars[row][col]->SetDayFocus(false);
627                 __pDayCalendars[row][col]->Invalidate(false);
628
629                 __date = focusedDate;
630                 if (__pDateFocusEventListener != null)
631                 {
632                         __pDateFocusEventListener->OnDateFocused(focusedDate);
633                 }
634         }
635 }
636
637
638 MonthPanel::MonthPanel(void)
639         : __pPm(null)
640         , __selectedIndex(0)
641         , __pListViewEvent(null)
642         , __pContextItem(null)
643         , __pContextItemNoEdit(null)
644         , __pPanningAnimationManager(null)
645         , __pSharePopup(null)
646         , __pThreeButtonPopup(null)
647         , __pTwoButtonPopup(null)
648         , __pGoToDatePopup(null)
649 {
650         memset((void *)__pPanelMonthCalendar, 0, sizeof(Panel*) * VIEW_SCROLL_EFFECT_COUNT);
651 }
652
653 MonthPanel::~MonthPanel(void)
654 {
655 }
656
657 result
658 MonthPanel::Initialize(void)
659 {
660         static const int _MIN_SIZE = 1;
661         return Construct(Rectangle(0, 0, _MIN_SIZE, _MIN_SIZE));
662 }
663
664 result
665 MonthPanel::OnInitializing(void)
666 {
667         __pPm = EventListPresentationModel::GetInstance();
668
669         Form* pForm = dynamic_cast<Form*>(GetParent());
670         AppAssertf(pForm != null, "[E_FAILURE] Unable to get Form.");
671
672         Rectangle bounds = pForm->GetClientAreaBounds();
673         bounds.x = 0;
674         bounds.y = 0;
675         SetBounds(bounds);
676
677         // Create panning animation manager
678         __pPanningAnimationManager = new (std::nothrow) PanningAnimationManager();
679         __pPanningAnimationManager->Initialize(bounds, *this);
680         __pPanningAnimationManager->SetPanningAnimationEventListener(*this);
681         AddControl(__pPanningAnimationManager);
682
683         MonthCalendarPanel* pPanel = new (std::nothrow) MonthCalendarPanel();
684         pPanel->Initialize(Rectangle(0, Y_CALENDAR, bounds.width, bounds.height), __pPm->GetCurrentDate(), *__pPm);
685         __pPanningAnimationManager->AddView(*pPanel, VIEW_SCROLL_EFFECT_CURRENT);
686         pPanel->SetDateFocusEventListener(*this);
687         pPanel->SetFocusEnabled(true);
688         pPanel->SetSize(pPanel->GetWidth(), pPanel->GetViewHeight());
689         __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT] = pPanel;
690
691         __pContextItem = new (std::nothrow) ListContextItem();
692         __pContextItem->Construct();
693         __pContextItem->AddElement(IDA_MONTH_PANEL_CONTEXT_MENU_EDIT,
694                                                          ResourceManager::GetString(IDS_CLD_SK3_EDIT), true);
695         __pContextItem->AddElement(IDA_MONTH_PANEL_CONTEXT_MENU_SHARE,
696                                                          ResourceManager::GetString(IDS_COM_SK4_SHARE), true);
697         __pContextItem->AddElement(IDA_MONTH_PANEL_CONTEXT_MENU_DELETE,
698                                                          ResourceManager::GetString(IDS_CLD_SK3_DELETE), true);
699         __pContextItem->SetElementBackgroundColor(IDA_MONTH_PANEL_CONTEXT_MENU_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL, Color(COLOR_ITEM_DELETE_BACKGROUND));
700         __pContextItem->SetElementBackgroundColor(IDA_MONTH_PANEL_CONTEXT_MENU_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_PRESSED, Color(COLOR_ITEM_DELETE_PRESSED_BACKGROUND));
701         __pContextItem->SetElementBackgroundColor(IDA_MONTH_PANEL_CONTEXT_MENU_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_HIGHLIGHTED, Color(COLOR_ITEM_DELETE_PRESSED_BACKGROUND));
702         __pContextItem->SetElementTextColor(IDA_MONTH_PANEL_CONTEXT_MENU_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL, Color(COLOR_ITEM_DELETE_TEXT));
703
704         __pContextItemNoEdit = new (std::nothrow) ListContextItem();
705         __pContextItemNoEdit->Construct();
706         __pContextItemNoEdit->AddElement(IDA_MONTH_PANEL_CONTEXT_MENU_SHARE,
707                                                          ResourceManager::GetString(IDS_COM_SK4_SHARE), true);
708
709         bounds.y += __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT]->GetHeight();
710         bounds.height -= bounds.y;
711         __pListViewEvent = new (std::nothrow) ListView();
712         __pListViewEvent->Construct(bounds, true, SCROLL_STYLE_FADE_OUT);
713         __pListViewEvent->SetBackgroundColor(Color(COLOR_EVENT_LIST_BACKGROUND));
714         __pListViewEvent->SetItemDividerColor(Color(COLOR_EVENT_LIST_DIVIDER));
715         __pListViewEvent->SetTextOfEmptyList(ResourceManager::GetString(IDS_CLD_BODY_NO_EVENTS));
716         __pListViewEvent->SetItemProvider(*this);
717         __pListViewEvent->AddListViewItemEventListener(*this);
718         AddControl(__pListViewEvent);
719         SetControlAlwaysOnTop(*__pListViewEvent, true);
720
721         __pSharePopup = new (std::nothrow) SharePopup();
722         __pSharePopup->Initialize();
723
724         __pThreeButtonPopup = new (std::nothrow) ThreeButtonPopup();
725         __pThreeButtonPopup->Initialize();
726
727         __pTwoButtonPopup = new (std::nothrow) TwoButtonPopup();
728         __pTwoButtonPopup->Initialize();
729
730         __pGoToDatePopup = new (std::nothrow) GoToDatePopup();
731         __pGoToDatePopup->Initialize();
732
733         return E_SUCCESS;
734 }
735
736 result
737 MonthPanel::OnTerminating(void)
738 {
739         __pPm->RemoveCalendarEventChangedEventListener(*this);
740         __pPm->RemoveCurrentDateChangedEventListener(*this);
741
742         if (__pSharePopup)
743         {
744                 __pSharePopup->Destroy();
745         }
746         if (__pThreeButtonPopup)
747         {
748                 __pThreeButtonPopup->Destroy();
749         }
750         if (__pTwoButtonPopup)
751         {
752                 __pTwoButtonPopup->Destroy();
753         }
754         if (__pGoToDatePopup)
755         {
756                 __pGoToDatePopup->Destroy();
757         }
758
759         delete __pContextItem;
760         delete __pContextItemNoEdit;
761         return E_SUCCESS;
762 }
763
764 void
765 MonthPanel::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
766 {
767         switch (requestId)
768         {
769         case IDA_MAIN_FORM_HEADER_TODAY:
770                 __pPanningAnimationManager->CancelPanningAnimationEvent();
771                 __pPm->SetTodayToCurrentDate();
772                 break;
773         case IDA_SUB_MENU_GO_TO_DATE:
774                 __pGoToDatePopup->RequestPopup(__pPm->GetCurrentDate(), this);
775                 break;
776         case IDA_MAIN_FORM_FOOTER_CREATE:
777         {
778                 LinkedList* pArgs = new (std::nothrow) LinkedList();
779                 pArgs->Add(new (std::nothrow) DateTime(__pPm->GetCurrentDate()));
780                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_EDITOR,
781                                                                                                                                           SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
782                 break;
783         }
784         case IDA_SUB_MENU_DELETE:
785                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_DELETER,
786                                                                                                                                           SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
787                 break;
788         case IDA_SUB_MENU_SEARCH:
789                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_SEARCHER,
790                                                                                                                                           SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
791                 break;
792         case IDA_SUB_MENU_CALENDARS:
793                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_CALENDAR_LIST,
794                                                                                                                                           SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
795                 break;
796         case IDA_SUB_MENU_SETTING:
797                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_SETTING,
798                                                                                                                                           SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
799                 break;
800         case IDA_VIEW_MENU_YEAR:
801                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_YEAR,
802                                                                                                                                           SCENE_TRANSITION_ANIMATION_TYPE_LEFT,
803                                                                                                                                           SCENE_HISTORY_OPTION_NO_HISTORY));
804                 break;
805         case IDA_VIEW_MENU_DAY:
806                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_DAY,
807                                                                                                                                           SCENE_TRANSITION_ANIMATION_TYPE_LEFT,
808                                                                                                                                           SCENE_HISTORY_OPTION_NO_HISTORY));
809                 break;
810         case IDA_VIEW_MENU_LIST:
811                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_LIST,
812                                                                                                                                           SCENE_TRANSITION_ANIMATION_TYPE_LEFT,
813                                                                                                                                           SCENE_HISTORY_OPTION_NO_HISTORY));
814                 break;
815         case IDA_GO_TO_DATE_POPUP_DONE:
816         {
817                 DateTime selectedDate = *static_cast<DateTime*>(pArgs->GetAt(0));
818                 DateTime currentDate = __pPm->GetCurrentDate();
819                 currentDate.SetValue(selectedDate.GetYear(), selectedDate.GetMonth(), selectedDate.GetDay(), currentDate.GetHour(), currentDate.GetMinute());
820                 __pPm->SetCurrentDate(currentDate);
821                 break;
822         }
823         case IDA_EVENT_POPUP_DELETE:
824                 __pPm->RemoveEvent(*static_cast<CalEventInstance*>(pArgs->GetAt(0)), true);
825                 break;
826         case IDA_EVENT_POPUP_ONLY_THIS_EVENT_DELETE:
827                 __pPm->RemoveEvent(*static_cast<CalEventInstance*>(pArgs->GetAt(0)), false);
828                 break;
829         case IDA_EVENT_POPUP_ALL_REPETITIVE_EVENT_DELETE:
830                 __pPm->RemoveEvent(*static_cast<CalEventInstance*>(pArgs->GetAt(0)), true);
831                 break;
832         case IDA_EVENT_POPUP_ONLY_THIS_EVENT_EDIT:
833         {
834                 pArgs->Add(new (std::nothrow) Boolean(false));
835                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_EDITOR,
836                                                                                                                                   SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
837                 pArgs = null;
838                 break;
839         }
840         case IDA_EVENT_POPUP_ALL_REPETITIVE_EVENT_EDIT:
841         {
842                 pArgs->Add(new (std::nothrow) Boolean(true));
843                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_EDITOR,
844                                                                                                                                   SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
845                 pArgs = null;
846                 break;
847         }
848         }
849
850         if (pArgs != null)
851         {
852                 pArgs->RemoveAll(true);
853                 delete pArgs;
854         }
855 }
856
857 void
858 MonthPanel::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
859 {
860         if (status == LIST_ITEM_STATUS_SELECTED)
861         {
862                 LinkedList* pArgs = new (std::nothrow) LinkedList(SingleObjectDeleter);
863                 pArgs->Add(new (std::nothrow) CalEventInstance(*__pPm->GetEventWithWholeIndex(__pPm->GetCurrentDate(), index)));
864                 result r = SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_DETAILS,
865                                                                                                                                                                  SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
866                 if (IsFailed(r))
867                 {
868                         delete pArgs;
869                 }
870         }
871 }
872
873 void
874 MonthPanel::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
875 {
876 }
877
878 void
879 MonthPanel::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus status)
880 {
881         if (status == LIST_CONTEXT_ITEM_STATUS_SELECTED)
882         {
883                 const CalEventInstance* pEvent = __pPm->GetEventWithWholeIndex(__pPm->GetCurrentDate(), index);
884                 switch (elementId)
885                 {
886                 case IDA_MONTH_PANEL_CONTEXT_MENU_EDIT:
887                         if (__pPm->IsEditableAllEvent(*pEvent))
888                         {
889                                 __pThreeButtonPopup->RequestPopup(THREE_BUTTON_POPUP_STYLE_EDIT, this, pEvent);
890                         }
891                         else
892                         {
893                                 LinkedList* pArgs = new (std::nothrow) LinkedList(SingleObjectDeleter);
894                                 pArgs->Add(new (std::nothrow) CalEventInstance(*pEvent));
895                                 pArgs->Add(new (std::nothrow) Boolean(true));
896                                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_EDITOR,
897                                                                                                                                                           SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
898                         }
899                         break;
900                 case IDA_MONTH_PANEL_CONTEXT_MENU_SHARE:
901                         __pSharePopup->RequestShare(pEvent->GetOriginalEventId());
902                         break;
903                 case IDA_MONTH_PANEL_CONTEXT_MENU_DELETE:
904                         if (pEvent->IsRecurring())
905                         {
906                                 __pThreeButtonPopup->RequestPopup(THREE_BUTTON_POPUP_STYLE_DELETE, this, pEvent);
907                         }
908                         else
909                         {
910                                 __pTwoButtonPopup->RequestPopup(TWO_BUTTON_POPUP_STYLE_SINGLE_EVENT, this, pEvent);
911                         }
912                         break;
913                 }
914         }
915 }
916
917 void
918 MonthPanel::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
919 {
920
921 }
922
923 void
924 MonthPanel::OnListViewItemReordered(ListView& listView, int indexFrom, int indexTo)
925 {
926
927 }
928
929 int
930 MonthPanel::GetItemCount(void)
931 {
932         return __pPm->GetWholeEventCount(__pPm->GetCurrentDate());
933 }
934
935 ListItemBase*
936 MonthPanel::CreateItem(int index, int itemWidth)
937 {
938         const CalEventInstance* pEvent = __pPm->GetEventWithWholeIndex(__pPm->GetCurrentDate(), index);
939         if (pEvent == null)
940         {
941                 return null;
942         }
943
944         EventItem* pItem = new (std::nothrow) EventItem();
945         pItem->Initialize(EVENT_ITEM_STYLE_NORMAL, itemWidth);
946         pItem->SetTitle(pEvent->GetSubject());
947         pItem->SetCalendarColor(__pPm->GetCalendarColor(pEvent->GetCalendarId()));
948         pItem->SetLocation(pEvent->GetLocation());
949         if (pEvent->IsAllDayEvent() == true)
950         {
951                 pItem->SetAllDayEvent();
952         }
953         else
954         {
955                 DateTime startTime = ResourceManager::ConvertUtcTimeToWallTime(pEvent->GetStartTime());
956                 DateTime endTime = ResourceManager::ConvertUtcTimeToWallTime(pEvent->GetEndTime());
957                 pItem->SetDateRange(startTime, endTime, __pPm->GetCurrentDate(), __pPm->GetTimeFormatter());
958         }
959         pItem->SetReminder(pEvent->HasReminder());
960         pItem->SetRepeat(pEvent->IsRecurring());
961         pItem->SetPriority(pEvent->GetPriority());
962         pItem->UpdateElements();
963
964         pItem->SetContextItem((pEvent->GetCalendarId() == ID_DEFAULT_BIRTHDAY_CALENDAR) ? __pContextItemNoEdit : __pContextItem);
965         return pItem;
966 }
967
968 bool
969 MonthPanel::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
970 {
971         delete pItem;
972         return true;
973 }
974
975 void
976 MonthPanel::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
977 {
978         AppLogDebug("Enter.");
979         if (pArgs != null)
980         {
981                 pArgs->RemoveAll(true);
982                 delete pArgs;
983         }
984
985         __pPm->SetViewType(VIEW_TYPE_MONTHLY);
986         MonthCalendarPanel* pCurrent = static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT]);
987         if (pCurrent->GetDate().GetYear() == __pPm->GetCurrentYear() && pCurrent->GetDate().GetMonth() == __pPm->GetCurrentMonth())
988         {
989                 pCurrent->UpdateEvent();
990                 __pListViewEvent->UpdateList();
991         }
992
993         DateTime maxDateTime = Calendarbook::GetMaxDateTime();
994         maxDateTime.AddYears(-1);
995         DateTime minDateTime = Calendarbook::GetMinDateTime();
996         minDateTime.AddYears(1);
997         for (int i = VIEW_SCROLL_EFFECT_NEXT; i < VIEW_SCROLL_EFFECT_COUNT; ++i)
998         {
999                 if (__pPanelMonthCalendar[i] == null)
1000                 {
1001                         MonthCalendarPanel* pPanel = new (std::nothrow) MonthCalendarPanel();
1002                         DateTime date = __pPm->GetCurrentDate();
1003                         switch (i)
1004                         {
1005                         case VIEW_SCROLL_EFFECT_NEXT:
1006                                 date.AddMonths(1);
1007                                 if (date > maxDateTime)
1008                                 {
1009                                         DateTime minDate = minDateTime;
1010                                         date.SetValue(minDate.GetYear(), minDate.GetMonth(), date.GetDay(), date.GetHour(), date.GetMinute());
1011                                 }
1012                                 pPanel->Initialize(Rectangle(0, Y_CALENDAR, GetWidth(), GetHeight()), date, *__pPm);
1013                                 break;
1014                         case VIEW_SCROLL_EFFECT_PREVIEW:
1015                                 date.AddMonths(-1);
1016                                 if (date < minDateTime)
1017                                 {
1018                                         DateTime maxDate = maxDateTime;
1019                                         date.SetValue(maxDate.GetYear(), maxDate.GetMonth(), date.GetDay(), date.GetHour(), date.GetMinute());
1020                                 }
1021                                 pPanel->Initialize(Rectangle(0, Y_CALENDAR, GetWidth(), GetHeight()), date, *__pPm);
1022                                 break;
1023                         }
1024                         __pPanningAnimationManager->AddView(*pPanel, (ViewScrollEffect)i);
1025                         pPanel->SetDateFocusEventListener(*this);
1026                         __pPanelMonthCalendar[i] = pPanel;
1027                 }
1028                 else
1029                 {
1030                         static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[i])->UpdateEvent();
1031                 }
1032         }
1033
1034         __pPanningAnimationManager->ResetPosition();
1035         Update(true);
1036
1037         __pPm->AddCalendarEventChangedEventListener(*this);
1038         __pPm->AddCurrentDateChangedEventListener(*this);
1039         AppLogDebug("Exit.");
1040 }
1041
1042 void
1043 MonthPanel::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
1044 {
1045         AppLogDebug("Enter.");
1046         __pPm->RemoveCalendarEventChangedEventListener(*this);
1047         __pPm->RemoveCurrentDateChangedEventListener(*this);
1048
1049         if (nextSceneId == IDSCN_YEAR || nextSceneId == IDSCN_DAY || nextSceneId == IDSCN_LIST)
1050         {
1051                 __pPanningAnimationManager->RemoveView(VIEW_SCROLL_EFFECT_NEXT);
1052                 __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT] = null;
1053                 __pPanningAnimationManager->RemoveView(VIEW_SCROLL_EFFECT_PREVIEW);
1054                 __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW] = null;
1055         }
1056         AppLogDebug("Exit.");
1057 }
1058
1059 void
1060 MonthPanel::OnCalendarEventChanged(void)
1061 {
1062         AppLogDebug("Enter.");
1063         static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT])->UpdateEvent();
1064         static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT])->UpdateEvent();
1065         static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW])->UpdateEvent();
1066         __pListViewEvent->UpdateList();
1067         AppLogDebug("Exit.");
1068 }
1069
1070 void
1071 MonthPanel::OnCurrentDateChanged(const DateTime& currentDate, const DateTime& prevDate)
1072 {
1073         AppLogDebug("Enter.");
1074         DateTime currentCalendarDate = static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT])->GetDate();
1075         Update(currentDate.GetYear() != currentCalendarDate.GetYear() || currentDate.GetMonth() != currentCalendarDate.GetMonth());
1076         AppLogDebug("Exit.");
1077 }
1078
1079 void
1080 MonthPanel::OnDateFocused(const DateTime& focusedDate)
1081 {
1082         DateTime adjustFocusedDate = focusedDate;
1083         adjustFocusedDate.AddMonths(__pPm->GetCurrentMonth() - adjustFocusedDate.GetMonth());
1084         __pPm->SetCurrentDate(adjustFocusedDate);
1085         __pListViewEvent->UpdateList();
1086 }
1087
1088 Control*
1089 MonthPanel::GetCurrentControl(void)
1090 {
1091         return __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT];
1092 }
1093
1094 Control*
1095 MonthPanel::GetNextControl(void)
1096 {
1097         return __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT];
1098 }
1099
1100 Control*
1101 MonthPanel::GetPreviewControl(void)
1102 {
1103         return __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW];
1104 }
1105
1106 void
1107 MonthPanel::OnPanningAnimationEnded(ViewScrollEffect direction)
1108 {
1109         DateTime maxDateTime = Calendarbook::GetMaxDateTime();
1110         maxDateTime.AddYears(-1);
1111         DateTime minDateTime = Calendarbook::GetMinDateTime();
1112         minDateTime.AddYears(1);
1113         if (__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT] != null && __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW] != null)
1114         {
1115                 if (direction == VIEW_SCROLL_EFFECT_PREVIEW)
1116                 {
1117                         MonthCalendarPanel* pPanel = static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT]);
1118                         DateTime date = static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW])->GetDate();
1119                         date.AddMonths(-1);
1120                         if (date < minDateTime)
1121                         {
1122                                 DateTime maxDate = maxDateTime;
1123                                 date.SetValue(maxDate.GetYear(), maxDate.GetMonth(), date.GetDay(), date.GetHour(), date.GetMinute());
1124                         }
1125                         pPanel->SetDate(date);
1126                         pPanel->RequestRedraw(false);
1127
1128                         __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT] = __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT];
1129                         __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT] = __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW];
1130                         __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW] = pPanel;
1131
1132                         static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT])->SetFocusEnabled(false);
1133                         static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT])->SetFocusEnabled(true);
1134                 }
1135                 else if (direction == VIEW_SCROLL_EFFECT_NEXT)
1136                 {
1137                         MonthCalendarPanel* pPanel = static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW]);
1138                         DateTime date = static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT])->GetDate();
1139                         date.AddMonths(1);
1140                         if (date > maxDateTime)
1141                         {
1142                                 DateTime minDate = minDateTime;
1143                                 date.SetValue(minDate.GetYear(), minDate.GetMonth(), date.GetDay(), date.GetHour(), date.GetMinute());
1144                         }
1145                         pPanel->SetDate(date);
1146                         pPanel->RequestRedraw(false);
1147
1148                         __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW] = __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT];
1149                         __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT] = __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT];
1150                         __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT] = pPanel;
1151
1152                         static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW])->SetFocusEnabled(false);
1153                         static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT])->SetFocusEnabled(true);
1154                 }
1155                 __pPm->SetCurrentDate(static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT])->GetDate());
1156                 __pListViewEvent->UpdateList();
1157         }
1158 }
1159
1160 void
1161 MonthPanel::DrawCalendar(void)
1162 {
1163         MonthCalendarPanel* pCurrent = static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT]);
1164         DateTime current = pCurrent->GetDate();
1165         pCurrent->SetDate(__pPm->GetCurrentDate());
1166         pCurrent->SetSize(pCurrent->GetWidth(), pCurrent->GetViewHeight());
1167
1168         int height = GetHeight() - Y_CALENDAR - pCurrent->GetHeight();
1169         if (__pListViewEvent->GetHeight() != height)
1170         {
1171                 __pListViewEvent->SetBounds(0, GetHeight() - height, GetWidth(), height);
1172         }
1173         if (EventListPresentationModel::IsSameDay(current, __pPm->GetCurrentDate()) == false)
1174         {
1175                 __pListViewEvent->UpdateList();
1176         }
1177
1178         DateTime maxDateTime = Calendarbook::GetMaxDateTime();
1179         maxDateTime.AddYears(-1);
1180         DateTime minDateTime = Calendarbook::GetMinDateTime();
1181         minDateTime.AddYears(1);
1182         MonthCalendarPanel* pNextPanel = static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT]);
1183         if (pNextPanel != null)
1184         {
1185                 DateTime nextDate = __pPm->GetCurrentDate();
1186                 nextDate.AddMonths(1);
1187                 if (nextDate > maxDateTime)
1188                 {
1189                         DateTime minDate = minDateTime;
1190                         nextDate.SetValue(minDate.GetYear(), minDate.GetMonth(), nextDate.GetDay(), nextDate.GetHour(), nextDate.GetMinute());
1191                 }
1192                 pNextPanel->SetDate(nextDate);
1193                 pNextPanel->SetSize(pNextPanel->GetWidth(), pCurrent->GetHeight());
1194         }
1195
1196         MonthCalendarPanel* pPrevPanel = static_cast<MonthCalendarPanel*>(__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW]);
1197         if (pPrevPanel != null)
1198         {
1199                 DateTime prevDate = __pPm->GetCurrentDate();
1200                 prevDate.AddMonths(-1);
1201                 if (prevDate < minDateTime)
1202                 {
1203                         DateTime maxDate = maxDateTime;
1204                         prevDate.SetValue(maxDate.GetYear(), maxDate.GetMonth(), prevDate.GetDay(), prevDate.GetHour(), prevDate.GetMinute());
1205                 }
1206                 pPrevPanel->SetDate(prevDate);
1207                 pPrevPanel->SetSize(pPrevPanel->GetWidth(), pCurrent->GetHeight());
1208         }
1209 }
1210
1211 void
1212 MonthPanel::DrawCurrentDate(void)
1213 {
1214         Form* pForm = dynamic_cast<Form*>(GetParent());
1215         if (pForm != null)
1216         {
1217                 Header* pHeader = pForm->GetHeader();
1218                 if (pHeader != null)
1219                 {
1220                         pHeader->SetTitleText(__pPm->GetMonthString(__pPm->GetCurrentDate()));
1221                         pHeader->Invalidate(false);
1222                 }
1223         }
1224 }
1225
1226 void
1227 MonthPanel::Update(bool draw)
1228 {
1229         DrawCurrentDate();
1230         DrawCalendar();
1231
1232         if (draw == true)
1233         {
1234                 __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_CURRENT]->Invalidate(true);
1235                 if (__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT] != null)
1236                 {
1237                         __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_NEXT]->RequestRedraw(false);
1238                 }
1239                 if (__pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW] != null)
1240                 {
1241                         __pPanelMonthCalendar[VIEW_SCROLL_EFFECT_PREVIEW]->RequestRedraw(false);
1242                 }
1243         }
1244 }