1、 屏幕显示区域为128*160;
2、 屏幕显示区域包括年、月,日、星期;
3、 使用四个方向键(上、下、左、右)、*键、#键和返回键,上键表示向上移动,下键表示向下移动,左键表示向左移动,右键表示向右移动,*键表示显示前一个月份的日历,#键表示显示后一个月份的日历,返回键表示退出。
4、 显示完整的单个月份的日历表。
5、 日历只为阳历,但是对应具体的日期,显示该如期的阴历。
6、 日历表功能
l 进入日历表,光标指示系统当前年月日;
l 四个方向键可控制光标移动到所要指示的年月日;
l 遵循日历的基本规则;如闰年和平年的日历的不同;
l 循环实现当光标向无日期区域移动时显示当前月份的下个月份或前个月份的日历表,或光标上移一行、下移一行。
l *键、#键循环实现显示当前月份的前个月份或下个月份的日历表。
----------------------------------------------------------------------------------------------------------------------
/*****************************************************************************
** File Name: mmicalendar_main.h
** Author: mark.hu
** Date: 2005/0907
** Copyright: 2003 Spreatrum, Incoporated. All Rights Reserved. *
** Description: This file is used to describe calendar *
******************************************************************************
** Important Edit History *
** --------------------------------------------------------------------------*
** DATE NAME DESCRIPTION *
** 2005/09/07 mark.hu Create *
******************************************************************************/
//#define _MMICALENDAR_MAIN_H_
/**--------------------------------------------------------------------------*
** Include Files *
**--------------------------------------------------------------------------*/
#include "window_parse.h"
#include "win.def"
#include "mmk_app.h"
#include "mmi_text.h"
#include "sci_types.h"
#include "mmicalendar_main.h"
#include "guisoftkey.h"
#include "guilcd.h"
#include "mmidisplay_data.h"
#include "guicalendar.h"
#include "guifont.h"
#include "mmi_theme.h"
#include "mmiset.h"
#ifdef _SMMI_UNIT_TEST_
#define LOCAL
#else
#define LOCAL static
#endif
/**--------------------------------------------------------------------------*
** MACRO DEFINITION *
**--------------------------------------------------------------------------*/
#define WEEKDAY_NUM 7 //一周的天数
#define DATE_LENGTH 2 //日期(1~31)的长度
#define YEAR_BOTTOM 1980 //最早年份
#define YEAR_TOP 2040 //最晚年份
#define LINENUM 6 //日历上显示日期的行数
#define COLNUM 7 //日历上显示日期的列数
#define MONTHNUM 12 //一年的月数
#define DECEMBER 12 //十二月
//定义标题栏的位置和高度added by yujiang
#define CALENDAR_TITLE_LEFT
0 //X
#define CALENDAR_TITLE_TOP
0 //Y
#define CALENDAR_TITLE_HIGH
32
#define CALENDAR_TITLE_LENGTH
128
#define CALENDAR_DATENUMBER_SHOW_HIGH
15 //根据数字大小来调整
#define CALENDAR_DATENUMBER_SHOW_LENGTH
18
/**--------------------------------------------------------------------------*
** TYPE AND STRUCT *
**--------------------------------------------------------------------------*/
typedef enum
{
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
};
/**--------------------------------------------------------------------------*
** EXTERNAL DECLARE *
**--------------------------------------------------------------------------*/
extern const GUI_TEXT_E s_gui_calendar_weekday_name[WEEKDAY_NUM];
extern uint8 g_ksp_Lang; //当前的语言类型
/**--------------------------------------------------------------------------*
** STATIC DEFINITION *
**--------------------------------------------------------------------------*/
//非闰年,假设1月1日是周日,s_gui_calendar_first_day[i]对应每月1日的星期
LOCAL const uint8 s_gui_calendar_first_day[MONTHNUM] = {0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5};
//闰年,假设1月1日是周日,s_gui_calendar_first_day_leap[i]对应每月1日的星期
LOCAL const uint8 s_gui_calendar_first_day_leap[MONTHNUM] = {0, 3, 4, 0, 2, 5, 0, 3, 6, 1, 4, 6};
//非闰年,s_gui_calendar_month_day[i]对应每月的天数
LOCAL const uint8 s_gui_calendar_month_day[MONTHNUM] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//闰年,s_gui_calendar_month_day_leap[i]对应每月的天数
LOCAL const uint8 s_gui_calendar_month_day_leap[MONTHNUM] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
LOCAL const GUI_POINT_T s_calendar_position[LINENUM][COLNUM] =
{
{{1,50}, {19,50}, {37,50}, {55,50}, {73,50}, {91,50}, {109,50}},
{{1,65}, {19,65}, {37,65}, {55,65}, {73,65}, {91,65}, {109,65}},
{{1,80}, {19,80}, {37,80}, {55,80}, {73,80}, {91,80}, {109,80}},
{{1,95}, {19,95}, {37,95}, {55,95}, {73,95}, {91,95}, {109,95}},
{{1,110},{19,110},{37,110},{55,110},{73,110},{91,110},{109,110}},
{{1,125},{19,125},{37,125},{55,125},{73,125},{91,125},{109,125}}
};
/**-------------------------------------------------------------------------------------------------------------------------------------**
my add
**--------------------------------------------------------------------------------------------------------------------------------------**/
unsigned int LunarCalendarDay;
unsigned int LunarCalendarTable[199] = {
0x04AE53,0x0A5748,0x5526BD,0x0D2650,0x0D9544,0x46AAB9,0x056A4D,0x09AD42,0x24AEB6,0x04AE4A,/*1901-1910*/
0x6A4DBE,0x0A4D52,0x0D2546,0x5D52BA,0x0B544E,0x0D6A43,0x296D37,0x095B4B,0x749BC1,0x049754,/*1911-1920*/
0x0A4B48,0x5B25BC,0x06A550,0x06D445,0x4ADAB8,0x02B64D,0x095742,0x2497B7,0x04974A,0x664B3E,/*1921-1930*/
0x0D4A51,0x0EA546,0x56D4BA,0x05AD4E,0x02B644,0x393738,0x092E4B,0x7C96BF,0x0C9553,0x0D4A48,/*1931-1940*/
0x6DA53B,0x0B554F,0x056A45,0x4AADB9,0x025D4D,0x092D42,0x2C95B6,0x0A954A,0x7B4ABD,0x06CA51,/*1941-1950*/
0x0B5546,0x555ABB,0x04DA4E,0x0A5B43,0x352BB8,0x052B4C,0x8A953F,0x0E9552,0x06AA48,0x6AD53C,/*1951-1960*/
0x0AB54F,0x04B645,0x4A5739,0x0A574D,0x052642,0x3E9335,0x0D9549,0x75AABE,0x056A51,0x096D46,/*1961-1970*/
0x54AEBB,0x04AD4F,0x0A4D43,0x4D26B7,0x0D254B,0x8D52BF,0x0B5452,0x0B6A47,0x696D3C,0x095B50,/*1971-1980*/
0x049B45,0x4A4BB9,0x0A4B4D,0xAB25C2,0x06A554,0x06D449,0x6ADA3D,0x0AB651,0x093746,0x5497BB,/*1981-1990*/
0x04974F,0x064B44,0x36A537,0x0EA54A,0x86B2BF,0x05AC53,0x0AB647,0x5936BC,0x092E50,0x0C9645,/*1991-2000*/
0x4D4AB8,0x0D4A4C,0x0DA541,0x25AAB6,0x056A49,0x7AADBD,0x025D52,0x092D47,0x5C95BA,0x0A954E,/*2001-2010*/
0x0B4A43,0x4B5537,0x0AD54A,0x955ABF,0x04BA53,0x0A5B48,0x652BBC,0x052B50,0x0A9345,0x474AB9,/*2011-2020*/
0x06AA4C,0x0AD541,0x24DAB6,0x04B64A,0x69573D,0x0A4E51,0x0D2646,0x5E933A,0x0D534D,0x05AA43,/*2021-2030*/
0x36B537,0x096D4B,0xB4AEBF,0x04AD53,0x0A4D48,0x6D25BC,0x0D254F,0x0D5244,0x5DAA38,0x0B5A4C,/*2031-2040*/
0x056D41,0x24ADB6,0x049B4A,0x7A4BBE,0x0A4B51,0x0AA546,0x5B52BA,0x06D24E,0x0ADA42,0x355B37,/*2041-2050*/
0x09374B,0x8497C1,0x049753,0x064B48,0x66A53C,0x0EA54F,0x06B244,0x4AB638,0x0AAE4C,0x092E42,/*2051-2060*/
0x3C9735,0x0C9649,0x7D4ABD,0x0D4A51,0x0DA545,0x55AABA,0x056A4E,0x0A6D43,0x452EB7,0x052D4B,/*2061-2070*/
0x8A95BF,0x0A9553,0x0B4A47,0x6B553B,0x0AD54F,0x055A45,0x4A5D38,0x0A5B4C,0x052B42,0x3A93B6,/*2071-2080*/
0x069349,0x7729BD,0x06AA51,0x0AD546,0x54DABA,0x04B64E,0x0A5743,0x452738,0x0D264A,0x8E933E,/*2081-2090*/
0x0D5252,0x0DAA47,0x66B53B,0x056D4F,0x04AE45,0x4A4EB9,0x0A4D4C,0x0D1541,0x2D92B5/*2091-2099*/
};
int MonthAdd[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
/**--------------------------------------------------------------------------*
** GLOBAL DEFINITION *
**--------------------------------------------------------------------------*/
GUI_CALENDAR_CTRL_T g_calendar_show;
/*---------------------------------------------------------------------------*/
/* LOCAL FUNCTION DECLARE */
/*---------------------------------------------------------------------------*/
/*****************************************************************************/
// Description : 日历控件的消息处理
// Global resource dependence :
// Author: Mark.hu
// Note:
/*****************************************************************************/
LOCAL MMI_RESULT_E HandleCalendarWinMsg(
MMI_WINDOW_ID_E win_id,
MMI_MESSAGE_ID_E msg_id,
DPARAM param
);
/*****************************************************************************/
// Description :阳历转换成农历
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL int LunarCalendar(int year,int month,int day);
/*****************************************************************************/
// Description :画农历
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_DrawLunarDate(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr);
/*****************************************************************************/
// Description : 计算某年是否为闰年
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL BOOLEAN MainCALENDAR_IsLeapYear(uint16 year);
/*****************************************************************************/
// Description : 计算某年某月有几天
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL uint8 MainCALENDAR_GetMonthday( uint16 solar_year,uint8 solar_month);
/*****************************************************************************/
// Description : 画日历的年月标题
// Global resource dependence :
// Author: Mark.hu
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_DrawYearMonthTitle(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr);
/*****************************************************************************/
// Description : 画日历的日期
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_DrawDate(GUI_CALENDAR_CTRL_T *calendar_ctrl_ptr);
/*****************************************************************************/
// Description : 画日历
// Global resource dependence :
// Author: Mark.hu
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_DrawCalendar(GUI_CALENDAR_CTRL_T *calendar_ctrl_ptr);
/*****************************************************************************/
// Description : 移到上月
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_MovePrevMonth(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr);
/*****************************************************************************/
// Description : 移到下月
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_MoveNextMonth(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr);
/*****************************************************************************/
// Description : 移到前一天
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_MovePrevDay(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr);
/*****************************************************************************/
// Description : 移到后一天
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_MoveNextDay(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr);
/*****************************************************************************/
// Description : 移到上一行
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_MoveUpLineDay(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr);
/*****************************************************************************/
// Description : 移到下一行
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_MoveDownLineDay(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr);
/*****************************************************************************/
// Description : 日历控件按键的辅助处理
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_HandleCalendarKey(
GUI_CALENDAR_CTRL_T*
calendar_ctrl_ptr,
uint16
msg_id
);
/*******************************************************************************************/
//
Description : 计算calendar的rect
//
Global resource dependence :
// Author: Mark.hu
//
Note:
/*********************************************************************************************/
LOCAL void MainCALENDAR_CalCalendarRect(GUI_CALENDAR_CTRL_T* calendar_ptr);
/*******************************************************************************************/
//
Description : 设置默认的calendar风格
//
Global resource dependence :
// Author: bin.ji
//
Note:
/*********************************************************************************************/
LOCAL void MainCALENDAR_SetDefaultCalendarStyle(GUI_CALENDAR_CTRL_T* calendar_ptr);
WINDOW_TABLE(CALENDAR_WIN_TAB) =
{
CLEAR_LCD,
WIN_PRIO(WIN_ONE_LEVEL),
WIN_FUNC((uint32)HandleCalendarWinMsg),
WIN_ID(MMICALENDAR_WIN_ID),
END_WIN
};
/**--------------------------------------------------------------------------*
** FUNCTION DEFINITION *
**--------------------------------------------------------------------------*/
/*****************************************************************************/
// Description :阳历转换成农历
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL int LunarCalendar(int year,int month,int day)
{
//栽自网上,代码是位运算,过程十分复杂。
int Spring_NY,Sun_NY,StaticDayCount;
int index,flag;
//Spring_NY 记录春节离当年元旦的天数。
//Sun_NY 记录阳历日离当年元旦的天数。
if( ((LunarCalendarTable[year-1901] & 0x0060) >> 5) == 1)
Spring_NY = (LunarCalendarTable[year-1901] & 0x001F) - 1;
else
Spring_NY = (LunarCalendarTable[year-1901] & 0x001F) - 1 + 31;
Sun_NY = MonthAdd[month-1] + day - 1;
if( (!(year % 4)) && (month > 2))
Sun_NY++;
//StaticDayCount记录大小月的天数 29 或30
//index 记录从哪个月开始来计算。
//flag 是用来对闰月的特殊处理。
//判断阳历日在春节前还是春节后
if (Sun_NY >= Spring_NY)//阳历日在春节后(含春节那天)
{
Sun_NY -= Spring_NY;
month = 1;
index = 1;
flag = 0;
if( ( LunarCalendarTable[year - 1901] & (0x80000 >> (index-1)) ) ==0)
StaticDayCount = 29;
else
StaticDayCount = 30;
while(Sun_NY >= StaticDayCount)
{
Sun_NY -= StaticDayCount;
index++;
if(month == ((LunarCalendarTable[year - 1901] & 0xF00000) >> 20) )
{
flag = ~flag;
if(flag == 0)
month++;
}
else
month++;
if( ( LunarCalendarTable[year - 1901] & (0x80000 >> (index-1)) ) ==0)
StaticDayCount=29;
else
StaticDayCount=30;
}
day = Sun_NY + 1;
}
else//阳历日在春节前
{
Spring_NY -= Sun_NY;
year--;
month = 12;
if ( ((LunarCalendarTable[year - 1901] & 0xF00000) >> 20) == 0)
index = 12;
else
index = 13;
flag = 0;
if( ( LunarCalendarTable[year - 1901] & (0x80000 >> (index-1)) ) ==0)
StaticDayCount = 29;
else
StaticDayCount = 30;
while(Spring_NY > StaticDayCount)
{
Spring_NY -= StaticDayCount;
index--;
if(flag == 0)
month--;
if(month == ((LunarCalendarTable[year - 1901] & 0xF00000) >> 20))
flag = ~flag;
if( ( LunarCalendarTable[year - 1901] & (0x80000 >> (index-1)) ) ==0)
StaticDayCount = 29;
else
StaticDayCount = 30;
}
day = StaticDayCount - Spring_NY + 1;
}
LunarCalendarDay |= day;
LunarCalendarDay |= (month << 6);
if(month == ((LunarCalendarTable[year - 1901] & 0xF00000) >> 20))
return 1;
else
return 0;
}
/*****************************************************************************/
// Description :画农历
// Global resource dependence :
// Author: Jibin
// Note: test be default
/*****************************************************************************/
/*LOCAL void MainCALENDAR_DrawLunarDate(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr)
{
const char *ChDay[] = {"*","初一","初二","初三","初四","初五",
"初六","初七","初八","初九","初十",
"十一","十二","十三","十四","十五",
"十六","十七","十八","十九","二十",
"廿一","廿二","廿三","廿四","廿五",
"廿六","廿七","廿八","廿九","三十"};
const char *ChMonth[] = {"*","正","二","三","四","五","六","七","八","九","十","十一","腊"};
GUI_RECT_T rect = {30,
125,
190,
140
};
uint8 title_str[25];
int year = (int)calendar_ctrl_ptr->solar_year;
int month = (int)calendar_ctrl_ptr->solar_month;
int day = (int)calendar_ctrl_ptr->solar_date;
char str[13] = "";
if(LunarCalendar(year,month,day))
{
strcat(str,"闰");
strcat(str,ChMonth[(LunarCalendarDay & 0x3C0) >> 6]);
}
else
strcat(str,ChMonth[(LunarCalendarDay & 0x3C0) >> 6]);
strcat(str,"月");
strcat(str,ChDay[LunarCalendarDay & 0x3F]);
sprintf((char*)title_str, "%s",str);
LCD_DisplayStringByAlign(
MAINLCD_ID,
rect, //the fixed display area
title_str, //string to display
(uint16)strlen((char*)title_str), //length of string to display
0, //space between two chars.
calendar_ctrl_ptr->title_font_color, //string color
calendar_ctrl_ptr->title_font, //font pointer
FALSE,
ALIGN_HVMIDDLE,
0
);
LunarCalendarDay=0;
}*/
/*****************************************************************************/
// Description : 计算某年是否为闰年
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL BOOLEAN MainCALENDAR_IsLeapYear( uint16 year)
{
BOOLEAN ret_val;
ret_val = (BOOLEAN)((!(year % 4) && (year % 100)) || !(year % 400));
return ret_val;
}
/*****************************************************************************/
// Description : 计算某年某月第一天为星期几
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
uint8 MainCALENDAR_GetFirstday(uint16 solar_year,uint8 solar_month)
{
uint8 ret_val;
uint16 year = (uint16)(solar_year-1);
//等于公元元年到上年12月31日所经过的天数减去年数乘上364的值, 除以7的余数就是那天的星期
uint16 year_plus = (uint16)(year + year/4 - year/100 + year/400);
if (MainCALENDAR_IsLeapYear(solar_year))
{
ret_val = (uint8)(( 1 + s_gui_calendar_first_day_leap[solar_month - 1] + year_plus ) % WEEKDAY_NUM);
}
else
{
ret_val = (uint8)(( 1 + s_gui_calendar_first_day[solar_month - 1] + year_plus ) % WEEKDAY_NUM);
}
return ret_val;
}
/*****************************************************************************/
// Description : 计算某年某月有几天
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL uint8 MainCALENDAR_GetMonthday(uint16 solar_year,uint8 solar_month)
{
uint8 ret_val;
if (MainCALENDAR_IsLeapYear(solar_year))
{
ret_val = s_gui_calendar_month_day_leap[solar_month - 1];
}
else
{
ret_val = s_gui_calendar_month_day[solar_month - 1];
}
return ret_val;
}
/*****************************************************************************/
// Description : 移到上月
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_MovePrevMonth(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr )
{
if(calendar_ctrl_ptr->solar_month==1)
{
calendar_ctrl_ptr->solar_month=12;
calendar_ctrl_ptr->solar_year--;
if(
calendar_ctrl_ptr->solar_data> (MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month)) )
calendar_ctrl_ptr->solar_data==(MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month));
}
else
{
calendar_ctrl_ptr->solar_month--;
if(
calendar_ctrl_ptr->solar_data> (MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month)) )
calendar_ctrl_ptr->solar_data==(MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month));
}
}
/*****************************************************************************/
// Description : 移到下月
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_MoveNextMonth(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr)
{
if(calendar_ctrl_ptr->solar_month==12)
{ calendar_ctrl_ptr->solar_year--;
calendar_ctrl_ptr->solar_month= 1;
if(
calendar_ctrl_ptr->solar_data> (MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month)) )
calendar_ctrl_ptr->solar_data==(MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month));
}
else
{
calendar_ctrl_ptr->solar_month++;
if(
calendar_ctrl_ptr->solar_data> (MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month)) )
calendar_ctrl_ptr->solar_data==(MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month));
}
}
/*****************************************************************************/
// Description : 移到前一天
// Global resource dependence :
// Author: Jibin
// Note: modify by ricezhang have be test ok.
/*****************************************************************************/
LOCAL void MainCALENDAR_MovePrevDay(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr)
{
if(calendar_ctrl_ptr->solar_date ==1)
{ if(calendar_ctrl_ptr->solar_month==1)
{ calendar_ctrl_ptr->solar_year++;
calendar_ctrl_ptr->solar_month=12;
calendar_ctrl_ptr->solar_date=
( MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month));
}
else
{ calendar_ctrl_ptr->solar_month--;
calendar_ctrl_ptr->solar_date= (MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month));
}
}
else
{ calendar_ctrl_ptr->solar_date--;
}
}
// 本人加入上面那段代码后就无法运行,有一大堆不知名错误显示,求大神求解吧!
}
/*****************************************************************************/
// Description : 移到后一天
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_MoveNextDay(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr)
{
if(calendar_ctrl_ptr-> solar_date==(MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month)))
{ if(calendar_ctrl_ptr->solar_month==12)
{ calendar_ctrl_ptr-> solar_date=1;
calendar_ctrl_ptr->solar_month++;
calendar_ctrl_ptr->solar_year++;
}
else
{ calendar_ctrl_ptr-> solar_date=1;
calendar_ctrl_ptr->solar_month++;
}
}
else
{ calendar_ctrl_ptr-> solar_date++;
}
}
/*****************************************************************************/
// Description : 移到上一行
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_MoveUpLineDay(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr)
{
if( calendar_ctrl_ptr->solar_month==1)
{
if(calendar_ctrl_ptr->solar_date-7<=0)
{ calendar_ctrl_ptr->solar_year--;
calendar_ctrl_ptr->solar_month=12;
calendar_ctrl_ptr->solar_date=
(MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month)+calendar_ctrl_ptr->solar_date)-7;
}
else
calendar_ctrl_ptr->solar_date-=7;
}
else
{
if(calendar_ctrl_ptr->solar_date-7<=0)
{ calendar_ctrl_ptr->solar_month--;
calendar_ctrl_ptr->solar_date=
(MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month)+calendar_ctrl_ptr->solar_date)-7;
}
else
{ calendar_ctrl_ptr->solar_date-=7;
}
}
}
/*****************************************************************************/
// Description : 移到下一行
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_MoveDownLineDay(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr)
{
if( calendar_ctrl_ptr->solar_month==12)
{
if(calendar_ctrl_ptr->solar_date+7>(MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month)))
{
calendar_ctrl_ptr->solar_date=(calendar_ctrl_ptr->solar_date+7)-(MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month));
calendar_ctrl_ptr->solar_year++;
calendar_ctrl_ptr->solar_month=1;
}
else
{ calendar_ctrl_ptr->solar_date = calendar_ctrl_ptr->solar_date+7;
}
}
else
{
if(calendar_ctrl_ptr->solar_date+7>(MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month)))
{
calendar_ctrl_ptr->solar_date=(calendar_ctrl_ptr->solar_date+7)-(MainCALENDAR_GetMonthday(calendar_ctrl_ptr->solar_year,calendar_ctrl_ptr->solar_month));
calendar_ctrl_ptr->solar_month++;
}
else
{ calendar_ctrl_ptr->solar_date = calendar_ctrl_ptr->solar_date+7;
}
}
}
/*****************************************************************************/
// Description : 日历控件的初始化
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
void* MainCALENDAR_Init(GUI_RECT_T
rect
) //日历的显示区域
{
GUI_CALENDAR_CTRL_T* calendar_ptr = &g_calendar_show;
if (PNULL != calendar_ptr)
{
SCI_MEMSET(calendar_ptr, 0x00, sizeof(GUI_CALENDAR_CTRL_T));
calendar_ptr->rect = rect; //控件的显示区域
calendar_ptr->solar_year = 2000; //年
calendar_ptr->solar_month = 1; //月
calendar_ptr->solar_date = 1; //日
MainCALENDAR_SetDefaultCalendarStyle(calendar_ptr);
MainCALENDAR_CalCalendarRect(calendar_ptr);
}
return (void*)calendar_ptr;
}
/*******************************************************************************************/
//
Description : 计算calendar的rect
//
Global resource dependence :
// Author: bin.ji
//
Note:
/*********************************************************************************************/
LOCAL void MainCALENDAR_CalCalendarRect(GUI_CALENDAR_CTRL_T* calendar_ptr )
{
GUI_RECT_T rect = calendar_ptr->rect;
//标题栏
calendar_ptr->title_rect = CreateRect(
rect.left,
rect.top,
rect.right,
rect.top + calendar_ptr->title_height
);
//星期栏
calendar_ptr->week_rect = CreateRect(
rect.left,
rect.top + calendar_ptr->title_height,
rect.right,
rect.top + calendar_ptr->title_height + calendar_ptr->week_height
);
//日期栏
calendar_ptr->day_rect = CreateRect(
rect.left,
rect.top + calendar_ptr->week_height + 4,
rect.right,
rect.bottom
);
calendar_ptr->block_width = (uint16)GUI_Divide((uint16)(rect.right - rect.left), COLNUM);
calendar_ptr->block_height = (uint16)GUI_Divide((uint16)(calendar_ptr->day_rect.bottom
- calendar_ptr->day_rect.top), LINENUM);
}
/*******************************************************************************************/
//
Description : 设置默认的calendar风格
//
Global resource dependence :
// Author: bin.ji
//
Note:
/*********************************************************************************************/
LOCAL void MainCALENDAR_SetDefaultCalendarStyle(GUI_CALENDAR_CTRL_T* calendar_ptr)
{
MMI_CALENDAR_STYLE_T calendar_style;
if (MMITHEME_GetCalendarStyle(&calendar_style))
{
calendar_ptr->title_height = calendar_style.title_height;
calendar_ptr->week_height = calendar_style.week_height;
// calendar_ptr->back_image = calendar_style.back_image;
calendar_ptr->day_back_color = calendar_style.day_back_color;
calendar_ptr->day_font = SONG_FONT_12;
calendar_ptr->day_font_color = calendar_style.day_font_color;
calendar_ptr->day_highlight_color = calendar_style.day_highlight_color;
calendar_ptr->saturday_color = MMI_BLUE_COLOR;
calendar_ptr->sunday_color = MMI_RED_COLOR;
calendar_ptr->day_highlight_color = 0x2000;
calendar_ptr->title_font = SONG_FONT_16;
calendar_ptr->title_font_color = MMI_YELLOW_COLOR;
calendar_ptr->title_back_color = calendar_style.title_back_color;
calendar_ptr->week_back_color = calendar_style.week_back_color;
calendar_ptr->week_font = calendar_style.week_font;
calendar_ptr->week_font_color = calendar_style.week_font_color;
}
}
/*****************************************************************************/
// Description : 日历控件的参数设置
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
void MainCALENDAR_SetParam( //返回PNULL,表示初始化失败,不等于PNULL,表示初始化成功。
GUI_CALENDAR_CTRL_T* calendar_ptr,
uint16
solar_year,
//阳历年
uint8
solar_month,
//阳历月
uint8
solar_date
//阳历日
)
{
calendar_ptr->solar_year = solar_year; //年
calendar_ptr->solar_month = solar_month; //月
calendar_ptr->solar_date = solar_date; //日
}
/*****************************************************************************/
// Description : 画日历的年月标题
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_DrawYearMonthTitle(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr)
{
GUI_RECT_T rect = {CALENDAR_TITLE_LEFT,
CALENDAR_TITLE_TOP,
CALENDAR_TITLE_LEFT + CALENDAR_TITLE_LENGTH,
CALENDAR_TITLE_TOP + CALENDAR_TITLE_HIGH
};
uint8 title_str[20];
uint16 year = calendar_ctrl_ptr->solar_year;
uint8 month = calendar_ctrl_ptr->solar_month;
uint8 date = calendar_ctrl_ptr->solar_date;
sprintf((char*)title_str, "%d-%d%d-%d%d", year, month/10, month%10,date/10,date%10);
LCD_DisplayStringByAlign(
MAINLCD_ID,
rect,
//the fixed display area
title_str,
//string to display
(uint16)strlen((char*)title_str),
//length of string to display
0,
//space between two chars.
calendar_ctrl_ptr->title_font_color,
//string color
calendar_ctrl_ptr->title_font,
//font pointer
FALSE,
ALIGN_HVMIDDLE,
0
);
}
/*****************************************************************************/
// Description : 画日历的日期
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void MainCALENDAR_DrawDate(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr)
{
//GUI_RECT_T rect = calendar_ctrl_ptr->day_rect;
GUI_COLOR_T color;
uint8 i;
uint8 x;
uint8 y;
uint8 wday;
uint8 date_str[DATE_LENGTH];
GUI_RECT_T part_rect;
uint16 year = calendar_ctrl_ptr->solar_year;
uint8 month = calendar_ctrl_ptr->solar_month;
uint8 date = calendar_ctrl_ptr->solar_date;
uint8 j = MainCALENDAR_GetFirstday(year, month);
uint8 month_day = MainCALENDAR_GetMonthday(year, month);
for (i=1;i<=month_day;i++)
{
wday = (i+j-1)%7; //计算星期
x=s_calendar_position[(i+j-1)/7][wday].x;
y=s_calendar_position[(i+j-1)/7][wday].y;
if (i == date)
{
color = calendar_ctrl_ptr->day_highlight_color;
GUI_DisplayStaticBmp(
MAINLCD_ID,
x+1,
y+3,
IMAGE_CALENDAR_INDICATION_ON
);
}
else if (wday == 0 )
{
color = calendar_ctrl_ptr->sunday_color;
}
else
if( wday== 6)
{
color = calendar_ctrl_ptr->saturday_color;
}
else
{
color = calendar_ctrl_ptr->day_font_color;
}
sprintf((char*)date_str, "%d", i);
part_rect = CreateRect(
(uint16)(x),
(uint16)(y),
(uint16)(x+CALENDAR_DATENUMBER_SHOW_LENGTH),
(uint16)(y+CALENDAR_DATENUMBER_SHOW_HIGH)
);
LCD_DisplayStringByAlign(
MAINLCD_ID,
part_rect,
date_str,
(uint16)strlen((char*)date_str),
0,
color,
SONG_FONT_14,
FALSE,
ALIGN_HVMIDDLE,
0
);
}
}
/*****************************************************************************/
// Description : 画日历
// Global resource dependence :
// Author: Jibin
// Note: 未完成部分
/*****************************************************************************/
LOCAL void MainCALENDAR_DrawCalendar(GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr )
{
if (PNULL == calendar_ctrl_ptr)
{
return;
}
if(MMISET_LANGUAGE_ENGLISH==g_ksp_Lang) //当前的语言类型
{
GUI_DisplayStaticBmp(MAINLCD_ID, 0, 0, IMAGE_CALENDAR_ENGLISH_BG);
}
else
{
GUI_DisplayStaticBmp(MAINLCD_ID, 0, 0, IMAGE_CALENDAR_BG);
}
//显示标题(年月)
MainCALENDAR_DrawYearMonthTitle(calendar_ctrl_ptr);
//显示六行日期
MainCALENDAR_DrawDate(calendar_ctrl_ptr);
//显示农历日期
MainCALENDAR_DrawLunarDate(calendar_ctrl_ptr);
}
/*****************************************************************************/
// Description : 日历控件按键的辅助处理
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL void HandleCalendarKey(GUI_CALENDAR_CTRL_T*
calendar_ctrl_ptr,uint16 msg_id )
{
if (PNULL == calendar_ctrl_ptr)
{
return;
}
switch( msg_id )
{
case MSG_KEYDOWN_UP: //移到上一行
MainCALENDAR_MoveUpLineDay(calendar_ctrl_ptr);
break;
case MSG_KEYDOWN_DOWN: //移到下一行
MainCALENDAR_MoveDownLineDay(calendar_ctrl_ptr);
break;
case MSG_KEYDOWN_LEFT: //移到上一天
MainCALENDAR_MovePrevDay(calendar_ctrl_ptr);
break;
case MSG_KEYDOWN_RIGHT: //移到下一天
MainCALENDAR_MoveNextDay(calendar_ctrl_ptr);
break;
case MSG_KEYDOWN_START: //移到上一月
MainCALENDAR_MovePrevMonth(calendar_ctrl_ptr);
break;
case MSG_KEYDOWN_HASH: //移到下一月
MainCALENDAR_MoveNextMonth(calendar_ctrl_ptr);
break;
default:
break;
}
}
/*****************************************************************************/
// Description : 日历控件的消息处理
// Global resource dependence :
// Author: Jibin
// Note:
/*****************************************************************************/
LOCAL MMI_RESULT_E HandleCalendarWinMsg(
MMI_WINDOW_ID_E win_id,
MMI_MESSAGE_ID_E msg_id,
DPARAM param
)
{
MMI_RESULT_E ret_val = MMI_RESULT_TRUE;
GUI_CALENDAR_CTRL_T* calendar_ctrl_ptr = &g_calendar_show;
SCI_DATE_T date;
GUI_RECT_T rect = {0,33,128,140};
if (PNULL == calendar_ctrl_ptr)
{
return MMI_RESULT_FALSE;
}
switch( msg_id )
{
case MSG_OPEN_WINDOW:
//获取当前的系统日期
TM_GetSysDate(&date);
MainCALENDAR_Init(rect);
MainCALENDAR_SetParam(calendar_ctrl_ptr, date.year, date.mon, date.mday);
MMK_SetWinSoftkeyId(win_id, TXT_NULL, TXT_NULL, STXT_RETURN, TRUE);
break;
case MSG_FULL_PAINT:
//进入键
MainCALENDAR_DrawCalendar(calendar_ctrl_ptr);
break;
case MSG_KEYDOWN_CANCEL:
//退出键
MMK_CloseWin(win_id);
break;
case MSG_KEYDOWN_UP:
//上键
case MSG_KEYDOWN_DOWN:
//下键
case MSG_KEYDOWN_LEFT:
//左键
case MSG_KEYDOWN_RIGHT:
//右键
case MSG_KEYDOWN_HASH:
//#键
case MSG_KEYDOWN_START:
// * 键
HandleCalendarKey(calendar_ctrl_ptr, msg_id);
MainCALENDAR_DrawCalendar(calendar_ctrl_ptr);
break;
default:
ret_val = MMI_RESULT_FALSE;
break;
}
return ret_val;
}