/********************************************************************
created: 2007/04/22
created: 22:4:2007 11:25
filename: ScheDatePage.c
file path: e:\brew program\schedule
file base: ScheDatePage
file ext: c
author: fhong
purpose:
*********************************************************************/
#include "ScheDatePage.h "
/*===============================================================================
Function Definitions
=============================================================================== */
//////////////////////////////////////////////////////////////////////////
//Public function declaration
//////////////////////////////////////////////////////////////////////////
extern int ScheDatePage_Init(IShell* pIShell,PageStateMgr* pPageStateMgr,BasePage** ppBasePage,uint32 nPageID)
{
int retVal = SUCCESS; // The return value.
ScheDatePage* pScheDatePage = NULL; // The page object.
// Input check.
//if( (NULL == pIShell) || (NULL == ppBasePage) ){}
// Create base class
retVal = BasePage_Init( pIShell, pPageStateMgr, (BasePage**)&pScheDatePage, sizeof(ScheDatePage), nPageID );
//if( (SUCCESS != retVal) || (NULL == pScheDatePage) ){}
// Initializing m_pMyDate
MyDate_Init( pScheDatePage, &pScheDatePage->m_pMyDate );
// Initializa local variable.
pScheDatePage->m_basePage.m_pfnPageDraw = ScheDatePage_Draw;
pScheDatePage->m_basePage.m_pfnHandleEvent = ScheDatePage_HandleEvent;
pScheDatePage->m_basePage.m_pfnRelease = ScheDatePage_Release;
if( SUCCESS != retVal )
{
if( NULL != pScheDatePage )
{
BasePage_Release( (BasePage*)pScheDatePage );
}
pScheDatePage = NULL;
}
*ppBasePage = (BasePage*)pScheDatePage;
return retVal;
}
//////////////////////////////////////////////////////////////////////////
extern int ScheDatePage_HandleEvent(BasePage* pBasePage,AEEEvent eCode,uint16 wParam,uint32 dwParam)
{
int retVal = SUCCESS; // The return value.
// Input check.
//if( NULL == pBasePage ){}
ScheDatePage* pScheDatePage = (ScheDatePage*)pBasePage; // The ScheDatePage object.
//AEERect rect ;
switch( eCode )
{
case EVT_KEY:
switch(wParam)
{
case AVK_SOFT1:
MEMSET( &pScheDatePage->m_basePage.m_pPageStateMgr->m_selDate,0,sizeof(pScheDatePage->m_basePage.m_pPageStateMgr->m_selDate) );
retVal = PageStateMgr_OpenNextPage( pScheDatePage->m_basePage.m_pPageStateMgr, SCHE_MENU_PAGE);
break;
case AVK_SOFT2:
PageStateMgr_CloseCurrentPage( pScheDatePage->m_basePage.m_pPageStateMgr ) ;
return NO_PICTURE ;
//retVal = ISHELL_CloseApplet( pScheDatePage->m_basePage.m_pIShell, FALSE );
break;
case AVK_SELECT:
//to do
{
retVal = GetCursorDate(pScheDatePage);
retVal = PageStateMgr_OpenNextPage( pScheDatePage->m_basePage.m_pPageStateMgr, SCHE_VIEW_EVT_PAGE);
}
break;
case AVK_1:
MyDate_GetWeekDay( pScheDatePage->m_pMyDate, 1940, 1, 6 ) ;
default:
MyDate_HandleEvent( pScheDatePage->m_pMyDate, eCode, wParam, dwParam ) ;
// SETAEERECT( &rect, 0, 0, 0, 0 ) ;
BasePage_BottomTip( &pScheDatePage->m_basePage, NULL, OPTION_BACK, 0 );
break;
}
break;
default:
break;
}
return retVal;
}
//////////////////////////////////////////////////////////////////////////
extern int ScheDatePage_Draw(BasePage* pBasePage)
{
int retVal = SUCCESS; // The return value.
// Input check.
//if( NULL == pBasePage ) {}
ScheDatePage* pScheDatePage = (ScheDatePage*)pBasePage; // The page object.
AEERect rect;
JulianType rJulianDate = { 0 } ;
rect.x=0;
rect.y=14;
rect.dx=pScheDatePage->m_basePage.m_DeviceInfo.cxScreen;
rect.dy=pScheDatePage->m_basePage.m_DeviceInfo.cyScreen-25;
pScheDatePage->m_basePage.m_backRGB = MAKE_RGB( 255, 255, 255 ) ;
pScheDatePage->m_basePage.m_selBackRGB = MAKE_RGB( 50, 50, 50 ) ;
IDISPLAY_ClearScreen( pScheDatePage->m_basePage.m_pIDisplay );
MyDate_Draw( pScheDatePage->m_pMyDate, &rect, NULL );
BasePage_BottomTip( &pScheDatePage->m_basePage, NULL, OPTION_BACK, 0 );
return retVal;
}
//////////////////////////////////////////////////////////////////////////
extern void ScheDatePage_Release(BasePage* pBasePage)
{
ScheDatePage* pScheDatePage = (ScheDatePage*)pBasePage;
if ( NULL == pScheDatePage )
{
return ;
}
else
{
MyDate_Release( pScheDatePage->m_pMyDate ) ;
}
return ;
}
//////////////////////////////////////////////////////////////////////////
/*===============================================================================
Private function definition
=============================================================================== */
//////////////////////////////////////////////////////////////////////////
static int GetCursorDate(ScheDatePage *pMe)
{
int retVal = SUCCESS;
Date date ;
char strDate[10] = {0};
AECHAR dateBuffer[10] = {0};
AECHAR buffer[10] = {0};
AECHAR ch[2] = {'0','\0'};
MyDate_GetCursorDate( pMe->m_pMyDate, &date ) ;
pMe->m_basePage.m_pPageStateMgr->m_selDate.m_year = date.m_year ;
pMe->m_basePage.m_pPageStateMgr->m_selDate.m_month = date.m_month ;
pMe->m_basePage.m_pPageStateMgr->m_selDate.m_day = date.m_day ;
return retVal;
}
//////////////////////////////////////////////////////////////////////////
/*===========================================================================================================
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MyDate Control function definition
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
============================================================================================================*/
//////////////////////////////////////////////////////////////////////////
//Public function difinition
//////////////////////////////////////////////////////////////////////////
int MyDate_Init( ScheDatePage* pMe, MyDate** ppMyDate )
{
int retVal = FALSE;
// Input check
MyDate* pMyDate = NULL;
JulianType rJulianDate ;
// Malloc the memory for pMyDate
pMyDate = ( MyDate* )MALLOC( sizeof( MyDate ) );
// Initializing DeviceInfo
pMyDate->m_DeviceInfo = pMe->m_basePage.m_DeviceInfo;
// Initializing IShell
pMyDate->m_pIShell = pMe->m_basePage.m_pIShell;
// Initializing IDisplay
pMyDate->m_pIDisplay = pMe->m_basePage.m_pIDisplay ;
//retVal = ISHELL_CreateInstance( pMe->a.m_pIShell, AEECLSID_DISPLAY, ( void** )&pMyDate->m_pIDisplay );
GETJULIANDATE( 0, &rJulianDate ) ;
// Initializing m_absoluteDate and m_cursorDate
MyDate_SetDate( pMyDate, rJulianDate.wYear, rJulianDate.wMonth, rJulianDate.wDay ) ;
//MyDate_SetDate( pMyDate, rJulianDate.wYear, rJulianDate.wMonth, rJulianDate.wDay ) ;
DataStorage_Init( pMyDate->m_pIShell, &pMyDate->m_pDataSorage ) ;
*ppMyDate = pMyDate;
return retVal;
}
//////////////////////////////////////////////////////////////////////////
int MyDate_Draw( MyDate* pMyDate, AEERect* pRect, IImage* pImage )
{
int retVal = FALSE;
uint16 year = pMyDate->m_cursorDate.m_year ;
uint16 month = pMyDate->m_cursorDate.m_month ;
uint16 day = pMyDate->m_cursorDate.m_day ;
AEERect rect = {0};
IDISPLAY_ClearScreen( pMyDate->m_pIDisplay );
//Draw year and month
SETAEERECT( &rect, 0, 0, 128, 20 );
MyDate_DrawYearMonth( pMyDate, &rect, year, month ) ;
// //Draw lunar calendar
// SETAEERECT( &rect, pRect->x, pRect->y, pRect->dx, pRect->dy ) ;
// MyDate_DrawLunar( pMyDate, &rect ) ;
//Draw week
SETAEERECT( &rect, 0, 20, 128, 20 );
MyDate_DrawWeek( pMyDate, &rect ) ;
//Draw horizontal line
IDISPLAY_DrawHLine( pMyDate->m_pIDisplay, 0, 35, 128 ) ;
//Draw all days of the specific month
SETAEERECT( &rect, 0, 40, 128, 100 );
MyDate_SignEvtOfAMonth( pMyDate,