MS_LIB.C
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:8k
- /* **************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: MS_LIB.C $
- *
- * Description:
- * ============
- * menu library handle
- *
- * Log:
- * ====
- * $Revision: 5 $
- * Last Modified by $Author: Leonh $ at $Modtime: 12/23/03 12:54p $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/UI/Menu_sys/MS_LIB.C $
- *
- * 5 12/23/03 1:01p Leonh
- * Angieh:Support for the hidden group search.
- *
- * 4 11/25/03 9:27a Leonh
- * Angieh:Move the compile(D_MS_EXTENSIONS).
- *
- * 3 03-05-08 19:51 Rogerl
- * Adjust layout according to video format
- *
- * 2 03-01-09 4:43 Leslie
- * Unicode support
- *
- * 10 23/04/02 9:39 Nirm
- * - Added dependency in "Config.h".
- *
- * 9 11/03/02 14:09 Nirm
- * Debug message in case of memory allocation failure.
- *
- * 8 3/05/02 11:25 Rinata
- * fix num_to_str to support high num of digits
- *
- * 7 2/27/02 7:02a Tomasp
- * Changed get_blk/rel_blk to malloc,free.
- *
- * 5 13/01/02 16:35 Atai
- * Remove old Defines
- *
- * 4 9/01/02 18:23 Nirm
- * Corrected Include-Paths.
- *
- * 3 30/12/01 10:00 Atai
- * Add explicit casting
- *
- * 2 25/12/01 10:41 Atai
- * Code cleaning
- **************************************************************************************** */
- #include "Config.h" // Global Configuration - do not remove!
- #include "Includesysdefs.h"
- #include "Decoderosdrendr.h"
- #include "Decoderosdlayou.h"
- #include "Decoderdecoder.h"
- #include "UIMenu_Sysms_wdgt.h"
- #include "UIMenu_Sysms_lib.h"
- #include "UIMenu_Sysosd_drv.h"
- BOOL g_ms_bMustClose = FALSE;
- void (*g_ms_deferred_action)(void) = NULL;
- WORD g_ui_active_menu_id = RUN_TIME_MENU_ID;
- WORD g_ui_default_menu_id = RUN_TIME_MENU_ID;
- //#ifdef D_USE_RETURN_IN_MENUS
- WORD g_ui_next_menu_id = RUN_TIME_MENU_ID;
- //#endif // D_USE_RETURN_IN_MENUS
- #ifdef D_MS_EXTENSIONS
- WORD g_ui_stopPending_menu_id = 0;
- UINT g_ui_stopPending_cnt = 0;
- #endif // D_MS_EXTENSIONS
- BOOL g_ms_bMustUseBigMemMap = FALSE;
- CONST MS_COLOR dialog_color = DIALOG_COLOR;
- CONST MS_COLOR i_color = I_COLOR;
- CONST MS_COLOR screen_color = SCREEN_COLOR;
- CONST MS_COLOR group_color = GROUP_COLOR;
- CONST MS_POS MS_toggle_pos = { 0, 0, 0, 0 };
- #ifdef D_USE_RETURN_IN_MENUS
- P_MENU_INFO g_ms_pMenuInfo = NULL;
- // Push a menu onto the menu stack
- void push_menu( WORD wMenuID )
- {
- P_MENU_INFO pMenuInfo;
- pMenuInfo = (P_MENU_INFO)malloc(sizeof(MENU_INFO));
- #ifdef _DEBUG
- if (NULL == pMenuInfo) {
- tr_printf(("FATAL: push_menu() Failed: Low system resources.n"));
- return;
- }
- #endif //_DEBUG
- pMenuInfo->m_wMenuID = wMenuID;
- pMenuInfo->m_pMenuInfo = (void *) g_ms_pMenuInfo;
- g_ms_pMenuInfo = pMenuInfo;
- }
- // Pop a menu from the menu stack
- WORD pop_menu( void )
- {
- P_MENU_INFO pMenuInfo = g_ms_pMenuInfo;
- WORD wMenuID = g_ui_default_menu_id;
- if ( pMenuInfo )
- {
- wMenuID = pMenuInfo->m_wMenuID;
- g_ms_pMenuInfo = (P_MENU_INFO) pMenuInfo->m_pMenuInfo;
- free(pMenuInfo);
- }
- return wMenuID;
- }
- // Flush the menu stack
- void flush_menu( void )
- {
- while ( g_ms_pMenuInfo )
- {
- pop_menu();
- }
- g_ui_next_menu_id = g_ui_default_menu_id;
- }
- // Call this when handling MS_UOP_RETURN
- // The popped menu ID is put into g_ui_next_menu_id
- void MS_return_to_menu( void )
- {
- g_ms_bMustClose = TRUE;
- g_ui_next_menu_id = pop_menu();
- }
- // Go to another menu without affecting the menu stack
- void MS_goto_next_menu( WORD wMenuID )
- {
- g_ms_bMustClose = TRUE;
- g_ui_next_menu_id = wMenuID;
- }
- // Call this from actions which require going to a submenu
- // wMenuID is the destination menu ID
- void MS_goto_submenu( WORD wMenuID )
- {
- push_menu(g_ui_active_menu_id);
- MS_goto_next_menu( wMenuID );
- }
- // REMINDER Move menu ID's to menu_var.h?
- #endif // D_USE_RETURN_IN_MENUS
- BOOL isDigit( wchar_t ch )
- {
- return ( (ch >= '0') && (ch <= '9') );
- }
- // Convert a number to a string
- //
- // For zero-padding, specify 10^iNumDigits + (actual num) as the num parameter
- //
- int num_to_str(UINT32 num, wchar_t *str, int iNumDigits)
- {
- int i = 0;
- UINT32 iMod = 1;
- UINT32 iValue = num;
- while ( iNumDigits-- > 1 )
- {
- iMod *= 10;
- }
-
- iValue = num % (iMod * 10);
- i = 0;
- while ( iMod > 1 )
- {
- if ( num > (iMod - 1) )
- {
- str[i++] = num_to_ch(iValue / iMod);
- }
- iValue %= iMod;
- iMod /= 10;
- }
- str[i++] = num_to_ch(iValue);
- str[i] = ' ';
- return i;
- }
- //tecobest gxd 20050817
- #if defined(D_MS_EXTENSIONS) || defined(D_TEST)||defined(D_IRCODE_TEST)||defined(D_FP_DISPLAY_TEST)||defined(D_FP_KEYCODE_TEST)
- unsigned char pucHexDigit[] = {'A', 'B', 'C', 'D', 'E', 'F'};
- // Convert a number to a hex string
- //
- // -- Take care that str storage is at least iNumDigits + 1 bytes
- //
- void num_to_hex_str(int num, wchar_t *str, int iNumDigits)
- {
- int i = 0;
- int iValue = num;
- unsigned char ucHexDigit;
- str[iNumDigits] = ' ';
- while (iNumDigits)
- {
- ucHexDigit = num & 0x0f;
- num >>= 4;
- str[--iNumDigits] = ( (ucHexDigit >= 0x0A) ? pucHexDigit[ucHexDigit - 0x0A] : num_to_ch(ucHexDigit) );
- }
- }
- void hex_to_num(wchar_t *text, long *pdw)
- {
- long dw = 0;
- int iLength = wcslen(text);
- wchar_t c;
- while ( iLength && !isHexDigit(*text) )
- {
- iLength--;
- text++;
- }
-
- if ( iLength )
- {
- while ( isHexDigit(c = *text++) )
- {
- c = hex_char_to_num(c);
- dw = dw * 0x10 + c;
- }
- } // iLength
- *pdw = dw;
- }
- #endif // D_MS_EXTENSIONS
- wchar_t strict_hex_char_to_num( wchar_t ch )
- {
- wchar_t cDecrement = 0;
-
- if ( (ch >= 'a') && (ch <= 'f') )
- cDecrement = 'a';
- else
- if ( (ch >= 'A') && (ch <= 'F') )
- cDecrement = 'A';
- if ( cDecrement )
- ch -= (cDecrement - 0x0A);
- else
- ch = 0;
-
- return ch;
- }
- BOOL isStrictHexDigit( wchar_t ch )
- {
- return ( ((ch >= 'A') && (ch <= 'F')) || ((ch >= 'a') && (ch <= 'f')) );
- }
- BOOL isHexDigit( wchar_t ch )
- {
- return ( isDigit(ch) || isStrictHexDigit(ch) );
- }
- wchar_t hex_char_to_num( wchar_t ch )
- {
- if ( isDigit(ch) )
- ch = char_to_num(ch);
- else
- ch = strict_hex_char_to_num(ch);
- return ch;
- }
- // Override standard user_op
- void *MS_override_user_op( MS_WIDGET *pmsw, void *pvNew_user_op )
- {
- void *pvOriginal_user_op = pmsw->user_op;
- pmsw->user_op = pvNew_user_op;
- return pvOriginal_user_op;
- }
- void MS_adjust_layout(void)
- {
- #ifdef D_LINE_DOUBLING
- WORD wHeightLimit = NBRLIN_NTSC;
- if ( (go_CurrentLayout.m_wHeight + (go_CurrentLayout.m_wOriginY * 2) ) > wHeightLimit )
- go_CurrentLayout.m_wHeight = wHeightLimit - (go_CurrentLayout.m_wOriginY * 2);
- go_CurrentLayout.m_wOriginY >>= 1;
- go_CurrentLayout.m_wHeight >>= 1;
- go_CurrentLayout.m_cPixRes = MS_PIX_RES;
- if ( go_CurrentLayout.m_cNbrHole )
- {
- char cIndex;
- for ( cIndex = 0; cIndex < go_CurrentLayout.m_cNbrHole; cIndex++ )
- {
- go_CurrentLayout.m_oHolePos[cIndex].m_wLineNbr >>= 1;
- go_CurrentLayout.m_oHolePos[cIndex].m_wHeight >>= 1;
- }
- }
- #else // D_LINE_DOUBLING
- WORD wHeightLimit = DEC_IsVideoPal() ? NBRLIN_PAL : NBRLIN_NTSC;
- if ( (go_CurrentLayout.m_wHeight + (go_CurrentLayout.m_wOriginY * 2) ) > wHeightLimit )
- go_CurrentLayout.m_wHeight = wHeightLimit - (go_CurrentLayout.m_wOriginY * 2);
- #endif // D_LINE_DOUBLING
- }
- #ifdef D_DISPLAY_1_MENU
- void seconds_to_time_input_str( DWORD dwSs, char *sz )
- {
- // Get either bookmark time or invalid string into szTime
- DWORD dwHh;
- DWORD dwMm;
- DWORD dwTime;
- unsigned char ucIndex;
-
- dwHh = dwSs / SECONDS_PER_HOUR;
- dwSs = dwSs - dwHh * SECONDS_PER_HOUR;
- dwMm = dwSs / SECONDS_PER_MINUTE;
- dwSs = dwSs - dwMm * SECONDS_PER_MINUTE;
- dwTime = dwHh * 10000 + dwMm * 100 + dwSs;
- #ifdef D_ONE_HOUR_DIGIT
- num_to_str(1000000 + dwTime, sz, 5);
- #else
- num_to_str(1000000 + dwTime, sz, 6);
- #endif
- }
- #endif // D_DISPLAY_1_MENU
- void MS_display_in_container( MS_WIDGET *pmsw )
- {
- OSD_SetOrigin( (MS_WIDGET*)pmsw->parent );
- pmsw->user_op( pmsw, MS_UOP_DISPLAY, ( pmsw->parent->pwli_focus->widget == pmsw ? C_FOCUSED : !C_FOCUSED ) );
- }
- void MS_set_deferred_action( void (*pfnDeferred)(void) )
- {
- g_ms_deferred_action = pfnDeferred;
- }