MS_DLG.C
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:29k
- /* **************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: MS_DLG.C $
- *
- * Description:
- * ============
- * Manipulation of menu dialogue
- *
- * Log:
- * ====
- * $Revision: 14 $
- * Last Modified by $Author: Fwang $ at $Modtime: 2/02/04 2:04p $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/UI/Menu_sys/MS_DLG.C $
- *
- * 14 2/02/04 2:26p Fwang
- * Add OSD_CHECK_PALETTE. Check osd palette before turn on OSD. Rewrite
- * osd palette if error detected.
- *
- * 13 10/28/03 10:09a Leslie
- * clean up the MS_remove_item_rapidly
- *
- * 12 8/29/03 11:55a Leonh
- * Clean up clips type and disc type because now add DVD ROM for clips
- *
- * 11 03-07-24 10:38 Frankm
- * Modify MS_remove_item_rapidly().
- *
- * 10 03-07-11 15:41 Leonm
- *
- * 9 03-02-19 15:10 Rogerl
- * Add MS_DIALOG_CYCLIC_SELECTION support
- *
- * 8 10/30/02 17:49 Rond
- *
- * 13 5/22/02 8:52a Tomasp
- * Changed include paths.
- *
- * 12 10/05/02 14:46 Nirm
- * - Corrected debug-messages.
- *
- * 11 23/04/02 9:39 Nirm
- * - Added dependency in "Config.h".
- *
- * 10 11/03/02 12:41 Nirm
- * Debug message in case of memory allocation failure.
- *
- * 9 2/27/02 7:02a Tomasp
- * Changed get_blk/rel_blk to malloc,free.
- *
- * 8 30/01/02 20:47 Nirm
- * Compilation-Warnings removal.
- *
- * 6 16/01/02 8:57 Nirm
- * Fixed debug-messages.
- *
- * 5 13/01/02 16:34 Atai
- * Remove old Defines
- *
- * 4 9/01/02 18:23 Nirm
- * Corrected Include-Paths.
- *
- * 3 30/12/01 9:59 Atai
- * remove warning
- *
- * 2 25/12/01 10:34 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 "Includesysdefs.h"
- #include "PlaycoreCoremaincoregdef.h"
- #include "UIMenu_Sysms_wdgt.h"
- #include "UIMenu_Sysms_lib.h"
- #include "UIMenu_Sysosd_drv.h"
- #include "decoderOSDLayou.h"
- //START of customer specific include files
- #include "customer.h"
- //END of customer specific include files
- #define ROM_START 0x4000
- #define MK_FP(seg,ofs) ((void __seg *)(seg) + (void __near *)(ofs))
- #define IS_IN_ROM(_fp_) ( (void huge *)(_fp_) >= (void huge *) MK_FP(ROM_START,0) )
- //
- // Delete an MS_DIALOG
- //
- // -- Calls the close functions for all sub-dialogs
- // and for the dialog ( or screen ) itself.
- //
- // -- Destroys the widget list
- //
- static void delete(MS_WIDGET *widget)
- {
- WIDGET_LIST_ITEM *curr = ((MS_DIALOG *)widget)->pwli_widget_list;
- WIDGET_LIST_ITEM *next;
- /* Turn Off OSD when closing menu */
- if (widget->parent == NO_PARENT)
- {
- OSD_TurnOff();
- }
- // Free the widget list
- while (curr)
- {
- // Remember the next pointer before we dispose its containing item
- next = curr->next;
- // If the current item's widget is a dialog, call its close function.
- // This should free the contained widgets
- if (MS_IS_DIALOG_BOX(curr->widget))
- {
- // Permit null close functions
- if ( ((MS_DIALOG *) curr->widget)->on_close )
- ((MS_DIALOG *)curr->widget)->on_close();
- }
-
- // Dispose the list item (created when the widget was added)
- // Note this doesn't dispose the widget itself
- free(curr);
- // On to the next list item
- curr = next;
- }
-
- // Support nested dialogs
- #ifdef D_MS_EXTENSIONS
- #else
- // If this is the top level
- if (widget->parent == NO_PARENT)
- #endif // D_MS_EXTENSIONS
- {
- // Call the close function
- // Permit null close functions
- if ( ((MS_DIALOG *) widget)->on_close )
- ((MS_DIALOG *)widget)->on_close();
- }
- }
- // Change the focus of a dialog to the specified widget
- void MS_change_focus(MS_DIALOG *pDialog, MS_WIDGET *pWidget)
- {
- WIDGET_LIST_ITEM *pwli;
-
- #ifdef D_MS_EXTENSIONS
- #ifdef _DEBUG
- WIDGET_LIST_ITEM *pwli_prev_focused = pDialog->pwli_focus;
- #endif // _DEBUG
- #else
- pDialog->pwli_prev_focused = pDialog->pwli_focus;
- #endif // D_MS_EXTENSIONS
- // ZORAN CDE0404 >>>
- pwli = pDialog->pwli_widget_list;
- while ( pwli )
- {
- if ( pwli->widget == pWidget )
- {
- pDialog->pwli_focus = pwli;
- break;
- }
- else
- pwli = pwli->next;
- }
- #ifdef _DEBUG
- #ifdef D_MS_EXTENSIONS
- if ( pwli_prev_focused == pDialog->pwli_focus )
- #else
- if ( pDialog->pwli_prev_focused == pDialog->pwli_focus )
- #endif // D_MS_EXTENSIONS
- {
- dbg_printf(("WARNING: MS_change_focus(): New is the same as the previous focused item!n"));
- }
- #endif // _DEBUG
- }
- static WIDGET_LIST_ITEM *first_selectable( MS_DIALOG *pDialog )
- {
- WIDGET_LIST_ITEM *pwli = pDialog->pwli_widget_list;
- while ( pwli )
- {
- if ( MS_IS_SELECTABLE(pwli->widget) )
- break;
- else
- pwli = pwli->next;
- }
- return pwli;
- }
- static WIDGET_LIST_ITEM *last_selectable( MS_DIALOG *pDialog )
- {
- WIDGET_LIST_ITEM *pwli = pDialog->pwli_widget_list;
- WIDGET_LIST_ITEM *pwliTentative = NULL;
- while ( pwli )
- {
- if ( MS_IS_SELECTABLE(pwli->widget) )
- pwliTentative = pwli;
- pwli = pwli->next;
- }
- return pwliTentative;
- }
- // Change the focus of a dialog to the specified widget list item
- static void change_focus_wli(MS_DIALOG *pDialog, WIDGET_LIST_ITEM *pwliNewFocus, MS_UOP uop)
- {
- WIDGET_LIST_ITEM *pwliFocus = pDialog->pwli_focus;
- MS_WIDGET *pmswFocus = NULL;
- MS_DIALOG *pmsd = NULL;
- MS_WIDGET *widget = NULL;
- MS_DIALOG *pmsdOrigin = NULL;
- if ( pwliFocus )
- {
- widget = pwliFocus->widget;
- if ( MS_IS_DIALOG_BOX(widget) )
- {
- pmsd = pDialog;
- while ( pmsd )
- {
- // save current focus
- pwliFocus = pmsd->pwli_focus;
- #ifdef D_MS_EXTENSIONS
- #else
- pmsd->pwli_prev_focused = pwliFocus;
- #endif // D_MS_EXTENSIONS
- // clear current focus
- pmsd->pwli_focus = NULL;
- // clear focus in all sub-dialogs
- pmsd = NULL;
- if ( pwliFocus )
- {
- pmswFocus = pwliFocus->widget;
- if ( MS_IS_DIALOG_BOX(pmswFocus) )
- pmsd = (MS_DIALOG *) pmswFocus;
- } // if ( pwliFocus )
- } // while ( pmsd )
- } // if ( MS_IS_DIALOG_BOX(widget) )
- else
- {
- pDialog->pwli_focus = NULL;
- } // if ( MS_IS_DIALOG_BOX(widget) )
- OSD_SetOrigin( (MS_WIDGET *) pDialog );
- MS_display( widget );
- #ifdef D_MS_EXTENSIONS
- MS_CALL_USER_OP( widget, MS_UOP_EXT_HELP, !C_FOCUSED );
- #endif
- } // if ( pwliFocus )
- pDialog->pwli_focus = pwliNewFocus;
- if ( pwliNewFocus )
- {
- pmsdOrigin = pDialog;
- widget = pwliNewFocus->widget;
- // Set the focus in all sub-dialogs
- if ( MS_IS_DIALOG_BOX(pwliNewFocus->widget) )
- {
- pmsd = (MS_DIALOG*)pwliNewFocus->widget;
- while ( pmsd )
- {
- if ( (uop == MS_UOP_RIGHT) || (uop == MS_UOP_DOWN) )
- {
- pwliNewFocus = first_selectable( pmsd );
- }
- else
- {
- pwliNewFocus = last_selectable( pmsd );
- } // if ( (uop == MS_UOP_RIGHT) || (uop == MS_UOP_DOWN) )
- #ifdef D_MS_EXTENSIONS
- #else
- pmsd->pwli_prev_focused = pmsd->pwli_focus;
- #endif // D_MS_EXTENSIONS
- // Set the focus
- pmsd->pwli_focus = pwliNewFocus;
- // Proceed to next sub-dialog
- pmsd = NULL;
- if ( pwliNewFocus )
- {
- pmswFocus = pwliNewFocus->widget;
- if ( MS_IS_DIALOG_BOX(pmswFocus) )
- pmsd = (MS_DIALOG *) pmswFocus;
- } // if ( pwliNewFocus )
- } // while ( pmsd )
- } // if ( MS_IS_DIALOG_BOX(pwliNewFocus->widget) )
- OSD_SetOrigin( (MS_WIDGET *) pmsdOrigin );
- MS_CALL_USER_OP( widget, MS_UOP_DISPLAY, C_FOCUSED );
- #ifdef D_MS_EXTENSIONS
- MS_CALL_USER_OP( widget, MS_UOP_EXT_HELP, C_FOCUSED );
- #endif // D_MS_EXTENSIONS
- } // if ( pwliNewFocus != NULL )
- }
- //
- // Display a dialog and its contents
- //
- static int display(MS_WIDGET *widget)
- {
- MS_DIALOG *msDlg = (MS_DIALOG *) widget;
- WIDGET_LIST_ITEM *curr = msDlg->pwli_widget_list;
- #ifdef D_MS_EXTENSIONS
- char cFocus = !C_FOCUSED;
- if ( MS_IS_SELECTABLE(widget) &&
- ( (msDlg->pwli_focus == NULL) || (/*MS_IS_GROUP(widget) && */MS_IS_HIGHLIGHT_AS_GROUP(widget)) ) &&
- ( widget->parent->pwli_focus ) &&
- ( widget->parent->pwli_focus->widget == msDlg )
- )
- cFocus = C_FOCUSED;
- #endif // D_MS_EXTENSIONS
-
- // Erase the dialog when appropriate
- if (!MS_HAS_NO_BACKGROUND(widget))
- {
- OSD_PutRect(widget->pos.x,
- widget->pos.y,
- widget->pos.w,
- widget->pos.h,
- // Highlight dialog when selectable and focused and has no focus
- #ifdef D_MS_EXTENSIONS
- BACK_COLOR(widget, cFocus));
- #else
- BG_COLOR(widget->color));
- #endif // D_MS_EXTENSIONS
- }
- OSD_SetOrigin(widget);
- while (curr)
- {
- OSD_SetOrigin(widget);
- curr->widget->user_op( curr->widget,
- MS_UOP_DISPLAY,
- //Highlight dialog when selectable and focused and has no focus
- #ifdef D_MS_EXTENSIONS
- (char)( ((cFocus == C_FOCUSED) || (curr == msDlg->pwli_focus)) ? C_FOCUSED : !C_FOCUSED) );
- #else
- (char)((curr == msDlg->pwli_focus) ? C_FOCUSED : !C_FOCUSED) );
- #endif // D_MS_EXTENSIONS
- curr = curr->next;
- }
- #ifdef D_MS_EXTENSIONS
- if ( msDlg->pwli_focus )
- MS_CALL_USER_OP(msDlg->pwli_focus->widget, MS_UOP_EXT_HELP, C_FOCUSED );
- #endif // D_MS_EXTENSIONS
- return MS_UOP_NOP;
- }
- static WIDGET_LIST_ITEM *find_up( WIDGET_LIST_ITEM *curr, MS_DIALOG *dialog )
- {
- int y = -1;
- MS_WIDGET *loopWidget;
- WIDGET_LIST_ITEM *candidate = NULL;
- while ( curr->prev )
- {
- curr = curr->prev;
- loopWidget = curr->widget;
- if ( MS_IS_SELECTABLE(loopWidget) && (loopWidget->pos.y < dialog->pwli_focus->widget->pos.y))
- {
- if (y == -1)
- {
- // Found the line above
- y = loopWidget->pos.y;
- }
-
- if (y == loopWidget->pos.y)
- {
- if ( (loopWidget->pos.x < dialog->pwli_focus->widget->pos.x) && candidate ) //FW0317 Change >= to > for moving in the same column
- {
- // Found the above (left) widget
- break;
- }
- else
- {
- candidate = curr;
- }
- }
- else
- {
- // No more widgets in the above lines
- break;
- }
- }
- }
- return ( y == -1 ? NULL : candidate );
- }
- static WIDGET_LIST_ITEM *find_down( WIDGET_LIST_ITEM *curr, MS_DIALOG *dialog )
- {
- int y = -1;
- MS_WIDGET *loopWidget;
- WIDGET_LIST_ITEM *candidate = NULL;
- // Look for the widget below the focused widget
- while (curr->next)
- {
- curr = curr->next;
- loopWidget = curr->widget;
- if ( MS_IS_SELECTABLE(loopWidget) && (loopWidget->pos.y > dialog->pwli_focus->widget->pos.y) )
- {
- if (y == -1)
- {
- // Found the line below
- y = loopWidget->pos.y;
- }
- if (y == loopWidget->pos.y)
- {
- if ( (loopWidget->pos.x > dialog->pwli_focus->widget->pos.x) && candidate ) //FW0317 Change >= to > for moving in the same column
- {
- // Found a widget to the right
- break;
- }
- else
- {
- candidate = curr;
- }
- }
- else
- {
- // No more widgets in the line below
- break;
- }
- }
- }
- return ( y == -1 ? NULL : candidate );
- }
- MS_UOP dialog_user_op(MS_WIDGET *widget,MS_UOP uop, char param)
- {
- MS_UOP dialog_uop = uop;
- MS_DIALOG *dialog = (MS_DIALOG *)widget;
- MS_WIDGET *focusWidget;
- WIDGET_LIST_ITEM *curr = NULL;
- BOOL bFound = FALSE;
- // Thes uops are always handled in the standard way
- switch (uop)
- {
- case MS_UOP_DELETE:
- delete(widget);
- if (widget->parent == NO_PARENT)
- {
- OSD_TurnOff();
- }
- return MS_UOP_NOP;
- case MS_UOP_DISPLAY:
- return display(widget);
- #ifdef D_USE_RETURN_IN_MENUS
- case MS_UOP_RETURN:
- if (( widget->parent == NO_PARENT ))//LeonH_0829_2003_a:Clear up
- {
- MS_return_to_menu();
- return MS_UOP_NOP;
- }
- break;
- #endif // D_USE_RETURN_IN_MENUS
- }
- curr = dialog->pwli_focus;
- if ( curr == NULL )
- {
- return uop;
- }
- focusWidget = curr->widget;
- dialog_uop = focusWidget->user_op(focusWidget, uop, param);
- #ifdef D_MS_EXTENSIONS
- /// Reassign curr in case user_op changed the focus
- if ( curr != dialog->pwli_focus )
- {
- #ifdef NO_C_STDLIB
- dbg_printf(("INFO: dialog_user_op(): focus widget's user_op changed the focus!n"));
- #endif
-
- curr = dialog->pwli_focus;
- }
- #endif // D_MS_EXTENSIONS
- switch (dialog_uop)
- {
- case MS_UOP_ENTER:
- case MS_UOP_NOP:
- return MS_UOP_NOP;
- case MS_UOP_UP:
- curr = find_up( curr, dialog );
- if ( curr == NULL )
- {
- // No widget above
- dbg_printf(("WARNING: dialog_user_op(): Cannot move upn"));
- if ( MS_IS_CLOSE_ON_UP(dialog) )
- {
- MS_remove_item((MS_WIDGET *) dialog);
- return MS_UOP_NOP;
- }
- #ifdef DIALOG_CYCLIC_SELECTION
- if ( MS_IS_DIALOG_CYCLIC_SELECTION(dialog) )
- {
- dbg_printf(("WARNING: dialog_user_op(): Cyclic operation to last selectable n"));
- curr = last_selectable( dialog );
- break;
- }
- #endif
- curr = dialog->pwli_focus;
- if ( ((MS_WIDGET *) dialog)->parent == NO_PARENT )
- uop = MS_UOP_NOP;
- }
- break;
- case MS_UOP_DOWN:
- curr = find_down( curr, dialog );
- if ( curr == NULL )
- {
- // No widget below
- dbg_printf(("WARNING: dialog_user_op(): Cannot move downn"));
- #ifdef DIALOG_CYCLIC_SELECTION
- if ( MS_IS_DIALOG_CYCLIC_SELECTION(dialog) )
- {
- dbg_printf(("WARNING: dialog_user_op(): Cyclic operation to first selectable n"));
- curr = first_selectable( dialog );
- break;
- }
- #endif
- curr = dialog->pwli_focus;
- if ( ((MS_WIDGET *) dialog)->parent == NO_PARENT )
- uop = MS_UOP_NOP;
- }
- break;
- case MS_UOP_LEFT:
- while (curr->prev)
- {
- curr = curr->prev;
- if (MS_IS_SELECTABLE(curr->widget))
- {
- bFound = TRUE;
- break;
- }
- }
- if ( !bFound )
- {
- dbg_printf(("WARNING: dialog_user_op(): Can't move leftn"));
- #ifdef D_MS_EXTENSIONS
- if ( MS_IS_DIALOG_WRAP_LR(dialog) )
- {
- curr = last_selectable( dialog );
- }
- else
- {
- curr = dialog->pwli_focus;
- if ( (((MS_WIDGET *) dialog)->parent == NO_PARENT) ||
- ( MS_IS_CLOSE_ON_UP(dialog) ) )
- uop = MS_UOP_NOP;
- }
- #else // D_MS_EXTENSIONS
- #ifdef DIALOG_CYCLIC_SELECTION
- if ( MS_IS_DIALOG_CYCLIC_SELECTION(dialog) )
- {
- dbg_printf(("WARNING: dialog_user_op(): Cyclic operation to last selectable n"));
- curr = last_selectable( dialog );
- break;
- }
- #endif
- curr = dialog->pwli_focus;
- if ( (((MS_WIDGET *) dialog)->parent == NO_PARENT) ||
- ( MS_IS_CLOSE_ON_UP(dialog) ) )
- uop = MS_UOP_NOP;
- #endif // D_MS_EXTENSIONS
-
- }
- break;
- case MS_UOP_RIGHT:
- while (curr->next)
- {
- curr = curr->next;
- if (MS_IS_SELECTABLE(curr->widget))
- {
- bFound = TRUE;
- break;
- }
- }
- if ( !bFound )
- {
- dbg_printf(("WARNING: dialog_user_op(): Can't move rightn"));
- #ifdef D_MS_EXTENSIONS
- if ( MS_IS_DIALOG_WRAP_LR( dialog ) )
- {
- curr = first_selectable( dialog );
- }
- else
- {
- curr = dialog->pwli_focus;
- if ( (((MS_WIDGET *) dialog)->parent == NO_PARENT) ||
- ( MS_IS_CLOSE_ON_UP(dialog) ) )
- uop = MS_UOP_NOP;
- }
- #else // D_MS_EXTENSIONS
- #ifdef DIALOG_CYCLIC_SELECTION
- if ( MS_IS_DIALOG_CYCLIC_SELECTION(dialog) )
- {
- dbg_printf(("WARNING: dialog_user_op(): Cyclic operation to first selectable n"));
- curr = first_selectable( dialog );
- break;
- }
- #endif
- curr = dialog->pwli_focus;
- if ( (((MS_WIDGET *) dialog)->parent == NO_PARENT) ||
- ( MS_IS_CLOSE_ON_UP(dialog) ) )
- uop = MS_UOP_NOP;
- #endif // D_MS_EXTENSIONS
- }
- break;
- }
- if (curr != dialog->pwli_focus)
- {
- // Focus changed
- change_focus_wli( dialog, curr, dialog_uop );
- uop = MS_UOP_NOP;
- }
- return uop;
- }
- //
- // Add a widget to a dialog and set the focus if specified
- //
- // -- Create a widget list item for the widget
- // -- Change the focus to the item, if specified
- //
- void MS_add_item(MS_DIALOG *dialog, MS_WIDGET *widget, char focus)
- {
- WIDGET_LIST_ITEM *curr;
- WIDGET_LIST_ITEM *last;
- WIDGET_LIST_ITEM *new_list_item;
-
- dbg_printf(("malloc WIDGET_LIST_ITEMn"));
- // Create a widget_list_item for the widget
- new_list_item = malloc(sizeof(WIDGET_LIST_ITEM));
- // Set the list item's widget member
- new_list_item->widget = widget;
- // Change the dialog's focus, if specified
- if ( focus == C_FOCUSED )
- {
- #ifdef D_MS_EXTENSIONS
- #else
- dialog->pwli_prev_focused = dialog->pwli_focus;
- #endif // D_MS_EXTENSIONS
- dialog->pwli_focus = new_list_item;
- }
- // Initialize last and current widget list items for insertion
- // to the beginning of the list
- last = curr = dialog->pwli_widget_list;
- if ( curr == NULL )
- {
- // List was empty:
- // -- Put the new item at the beginning of the list
- dialog->pwli_widget_list = new_list_item;
- new_list_item->next = new_list_item->prev = curr;
- // REMINDER may be responsible for wrong background color (0)
- // Otherwise, this may have been put here to distinguish screens from dialogs
- // REMINDER This might have been a way of testing whether the item was CONST
- // What happens if you assign a value to a ROM location? (hopefully, the location just won't change )
- // if (widget->parent != NO_PARENT)
- {
- if (!IS_IN_ROM(widget))
- widget->parent = dialog;
- }
- return;
- }
- // Not the first item:
- // -- Find the correct place to insert the item
- // ( before first item with bigger line number, or on same line to the right )
- //
- while (last)
- {
- curr = last;
- if ( (curr->widget->pos.y > widget->pos.y) ||
- ((curr->widget->pos.y == widget->pos.y) && (curr->widget->pos.x > widget->pos.x)) )
- {
- // link to previous item
- new_list_item->prev = curr->prev;
- // link to next item
- new_list_item->next = curr;
- if (curr->prev)
- {
- // Not the first item
- // link as previous item's next item
- curr->prev->next = new_list_item;
- // link as next item's previous item
- curr->prev = new_list_item;
- }
- else
- {
- // First item
- // No previous item
- new_list_item->prev = 0;
-
- // Next item is the former first item
- new_list_item->next = dialog->pwli_widget_list;
- // Link former first item to new item
- dialog->pwli_widget_list->prev = new_list_item;
- // Make the new item the first in the list
- dialog->pwli_widget_list = new_list_item;
- }
- // REMINDER may be responsible for wrong background color (0)
- // Otherwise, this may have been put here to distinguish screens from dialogs
- // if (widget->parent != NO_PARENT)
- {
- if (!IS_IN_ROM(widget))
- widget->parent = dialog;
- }
- return;
- }
-
- // Advance to next item
- last = curr->next;
- }
-
- // New item should be the last item in the list
-
- // No next item
- new_list_item->next = 0;
- // Link as previous item's next item
- curr->next = new_list_item;
- // Link to previous item
- new_list_item->prev = curr;
- // REMINDER may be responsible for wrong background color (0)
- // Otherwise, this may have been put here to distinguish screens from dialogs
- // if (widget->parent != NO_PARENT)
- {
- if (!IS_IN_ROM(widget))
- widget->parent = dialog;
- }
- return;
- }
- void MS_remove_item_rapidly(MS_DIALOG *dialog, MS_WIDGET *widget)
- {
- WIDGET_LIST_ITEM *curr;
-
- if ( dialog == NO_PARENT )
- {
- dbg_printf(("WARNING: MS_remove_item_rapidly(): Item has no parent!n"));
- return;
- }
- if ( dialog->pwli_focus->widget == widget ) {
- #ifdef D_MS_EXTENSIONS
- // Clear the focus here
- // The focus item shouldn't be removed while the dialog is active
- // without resetting the focus afterward
- dialog->pwli_focus = NULL;
- #else
- dialog->pwli_focus = dialog->pwli_prev_focused;
- #endif // D_MS_EXTENSIONS
- }
- curr = dialog->pwli_widget_list;
- while (curr)
- {
- if (curr->widget == widget)
- {
- if (!curr->prev)
- {
- // First item
- dialog->pwli_widget_list = curr->next;
- }
- else
- {
- curr->prev->next = curr->next;
- }
- if (curr->next)
- {
- // Removed item is not the last item
- curr->next->prev = curr->prev;
- }
- // Item has been de-linked, so
- // free it
- free(curr);
- return;
- }
- curr = curr->next;
- }
- dbg_printf(("WARNING: MS_remove_item_rapidly(): Item not found in the listn"));
- // Item not found in the list
- return;
- }
- void MS_delete(MS_WIDGET *widget)
- {
- widget->user_op(widget,MS_UOP_DELETE,0);
- free(widget);
- }
- //
- // Hide a widget
- //
- // This just erases the widget's rectangle.
- // The menu system doesn't attempt to remember that the widget is hidden.
- //
- void MS_hide(MS_WIDGET *widget,MS_DIALOG *parent)
- {
- OSD_PutRect(widget->pos.x, widget->pos.y, widget->pos.w, widget->pos.h,
- BG_COLOR(parent->widget.color));
- }
- //Implement YesNo dialog for Password Menu
- #ifdef ZS5XX_PASSWORD
- // Remove a widget from its parent's widget list
- //
- // Return 1 if the item was found and removed
- // Return 0 if the item wasn't found
- //
- // REMINDER Don't call this from the widget's close function
- //
- int MS_detach_item(MS_WIDGET *widget)
- {
- WIDGET_LIST_ITEM *curr;
- MS_DIALOG *dialog = widget->parent;
- if ( dialog == NO_PARENT )
- {
- dbg_printf(("WARNING: MS_detach_item(): Item has no parent!n"));
- return 0;
- }
-
- {
- if ( dialog->pwli_focus->widget == widget )
- #ifdef D_MS_EXTENSIONS
- // Clear the focus here
- // The focus item shouldn't be removed while the dialog is active
- // without resetting the focus afterward
- dialog->pwli_focus = NULL;
- #else
- dialog->pwli_focus = dialog->pwli_prev_focused;
- #endif // D_MS_EXTENSIONS
- }
- curr = dialog->pwli_widget_list;
- while (curr)
- {
- if (curr->widget == widget)
- {
- if (!curr->prev)
- {
- WIDGET_LIST_ITEM *next = curr->next;
- // First item
- dialog->pwli_widget_list = next;
- }
- else
- {
- curr->prev->next = curr->next;
- }
- if (curr->next)
- {
- WIDGET_LIST_ITEM *prev = curr->prev;
-
- // Removed item is not the last item
- curr->next->prev = prev;
- }
-
- // Item has been de-linked, so
- // free it
- free(curr);
- if (widget->parent != NO_PARENT)
- {
- OSD_SetOrigin((MS_WIDGET *)widget->parent);
- }
- OSD_PutRect(widget->pos.x,widget->pos.y,widget->pos.w,widget->pos.h,BG_COLOR(widget->parent->widget.color));
-
- // Item is in a dialog or screen
- if (widget->parent != NO_PARENT)
- {
- MS_refresh(widget->parent);
- #ifndef ZS5XX //For ZS5, do not execute the following line.
- widget->parent = NO_PARENT;
- #endif //ZS5XX
- }
- return 1;
- }
- curr = curr->next;
- }
- dbg_printf(("WARNING: MS_detach_item(): Item not found in the listn"));
- // Item not found in the list
- return 0;
- }
- #define CALL_ON_CLOSE(_on_close_) if ( _on_close_ ) _on_close_()
- int MS_remove_item(MS_WIDGET *widget)
- {
- int iReturn = MS_detach_item(widget);
- if ( iReturn )
- {
- if (MS_IS_DIALOG_BOX(widget))
- {
- CALL_ON_CLOSE(((MS_DIALOG *)widget)->on_close);
- }
- }
- return iReturn;
- }
- #else // ZS5XX_PASSWORD
- // Remove a widget from its parent's widget list
- // if the item is a dialog, call its close function
- //
- // Return 1 if the item was found and removed
- // Return 0 if the item wasn't found
- //
- // REMINDER Don't call this from the widget's close function
- //
- int MS_remove_item(MS_WIDGET *widget)
- {
- WIDGET_LIST_ITEM *curr;
- MS_DIALOG *dialog = widget->parent;
- if ( dialog == NO_PARENT )
- {
- dbg_printf(("WARNING: MS_remove_item(): Item has no parent!n"));
- return 0;
- }
-
- if ( dialog->pwli_focus->widget == widget ) {
- #ifdef D_MS_EXTENSIONS
- // Clear the focus here
- // The focus item shouldn't be removed while the dialog is active
- // without resetting the focus afterward
- dialog->pwli_focus = NULL;
- #else
- dialog->pwli_focus = dialog->pwli_prev_focused;
- #endif // D_MS_EXTENSIONS
- }
- curr = dialog->pwli_widget_list;
- while (curr)
- {
- if (curr->widget == widget)
- {
- if (!curr->prev)
- {
- // First item
- dialog->pwli_widget_list = curr->next;
- }
- else
- {
- curr->prev->next = curr->next;
- }
- if (curr->next)
- {
- // Removed item is not the last item
- curr->next->prev = curr->prev;
- }
-
- // Item has been de-linked, so
- // free it
- free(curr);
- if (widget->parent != NO_PARENT)
- {
- OSD_SetOrigin((MS_WIDGET *)widget->parent);
- }
- OSD_PutRect(widget->pos.x,widget->pos.y,widget->pos.w,widget->pos.h,BG_COLOR(widget->parent->widget.color));
-
- // Item is in a dialog or screen
- if (widget->parent != NO_PARENT)
- {
- MS_refresh(widget->parent);
- }
- if (MS_IS_DIALOG_BOX(widget))
- {
- ((MS_DIALOG *)widget)->on_close();
- }
- return 1;
- }
- curr = curr->next;
- }
- dbg_printf(("WARNING: MS_remove_item(): Item not found in the listn"));
- // Item not found in the list
- return 0;
- }
- #endif // ZS5XX_PASSWORD
- int MS_refresh(MS_DIALOG *dialog)
- {
- WIDGET_LIST_ITEM *curr = dialog->pwli_widget_list;
- dbg_printf(("MS_refreshn"));
-
- OSD_SetOrigin((MS_WIDGET *) dialog);
- while (curr)
- {
- curr->widget->user_op(curr->widget, MS_UOP_DISPLAY, (char) ((curr == dialog->pwli_focus) ? C_FOCUSED : !C_FOCUSED));
- if ( MS_IS_DIALOG_BOX( curr->widget ) )
- {
- OSD_SetOrigin((MS_WIDGET *) dialog);
- }
- curr = curr->next;
- }
- return 1;
- }
- void MS_display(MS_WIDGET *widget)
- {
- widget->user_op(widget,MS_UOP_DISPLAY, !C_FOCUSED);
- }
- #ifdef OSD_DISPLAY_SPEED_TEST
- extern int osd_test_timer;
- #endif
- void MS_dialog_display(MS_DIALOG *dialog)
- {
- #ifdef OSD_DISPLAY_SPEED_TEST
- char sz_test[16];
- WORD save_menu_id;
- osd_test_timer=0;
- #endif
- if ( dialog->widget.parent == NO_PARENT )
- {
- OSD_TurnOff();
- ((MS_SCREEN *)dialog)->layout();
- }
- #ifdef OSD_CHECK_PALETTE
- if(!OSDCheckPalette()){
- OSDSetPalette( OSD_COLOR_PALETTE_0, (OSD_Palette *) go_CurrentLayout.m_pColorPalette );
- }
- #endif
- ((MS_WIDGET*)dialog)->user_op((MS_WIDGET*)dialog,MS_UOP_DISPLAY,1);
- if ( dialog->widget.parent == NO_PARENT )
- {
- OSD_TurnOn();
- }
- #ifdef OSD_DISPLAY_SPEED_TEST
- num_to_str(osd_test_timer,sz_test,3);
- save_menu_id = g_ui_active_menu_id;
- g_ui_active_menu_id = RUN_TIME_MENU_ID;
- ui_tmp_string(sz_test);
- g_ui_active_menu_id = save_menu_id;
- #endif
- }
- MS_UOP MS_user_operation(MS_SCREEN *screen,MS_UOP uop, char param)
- {
- //Enable override of screen user_op
- uop = MS_CALL_USER_OP( screen, uop, param );
-
- if ( g_ms_deferred_action )
- {
- g_ms_deferred_action();
- MS_set_deferred_action( NULL );
- }
- if ( g_ms_bMustClose )
- {
- #ifdef D_USE_RETURN_IN_MENUS
- g_ms_bMustClose = FALSE;
- close_menu();
- #else
- close_menu();
- g_ms_bMustClose = FALSE;
- #endif // D_USE_RETURN_IN_MENUS
- }
- return uop;
- }
- // Optimize screen and dialog creation; prepare for dialog subclassing
- void MS_init_dialog(MS_DIALOG *dialog,
- MS_POS *pos,
- MS_COLOR color,
- MS_DIALOG *parent,
- void (*on_close)(void),
- unsigned short attr)
- {
- MS_WIDGET *widget;
- dbg_printf(("MS_init_dialogn"));
- #ifdef _DEBUG
- if (NULL == dialog) {
- tr_printf(("FATAL: MS_init_dialog() Failed: NULL control.n"));
- return;
- }
- #endif //_DEBUG
- // Use explicit pointer instead of casting
- widget = &dialog->widget;
- widget->pos = *pos;
- widget->attr = attr | MS_DIALOG_BOX;
- widget->color = color;
- widget->user_op = dialog_user_op;
- widget->parent = parent;
- dialog->pwli_widget_list = NULL;
- dialog->pwli_focus = NULL;
- #ifdef D_MS_EXTENSIONS
- #else
- dialog->pwli_prev_focused = NULL;
- #endif // D_MS_EXTENSIONS
- dialog->on_close = on_close;
-
- widget->attrh = 0;
-
- return;
- }
- MS_DIALOG *MS_create_dialog(MS_POS *pos,MS_COLOR color,MS_DIALOG *parent,void (*on_close)(void),unsigned short attr)
- {
- MS_DIALOG *dialog;
- dbg_printf(("MS_create_dialogn"));
-
- dialog = (MS_DIALOG *)malloc(sizeof(MS_DIALOG));
- #ifdef _DEBUG
- if (NULL == dialog) {
- tr_printf(("FATAL: MS_create_dialog() Failed: Low system resources.n"));
- return NULL;
- }
- #endif //_DEBUG
-
- MS_init_dialog(dialog, pos, color, parent, on_close, attr);
- return dialog;
- }
- MS_SCREEN *MS_create_screen(MS_POS *pos,MS_COLOR color, unsigned short attr,void (*on_close)(void),void(*layout)(void))
- {
- MS_SCREEN *pScreen;
- dbg_printf(("MS_create_screen"));
-
- pScreen = (MS_SCREEN *)malloc(sizeof(MS_SCREEN));
- #ifdef _DEBUG
- if (NULL == pScreen) {
- tr_printf(("FATAL: MS_create_screen() Failed: Low system resources.n"));
- return NULL;
- }
- #endif //_DEBUG
- MS_init_dialog(&pScreen->dialog, pos, color, NO_PARENT, on_close, (MS_HOT_SPOT | attr));
- pScreen->layout = layout;
- return pScreen;
- }