MS_TIME.C
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:11k
- /* **************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: MS_TIME.C $
- *
- * Description:
- * ============
- * Menu system Time presentation
- *
- * Log:
- * ====
- * $Revision: 11 $
- * Last Modified by $Author: Leonh $ at $Modtime: 12/23/03 12:54p $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/UI/Menu_sys/MS_TIME.C $
- *
- * 11 12/23/03 1:02p Leonh
- * Angieh:Support for the hidden group search.
- *
- * 10 8/12/03 2:09p Mikex
- * bug fix for that the input number will disappear in the time search
- * menu after changing the focus to track menu.
- *
- * 9 03-06-24 14:00 Billt
- * Added EDIT_INPUT_SHIFT_LEFT
- *
- * 8 03-05-19 23:08 Rogerl
- * Time edit leading by '0'
- *
- * 7 03-05-16 19:08 Rogerl
- * Implement SUPPORT_TIME_EDIT_LEFT_TO_RIGHT
- *
- * 6 03-04-21 17:50 Mikelv
- * If the input time is nothing,ignore it
- *
- * 5 4/13/03 4:53p Rinata
- * fix password ibehave on parental control n case it is 0000
- *
- * 4 03-02-18 16:23 Royz
- * fix time search bug
- *
- * 3 03-01-09 4:43 Leslie
- * Unicode support
- *
- * 12 23/04/02 9:39 Nirm
- * - Added dependency in "Config.h".
- *
- * 11 11/03/02 12:58 Nirm
- * Debug message in case of memory allocation failure.
- *
- * 10 2/27/02 7:02a Tomasp
- * Changed get_blk/rel_blk to malloc,free.
- *
- * 9 12/02/02 11:09 Atai
- * Optimize initalized array use
- *
- * 7 16/01/02 8:57 Nirm
- * Fixed debug-messages.
- *
- * 6 1/15/02 3:36p Tomasp
- * - fix compilation warning (a bug) - problem in case the time is > 10h
- *
- * 5 13/01/02 16:39 Atai
- * Remove old Defines
- *
- * 4 9/01/02 18:23 Nirm
- * Corrected Include-Paths.
- *
- * 3 30/12/01 10:05 Atai
- * Add explicit casting
- *
- * 2 25/12/01 10:57 Atai
- * Code cleaning
- **************************************************************************************** */
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #include "DebugDbgMain.h"
- #undef IFTRACE
- #define IFTRACE if (gTraceMenu)
- #endif //_DEBUG
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "Includesysdefs.h"
- #include "Decoderosdrendr.h"
- #include "UIMenu_Sysosd_drv.h"
- #include "UIMenu_Sysms_wdgt.h"
- #include "UIMenu_Sysms_lib.h"
- #ifdef D_ONE_HOUR_DIGIT
- #define MS_TIME_STR_LENGTH 7
- #else
- #define MS_TIME_STR_LENGTH 8
- #endif // D_ONE_HOUR_DIGIT
- BOOL b_TIME_NULL = FALSE;
- // format text as a time string ( e.g., "2957" -> "00:29:57" )
- static void text_to_time_str(wchar_t *text, int iLength, wchar_t *time_str)
- {
- #ifdef D_ONE_HOUR_DIGIT
- static CONST int iFirstChar[] = { 6, 5, 3, 2, 0 };
- #else
- static CONST int iFirstChar[] = { 7, 6, 4, 3, 1, 0 };
- #endif // D_ONE_HOUR_DIGIT
- int iFirstCharIndex;
- int iCharIndex;
- wcscpy(time_str, EMPTY_TIME);
- if ( iLength == 0 )
- return;
- iFirstCharIndex = iLength - 1; // e.g., 3
- for ( iCharIndex = 0; iCharIndex < iLength; iCharIndex++ )
- {
- time_str[iFirstChar[iFirstCharIndex--]] = text[iCharIndex];
- // e.g., [iFirstChar[3]] <- [0]
- // e.g., [iFirstChar[2]] <- [1]
- // e.g., [iFirstChar[1]] <- [2]
- // e.g., [iFirstChar[0]] <- [3]
- }
- }
- BOOL text_to_num(wchar_t *text, long *pdw)
- {
- long dw = 0;
- int iLength = wcslen(text);
- wchar_t c;
- while (iLength && !isDigit(*text))
- {
- iLength--;
- text++;
- }
-
- if ( iLength )
- {
- while ( isDigit(c = *text++) )
- {
- c = char_to_num(c);
- dw = dw * 10 + c;
- }
- *pdw = dw;
- return TRUE;
- } // iLength
- *pdw = dw;
- return FALSE;
- }
- void text_to_BCDnum(wchar_t *text, DWORD *pdw)
- {
- long dw = 0;
- int iLength = wcslen(text);
- char c;
- while (iLength && !isHexDigit(*text))
- {
- iLength--;
- text++;
- }
- if ( iLength )
- {
- while ( isHexDigit(c = *text++) )
- {
- c = hex_char_to_num(c);
- dw |= c;
- if (wcslen(text))
- dw = dw<<4 ;
- }
- } // iLength
- *pdw = dw;
- }
- // Convert an unformatted time string to seconds
- void text_to_seconds(wchar_t *text, long *pSeconds)
- {
- int iLength = wcslen(text);
- long seconds = 0;
- int iTextIndex;
- wchar_t c;
- static CONST long iMultiplier[] = { 36000L, 3600, 600, 60, 10, 1 };
- int iMultiplierIndex = 5;
- for ( iTextIndex = iLength - 1; iTextIndex >= 0 ; iTextIndex-- )
- {
- if ( isDigit(c = text[iTextIndex]) )
- {
- c = char_to_num(c);
- seconds += ((long) c * iMultiplier[iMultiplierIndex--]);
- b_TIME_NULL = TRUE;
- }
- }
- *pSeconds = seconds;
- }
- int get_num_digits(ULONG number)
- {
- int digits =1;
- while(number/10)
- {
- digits ++;
- number /= 10;
- }
- return digits;
- }
- int get_time_digits(ULONG number)
- {
- static CONST long iMultiplier[] = { 36000L, 3600, 600, 60, 10, 1 };
- int digits =1;
- while(number>= iMultiplier[5-digits] && digits <6)
- {
- digits ++;
- }
- return digits;
- }
- #ifdef SUPPORT_TIME_EDIT_LEFT_TO_RIGHT
- // format text as a time string ( e.g., "2957" -> "00:29:57" )
- static void text_to_time_str2(wchar_t *text, int iLength, wchar_t *time_str, int max_digits)
- {
- static CONST int iFirstChar[] = { 7, 6, 4, 3, 1, 0 };
- int iFirstCharIndex;
- int iCharIndex;
- // Maximum time digits is 6, RL051903
- if (6< max_digits)
- max_digits =6;
- wcscpy(time_str, EMPTY_TIME);
- if ( iLength == 0 )
- return;
- else
- // Fill leading zeros, Rl051903
- for(iCharIndex =0; iCharIndex < (6-max_digits);iCharIndex++)
- {
- time_str[iFirstChar[5-iCharIndex]]= '0';
- }
- // Find First Digit to fill , RL051603
- //iFirstCharIndex = iLength - 1; // e.g., 3
- iFirstCharIndex = max_digits - 1; // e.g., 3
- for ( iCharIndex = 0; iCharIndex < iLength; iCharIndex++ )
- {
- time_str[iFirstChar[iFirstCharIndex--]] = text[iCharIndex];
- // e.g., [iFirstChar[3]] <- [0]
- // e.g., [iFirstChar[2]] <- [1]
- // e.g., [iFirstChar[1]] <- [2]
- // e.g., [iFirstChar[0]] <- [3]
- }
- }
- // Convert an unformatted time string to seconds
- void text_to_seconds2(wchar_t *text, long *pSeconds,int max_digits)
- {
- int iLength = wcslen(text);
- long seconds = 0;
- int iTextIndex;
- wchar_t c;
- static CONST long iMultiplier[] = { 36000L, 3600, 600, 60, 10, 1 };
- int iMultiplierIndex = 5;
- // Find First Digit to fill , RL051603
- iMultiplierIndex = 6-max_digits;
- for ( iTextIndex = 0; iTextIndex < iLength ; iTextIndex++ )
- {
- if ( isDigit(c = text[iTextIndex]) )
- {
- c = char_to_num(c);
- seconds += ((long) c * iMultiplier[iMultiplierIndex++]);
- b_TIME_NULL = TRUE;
- }
- }
- *pSeconds = seconds;
- }
- #endif
- static void display (MS_WIDGET *widget, char focus)
- {
- MS_EDIT *edit = (MS_EDIT *)widget;
- wchar_t time_str[MS_TIME_STR_LENGTH+1];
- #ifdef SUPPORT_TIME_EDIT_LEFT_TO_RIGHT
- if (MS_IS_TIME_EDIT_LEFT_TO_RIGHT(widget))
- text_to_time_str2(edit->present.text, (int) edit->current_num, time_str,(int )edit->max_width);
- else
- #endif
- #ifdef EDIT_INPUT_SHIFT_LEFT
- {
- BYTE i;
- BYTE j = (edit->max_width) - (edit->current_num);
- for ( i = 0; (i+j < (edit->max_width))&&j; i++ )
- {
- ((wchar_t *)(edit->present.text))[i] = ((wchar_t *)(edit->present.text))[i+j];
- }
- text_to_time_str(edit->present.text, (int) edit->current_num, time_str);
- for ( i = (edit->max_width); (i-j > 0)&&j; i-- )
- {
- ((wchar_t *)(edit->present.text))[i-1] = ((wchar_t *)(edit->present.text))[i-j-1];
- ((wchar_t *)(edit->present.text))[i-j-1] = '-';
- }
- }
- #else //EDIT_INPUT_SHIFT_LEFT
- text_to_time_str(edit->present.text, (int) edit->current_num, time_str);
- #endif //EDIT_INPUT_SHIFT_LEFT
- // First time focus, start from beginning of the field
- OSD_PutText(widget->pos.x,
- widget->pos.y,
- widget->pos.w,
- widget->pos.h,
- #ifdef D_MS_EXTENSIONS
- FORE_COLOR(widget, focus),
- #else
- FG_COLOR(widget->color),
- #endif
- BACK_COLOR(widget, focus),
- time_str,
- MS_JUST(widget),
- C_ASCII);
- }
- static unsigned char number_select(MS_EDIT *edit,unsigned char num)
- {
- if ( edit_number_select( edit, num ) )
- {
- #ifdef D_MS_EXTENSIONS
- MS_SET_ACTION_PENDING(edit);
- #endif // D_MS_EXTENSIONS
- OSD_SetOrigin( ((MS_WIDGET *) edit)->parent );
- display((MS_WIDGET *)edit, C_FOCUSED); // Display the text with the new number;
- }
- return 1;
- }
- MS_UOP time_user_op(MS_WIDGET *widget,MS_UOP uop,char param)
- {
- switch (uop) {
- case MS_UOP_DELETE:
- return MS_UOP_NOP;
- // no break needed
- case MS_UOP_CLEAR:
- wcscpy( ((wchar_t *)((MS_EDIT *) widget)->present.text), L"------");
- //param = 1;
- param = ( (((MS_DIALOG *) widget->parent)->pwli_focus->widget == widget) ? C_FOCUSED : !C_FOCUSED );
- ((MS_EDIT *)widget)->current_num = 0;
- // Fall through!
- case MS_UOP_DISPLAY:
- display(widget,param);
- #ifdef D_MS_EXTENSIONS
- #else
- //((MS_EDIT *)widget)->current_num = 0;
- #endif // D_MS_EXTENSIONS
- return MS_UOP_NOP;
- // no break needed
- case MS_UOP_0:
- case MS_UOP_1:
- case MS_UOP_2:
- case MS_UOP_3:
- case MS_UOP_4:
- case MS_UOP_5:
- case MS_UOP_6:
- case MS_UOP_7:
- case MS_UOP_8:
- case MS_UOP_9:
- {
- number_select((MS_EDIT *)widget,(unsigned char)(uop-MS_UOP_0));
- #ifdef SUPPORT_TIME_EDIT_LEFT_TO_RIGHT
- //Take action when enter last digit, RL051603
- if(MS_IS_TIME_EDIT_LEFT_TO_RIGHT(widget))
- if(((MS_EDIT *)widget)->current_num ==( (MS_EDIT *)widget)->max_width)
- ((MS_EDIT *)widget)->action(((MS_EDIT *)widget)->present.text);
- #endif
- return MS_UOP_NOP;
- }
- // break;
- }
- if (uop != MS_UOP_ENTER) {
- return uop;
- }
- #ifdef D_MS_EXTENSIONS
- // reset action_pending because the user pressed ENTER
- // regardless of whether the action function is NULL
- MS_RESET_ACTION_PENDING(widget);
- #endif // D_MS_EXTENSIONS
- {
- wchar_t time_str[MS_TIME_STR_LENGTH+1];
- text_to_time_str(((MS_EDIT *)widget)->present.text, (int) ((MS_EDIT *)widget)->current_num, time_str);
-
- ((MS_EDIT *)widget)->current_num = 0;
- // Force action at last , RL051603
- ((MS_EDIT *)widget)->action(time_str);
- }
- return MS_UOP_NOP;
- }
- // text must be a valid memory, size "max_width" plus one , ended with ' '
- MS_TIME *MS_create_time(MS_POS *pos,MS_COLOR color,void *text,void (* action)(void *), unsigned char max_width,unsigned char attr)
- {
- MS_TIME *time;
- dbg_printf(("MS_create_timen"));
- time = (MS_TIME *)malloc(sizeof(MS_TIME));
- #ifdef _DEBUG
- if (NULL == time) {
- tr_printf(("FATAL: MS_create_time() Failed: Low system resources.n"));
- return NULL;
- }
- #endif //_DEBUG
- ((MS_WIDGET *)time)->pos = *pos;
- ((MS_WIDGET *)time)->parent = NO_PARENT;
- ((MS_EDIT *)time)->present.text = text;
- ((MS_EDIT *)time)->action = action;
- ((MS_EDIT *)time)->max_width = max_width;
- ((MS_EDIT *)time)->current_num = 0;
- ((MS_WIDGET *)time)->attr = attr | MS_ASCII;
- ((MS_WIDGET *)time)->color = color;
- ((MS_WIDGET *)time)->user_op = time_user_op;
-
- ((MS_WIDGET *)time)->attrh = ALIGN_CENTER;
-
- return time;
- }