MS_EDIT.C
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:9k
- /* **************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: MS_EDIT.C $
- *
- * Description:
- * ============
- * manipulate menu edit window
- *
- * Log:
- * ====
- * $Revision: 5 $
- * Last Modified by $Author: Billt $ at $Modtime: 03-06-24 13:57 $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /SourceCode/I64_Common/I64_Reference/UI/Menu_sys/MS_EDIT.C $
- *
- * 5 03-06-24 14:01 Billt
- * Added EDIT_INPUT_SHIFT_LEFT
- *
- * 4 03-02-12 17:18 Royz
- * add ESS style program support
- *
- * 3 03-01-09 4:43 Leslie
- * Unicode support
- *
- * 9 23/04/02 9:39 Nirm
- * - Added dependency in "Config.h".
- *
- * 8 11/03/02 12:43 Nirm
- * Debug message in case of memory allocation failure.
- *
- * 7 2/27/02 7:02a Tomasp
- * Changed get_blk/rel_blk to malloc,free.
- *
- * 5 16/01/02 8:57 Nirm
- * Fixed debug-messages.
- *
- * 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:38 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"
- #define MS_MAX_EDIT 8
- #define PEDIT(_widget_) ( (MS_EDIT *) (_widget_) )
- void edit_display (MS_WIDGET *widget, char focus)
- {
- MS_EDIT *edit = PEDIT(widget);
-
- OSD_SetOrigin( (MS_WIDGET*)widget->parent );
-
- // First time focus, start from beginning of the field
- #ifdef D_MS_EXTENSIONS
- OSD_PutText(widget->pos.x, widget->pos.y, widget->pos.w, widget->pos.h, FORE_COLOR(widget, focus), BACK_COLOR(widget, focus), edit->present.text, MS_JUST(widget), C_ASCII);
- #else
- OSD_PutText(widget->pos.x, widget->pos.y, widget->pos.w, widget->pos.h, FG_COLOR(widget->color),BACK_COLOR(widget, focus), edit->present.text, MS_JUST(widget), C_ASCII);
- #endif
- }
- unsigned char edit_number_select(MS_EDIT *edit, unsigned char num)
- {
- if (edit->current_num >= edit->max_width) {
- dbg_printf(("End of the edit arean"));
- #ifdef D_MS_EXTENSIONS
- {
- // Handle single-digit case
- if ( edit->max_width > 1 )
- // Reversed first two parameters
- memmove( (wchar_t *) (edit->present.text), &((wchar_t *) (edit->present.text))[1], edit->max_width - 1 );
- edit->current_num--;
- }
- #else
- // return 0;
- _wcsnset( ((wchar_t *) edit->present.text), L'-', edit->max_width );
- edit->current_num = 0;
- #endif
- }
- if (MS_IS_USE_SC(edit)) {
- // Need to be implemented !!!!
- }
- else {
- // Support MS_EDIT_HEX
- #ifdef D_MS_EXTENSIONS
- if ( num > 9 )
- ((wchar_t *)(edit->present.text))[edit->current_num++] = 'A' + (num - 0x0A);
- else
- #endif // D_MS_EXTENSIONS
- #ifdef EDIT_INPUT_SHIFT_LEFT
- {
- BYTE i;
- for ( i = 0; i < (edit->max_width) - 1; i++ )
- ((wchar_t *)(edit->present.text))[i] = ((wchar_t *)(edit->present.text))[i+1];
- ((wchar_t *)(edit->present.text))[i] = '0' + num;
- edit->current_num++;
- }
- #else //EDIT_INPUT_SHIFT_LEFT
- ((wchar_t *)(edit->present.text))[edit->current_num++] = '0' + num;
- #endif //EDIT_INPUT_SHIFT_LEFT
- }
- #ifdef D_MS_EXTENSIONS
- // Terminate with null to forget old value
- ((wchar_t *)(edit->present.text))[edit->current_num] = ' ';
- #endif
- #ifdef D_EDIT_EXTENSIONS
- // Terminate with null to forget old value
- ((wchar_t *)(edit->present.text))[edit->current_num] = ' ';
- #endif
- return 1;
- }
- 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*)((MS_WIDGET *) edit)->parent );
- edit_display((MS_WIDGET *)edit, C_FOCUSED); // Display the text with the new number;
- }
- return 1;
- }
- void edit_convert( MS_EDIT *pmse, DWORD *dw )
- {
- #ifdef D_MS_EXTENSIONS
- if ( MS_IS_EDIT_HEX( pmse ) )
- {
- hex_to_num( pmse->present.text, dw );
- }
- else
- #endif // D_MS_EXTENSIONS
- {
- text_to_num( pmse->present.text, (long*)dw );
- }
- }
- #ifdef D_MS_EXTENSIONS
- static void inc_dec_edit_value(MS_WIDGET *widget, MS_UOP uop, char param)
- {
- MS_EDIT *pmse = PEDIT(widget);
- BOOL bCanChangeValue = FALSE;
- DWORD dw;
-
- edit_convert( pmse, &dw );
- switch ( uop )
- {
- case MS_UOP_LEFT:
- case MS_UOP_DOWN:
- // edit value -- ( validate first )
- bCanChangeValue = ( dw > 0 );
- if ( bCanChangeValue )
- dw--;
- break;
- case MS_UOP_UP:
- case MS_UOP_RIGHT:
- // edit value ++ ( validate first )
- {
- DWORD dwMaxValue = 0;
- int iMaxWidth = pmse->max_width;
- if ( MS_IS_EDIT_HEX( pmse ) )
- {
- while ( iMaxWidth-- )
- {
- dwMaxValue <<= 4;
- dwMaxValue += 0xF;
- }
- }
- else
- {
- while ( iMaxWidth-- )
- {
- dwMaxValue *= 10;
- dwMaxValue += 9;
- }
- }
- bCanChangeValue = ( dw < dwMaxValue );
- }
- if ( bCanChangeValue )
- dw++;
- break;
- }
- if ( bCanChangeValue )
- {
- if ( MS_IS_EDIT_HEX( pmse ) )
- {
- num_to_hex_str( dw, pmse->present.text, pmse->max_width );
- }
- else
- {
- num_to_str( dw, pmse->present.text, pmse->max_width );
- }
- OSD_SetOrigin( widget->parent );
-
- edit_display( widget, C_FOCUSED );
- if ( pmse->action )
- pmse->action(pmse->present.text);
- // Note we reset regardless of whether the action function is NULL
- #ifdef D_MS_EXTENSIONS
- MS_RESET_ACTION_PENDING(pmse);
- #endif // D_MS_EXTENSIONS
- }
- }
- #endif // D_MS_EXTENSIONS
- MS_UOP edit_user_op(MS_WIDGET *widget,MS_UOP uop,char param)
- {
- MS_EDIT *ms_edit = PEDIT(widget);
-
- switch (uop) {
- case MS_UOP_DELETE:
- return MS_UOP_NOP;
- case MS_UOP_CLEAR:
- _wcsnset( ((wchar_t *) ms_edit->present.text), L'-', ms_edit->max_width );
- //param = 1;
- // REMINDER see if the param assignment is really necessary
- if ( param == !C_FOCUSED )
- param = ( (((MS_DIALOG *) widget->parent)->pwli_focus->widget == widget) ? C_FOCUSED : !C_FOCUSED );
- ms_edit->current_num = 0;
- // Fall through!
- case MS_UOP_DISPLAY:
- edit_display(widget,param);
- #ifdef D_MS_EXTENSIONS
- #else
- ms_edit->current_num = 0;
- #endif
- return MS_UOP_NOP;
- 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, (unsigned char)(uop - MS_UOP_0));
- return MS_UOP_NOP;
- }
- //break;
- #ifdef D_MS_EXTENSIONS
- case MS_UOP_A:
- case MS_UOP_B:
- case MS_UOP_C:
- case MS_UOP_D:
- case MS_UOP_E:
- case MS_UOP_F:
- if ( MS_IS_EDIT_HEX(ms_edit) )
- {
- number_select(ms_edit, (unsigned char)(0x0A + uop - MS_UOP_A));
- return MS_UOP_NOP;
- }
- break;
- #endif // D_MS_EXTENSIONS
- #ifdef D_MS_EXTENSIONS
- case MS_UOP_LEFT:
- case MS_UOP_RIGHT:
- if ( MS_IS_EDIT_LR(ms_edit) )
- {
- inc_dec_edit_value(widget, uop, param);
- return MS_UOP_NOP;
- }
- break;
- case MS_UOP_UP:
- case MS_UOP_DOWN:
- if ( MS_IS_EDIT_UD(ms_edit) )
- {
- inc_dec_edit_value(widget, uop, param);
- return MS_UOP_NOP;
- }
- break;
- #endif // D_MS_EXTENSIONS
- }
- if (uop != MS_UOP_ENTER) {
- return uop;
- }
- if ( ms_edit->action )
- ms_edit->action(ms_edit->present.text);
- #ifdef D_MS_EXTENSIONS
- MS_RESET_ACTION_PENDING(ms_edit);
- #endif // D_MS_EXTENSIONS
- ms_edit->current_num = 0;
- return MS_UOP_NOP;
- }
- static void init_edit(MS_EDIT *mse, MS_POS *pos,MS_COLOR color,void *text,void (* action)(void *), unsigned char max_width,unsigned char attr)
- {
- #ifdef _DEBUG
- if (NULL == mse) {
- tr_printf(("FATAL: init_edit() Failed: NULL control.n"));
- return;
- }
- #endif //_DEBUG
- ((MS_WIDGET *)mse)->pos = *pos;
- ((MS_WIDGET *)mse)->parent = NO_PARENT;
- mse->present.text = text;
- mse->action = action;
- mse->max_width = max_width;
- mse->current_num = 0;
- ((MS_WIDGET *)mse)->attr = attr | MS_ASCII;
- ((MS_WIDGET *)mse)->color = color;
- ((MS_WIDGET *)mse)->user_op = edit_user_op;
-
- ((MS_WIDGET *)mse)->attrh = ALIGN_CENTER;
- }
- // text must be a valid memory, size "max_width" plus one , ended with ' '
- MS_EDIT *MS_create_edit(MS_POS *pos,MS_COLOR color,void *text,void (* action)(void *), unsigned char max_width,unsigned char attr)
- {
- MS_EDIT *mse;
- dbg_printf(("MS_create_editn"));
- mse = PEDIT(malloc(sizeof(MS_EDIT)));
- #ifdef _DEBUG
- if (NULL == mse) {
- tr_printf(("FATAL: MS_create_edit() Failed: Low system resources.n"));
- return NULL;
- }
- #endif //_DEBUG
- init_edit(mse, pos, color, text, action, max_width, attr);
- return mse;
- }