⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 healthmenstural.c

📁 mtk工具箱,计算器的详细设计,可以由此入手了解mtk的
💻 C
📖 第 1 页 / 共 5 页
字号:
S16 MensGetDaysDifference(MYTIME *t1, MYTIME *t2)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 Result;
    MYTIME startTime, endTime, incTime;
    U8 SignFlag;

    TIME_EQUALITY eq = CompareTime(*t1, *t2, NULL);

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(&incTime, 0, sizeof(MYTIME));
    if (eq == TIME_LESS)    /* t1 < t2 */
    {
        startTime = *t1;
        endTime = *t2;
        SignFlag = 0;
    }
    else if (eq == TIME_GREATER)    /* t1 > t2 */
    {
        startTime = *t2;
        endTime = *t1;
        SignFlag = 1;
    }
    else    /* no difference */
    {
        return 0;
    }

    /* day */
    if (endTime.nMonth > startTime.nMonth || endTime.nYear > startTime.nYear)
    {
        Result = endTime.nDay + LastDayOfMonth(startTime.nMonth, startTime.nYear) - startTime.nDay;
        incTime.nMonth = 1;
	        
		/* Increase one month with IncrementTime() may make 3/31 to become 5/1 */
		startTime.nMonth += 1;
		if (startTime.nMonth > NUM_MONTHS)
		{
			startTime.nYear ++;	
			startTime.nMonth = 1;
		}		

        startTime.nDay = 1; /* to prevent day out of boundary */

        /* month */
        while (!(endTime.nMonth == startTime.nMonth && endTime.nYear == startTime.nYear))
        {
            Result += LastDayOfMonth(startTime.nMonth, startTime.nYear);
            IncrementTime(startTime, incTime, &startTime);
        }
    }
    else
    {
        Result = endTime.nDay - startTime.nDay;
    }

    if (SignFlag == 1)
    {
        return Result;
    }
    else
    {
        return Result * (-1);
    }
}

#ifdef __MMI_CALENDAR_V2__


/*****************************************************************************
 * FUNCTION
 *  mmi_mens_construct_cell_info
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_mens_construct_cell_info(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 i, nextMonthBoundary;
    gui_calendar_cell_struct *cell;
    MYTIME preMonth, incTime, currTime;
    U8 lastDayofPreMonth;
    S16 DiffDays;
    S16 Color[31];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(&preMonth, 0, sizeof(MYTIME));
    memset(&incTime, 0, sizeof(MYTIME));
    memset(&currTime, 0, sizeof(MYTIME));
    /* GetDateTime(&currTime); */
    currTime.nMonth = (U8) g_mens_cntx->CurrMonth;
    currTime.nYear = (U16) g_mens_cntx->CurrYear;
    currTime.nDay = 1;

    incTime.nMonth = 1;
    applib_dt_decrease_time(
        (applib_time_struct*) & currTime,
        (applib_time_struct*) & incTime,
        (applib_time_struct*) & preMonth);
    lastDayofPreMonth = applib_dt_last_day_of_mon(preMonth.nMonth, preMonth.nYear);

    cell = g_mens_cntx->MenstrulCell + (g_mens_cntx->DayOnFirst);

    /* last month */
    for (i = g_mens_cntx->DayOnFirst - 1; i >= 0; i--)
    {
        cell--;
        mmi_clndr_util_num_to_unicode(lastDayofPreMonth, (U8*) cell->text, GUI_CALENDAR_MAX_CELL_TEXT);
        cell->valid = MMI_FALSE;
        cell->bg_index = GUI_CALENDAR_COLOR_NONE;
        lastDayofPreMonth--;
    }

    /* this month */
    cell = g_mens_cntx->MenstrulCell + g_mens_cntx->DayOnFirst;

    DiffDays = MensGetDaysDifference(&currTime, &g_mens_cntx->InputDate);
    for (i = 1; i <= g_mens_cntx->DayOfMon; i++)
    {
        /* get/set color of days */
        Color[i] = (MensGetDisplayColor(DiffDays, g_mens_cntx->AvgPeriod));

        if (Color[i] != COLOR_NONE)
        {
            cell->bg_index = GUI_CALENDAR_COLOR_MENSTRUAL + Color[i] - 1;
        }
        else
        {
            cell->bg_index = GUI_CALENDAR_COLOR_NONE;
        }
        mmi_clndr_util_num_to_unicode(i, (U8*) cell->text, GUI_CALENDAR_MAX_CELL_TEXT);
        cell->valid = MMI_TRUE;
        cell++;
        DiffDays++;

    }

    /* next month */
    nextMonthBoundary = CLNDR_ROW * CLNDR_COLUMN - (g_mens_cntx->DayOnFirst + g_mens_cntx->DayOfMon);
    for (i = 1; i <= nextMonthBoundary; i++)
    {
        mmi_clndr_util_num_to_unicode(i, (U8*) cell->text, GUI_CALENDAR_MAX_CELL_TEXT);
        cell->bg_index = GUI_CALENDAR_COLOR_NONE;
        cell->valid = MMI_FALSE;
        cell++;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_mens_highlight
 * DESCRIPTION
 *  
 * PARAMETERS
 *  row         [IN]        
 *  column      [IN]        
 * RETURNS
 *  
 *****************************************************************************/
MMI_BOOL mmi_mens_highlight(U32 row, U32 column)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 totaldays;
    S8 tmpString[MENS_TITLE_LEN];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    totaldays = (row * CLNDR_COLUMN) + column + 1;
    g_mens_cntx->CurrDay = totaldays - g_mens_cntx->DayOnFirst;
    /* g_mens_cntx->CalTime.DayIndex = DOW(g_clndr_cntx->CalTime.nYear, g_clndr_cntx->CalTime.nMonth, g_clndr_cntx->CalTime.nDay); */

    sprintf(tmpString, "%d %02d", (U16) g_mens_cntx->CurrYear, g_mens_cntx->CurrMonth);
    AnsiiToUnicodeString(g_mens_cntx->TitleString, tmpString);

    wgui_calendar_set_normal_title((U8*) g_mens_cntx->TitleString);

    return MMI_FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_mens_left_out_of_boundary
 * DESCRIPTION
 *  
 * PARAMETERS
 *  row         [IN]        
 *  column      [IN]        
 * RETURNS
 *  
 *****************************************************************************/
MMI_BOOL mmi_mens_left_out_of_boundary(U32 row, U32 column)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MYTIME nextDate, incTime;
    S8 tmpString[MENS_TITLE_LEN];
    U32 highlightDays, highlightX, highlightY;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(&nextDate, 0, sizeof(MYTIME));
    memset(&incTime, 0, sizeof(MYTIME));

    nextDate.nYear = g_mens_cntx->CurrYear;
    nextDate.nMonth = g_mens_cntx->CurrMonth;
    nextDate.nDay = g_mens_cntx->CurrDay;

    incTime.nDay = 1;

    applib_dt_decrease_time(
        (applib_time_struct*) & nextDate,
        (applib_time_struct*) & incTime,
        (applib_time_struct*) & nextDate);

    if (g_mens_cntx->CurrYear == nextDate.nYear && g_mens_cntx->CurrMonth == nextDate.nMonth)
    {
        g_mens_cntx->CurrDay--;
        sprintf(tmpString, "%d %02d", (U16) g_mens_cntx->CurrYear, g_mens_cntx->CurrMonth);

        highlightDays = g_mens_cntx->DayOnFirst + g_mens_cntx->CurrDay - 1;
        highlightX = highlightDays % CLNDR_TOTAL_WEEKDAY;
        highlightY = highlightDays / CLNDR_TOTAL_WEEKDAY;
        wgui_calendar_set_highlight(highlightY, highlightX);

        AnsiiToUnicodeString(g_mens_cntx->TitleString, tmpString);
        wgui_calendar_set_normal_title((U8*) g_mens_cntx->TitleString);
    }
    else
    {
        MensGoToPreviousDay();

        /* Check if out of boundary and have a popup */
        if (g_mens_cntx->IsAddToHistory == TRUE)
        {
            return MMI_FALSE;
        }
    }
    return MMI_TRUE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_mens_right_out_of_boundary
 * DESCRIPTION
 *  
 * PARAMETERS
 *  row         [IN]        
 *  column      [IN]        
 * RETURNS
 *  
 *****************************************************************************/
MMI_BOOL mmi_mens_right_out_of_boundary(U32 row, U32 column)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MYTIME nextDate, incTime;
    S8 tmpString[MENS_TITLE_LEN];
    U32 highlightDays, highlightX, highlightY;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(&nextDate, 0, sizeof(MYTIME));
    memset(&incTime, 0, sizeof(MYTIME));

    nextDate.nYear = g_mens_cntx->CurrYear;
    nextDate.nMonth = g_mens_cntx->CurrMonth;
    nextDate.nDay = g_mens_cntx->CurrDay;

    incTime.nDay = 1;

    applib_dt_increase_time(
        (applib_time_struct*) & nextDate,
        (applib_time_struct*) & incTime,
        (applib_time_struct*) & nextDate);

    if (g_mens_cntx->CurrYear == nextDate.nYear && g_mens_cntx->CurrMonth == nextDate.nMonth)
    {
        g_mens_cntx->CurrDay++;
        sprintf(tmpString, "%d %02d", (U16) g_mens_cntx->CurrYear, g_mens_cntx->CurrMonth);

        highlightDays = g_mens_cntx->DayOnFirst + g_mens_cntx->CurrDay - 1;
        highlightX = highlightDays % CLNDR_TOTAL_WEEKDAY;
        highlightY = highlightDays / CLNDR_TOTAL_WEEKDAY;
        wgui_calendar_set_highlight(highlightY, highlightX);

        AnsiiToUnicodeString(g_mens_cntx->TitleString, tmpString);
        wgui_calendar_set_normal_title((U8*) g_mens_cntx->TitleString);
    }
    else
    {
        MensGoToNextDay();

        /* Check if out of boundary and have a popup */
        if (g_mens_cntx->IsAddToHistory == TRUE)
        {
            return MMI_FALSE;
        }
    }
    return MMI_TRUE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_mens_up_out_of_boundary
 * DESCRIPTION
 *  
 * PARAMETERS
 *  row         [IN]        
 *  column      [IN]        
 * RETURNS
 *  
 *****************************************************************************/
MMI_BOOL mmi_mens_up_out_of_boundary(U32 row, U32 column)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MensGoToPreviousWeek();
    /* Check if out of boundary and have a popup */
    if (g_mens_cntx->IsAddToHistory == TRUE)
    {
        return MMI_FALSE;
    }
    else
    {
        return MMI_TRUE;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_mens_down_out_of_boundary
 * DESCRIPTION
 *  
 * PARAMETERS
 *  row         [IN]        
 *  column      [IN]        
 * RETURNS
 *  
 *****************************************************************************/
MMI_BOOL mmi_mens_down_out_of_boundary(U32 row, U32 column)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MensGoToNextWeek();
    /* Check if out of boundary and have a popup */
    if (g_mens_cntx->IsAddToHistory == TRUE)
    {
        return MMI_FALSE;
    }
    else
    {
        return MMI_TRUE;
    }
}


/*****************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -