]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Ui.c
Correct Data type conversion.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Ui.c
index 0d3c1ebce8f3e7c88339e268ee6397c928b40645..0e74c5800dea014a5073c88b7c952d110952ca09 100644 (file)
@@ -1134,7 +1134,7 @@ GetWidth (
     Width -= SUBTITLE_INDENT;\r
   }\r
 \r
-  return Width;\r
+  return (UINT16) (Width - LEFT_SKIPPED_COLUMNS);\r
 }\r
 \r
 /**\r
@@ -1704,7 +1704,7 @@ UiDisplayMenu (
     Row     = LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;\r
   }\r
 \r
-  Col = LocalScreen.LeftColumn;\r
+  Col = LocalScreen.LeftColumn + LEFT_SKIPPED_COLUMNS;\r
   BottomRow = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT - SCROLL_ARROW_HEIGHT - 1;\r
 \r
   Selection->TopRow = TopRow;\r
@@ -1775,8 +1775,8 @@ UiDisplayMenu (
         UpArrow         = FALSE;\r
         Row             = TopRow;\r
 \r
-        Temp            = SkipValue;\r
-        Temp2           = SkipValue;\r
+        Temp            = (UINTN) SkipValue;\r
+        Temp2           = (UINTN) SkipValue;\r
 \r
         ClearLines (\r
           LocalScreen.LeftColumn,\r
@@ -1833,7 +1833,6 @@ UiDisplayMenu (
           Temp  = 0;\r
           Row   = OriginalRow;\r
 \r
-          gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
           Status = ProcessOptions (Selection, MenuOption, FALSE, &OptionString);\r
           if (EFI_ERROR (Status)) {\r
             //\r
@@ -1981,6 +1980,7 @@ UiDisplayMenu (
             Row = OriginalRow;\r
             FreePool (StringPtr);\r
           }\r
+          gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
 \r
           //\r
           // Need to handle the bottom of the display\r
@@ -2296,6 +2296,7 @@ UiDisplayMenu (
         //\r
         // Don't print anything if it is a NULL help token\r
         //\r
+        ASSERT(MenuOption != NULL);\r
         if (MenuOption->ThisTag->Help == 0) {\r
           StringPtr = L"\0";\r
         } else {\r
@@ -2372,6 +2373,16 @@ UiDisplayMenu (
       //\r
       case '+':\r
       case '-':\r
+        //\r
+        // If the screen has no menu items, and the user didn't select UiReset\r
+        // ignore the selection and go back to reading keys.\r
+        //\r
+        if(IsListEmpty (&gMenuOption)) {\r
+          ControlFlag = CfReadKey;\r
+          break;\r
+        }\r
+\r
+        ASSERT(MenuOption != NULL);\r
         Statement = MenuOption->ThisTag;\r
         if ((Statement->Operand == EFI_IFR_DATE_OP)\r
           || (Statement->Operand == EFI_IFR_TIME_OP)\r
@@ -2407,6 +2418,16 @@ UiDisplayMenu (
 \r
       case ' ':\r
         if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) != FORMSET_CLASS_FRONT_PAGE) {\r
+          //\r
+          // If the screen has no menu items, and the user didn't select UiReset\r
+          // ignore the selection and go back to reading keys.\r
+          //\r
+          if(IsListEmpty (&gMenuOption)) {\r
+            ControlFlag = CfReadKey;\r
+            break;\r
+          }\r
+          \r
+          ASSERT(MenuOption != NULL);\r
           if (MenuOption->ThisTag->Operand == EFI_IFR_CHECKBOX_OP && !MenuOption->GrayOut) {\r
             ScreenOperation = UiSelect;\r
           }\r
@@ -2478,6 +2499,7 @@ UiDisplayMenu (
     case CfUiSelect:\r
       ControlFlag = CfCheckSelection;\r
 \r
+      ASSERT(MenuOption != NULL);\r
       Statement = MenuOption->ThisTag;\r
       if ((Statement->Operand == EFI_IFR_TEXT_OP) ||\r
           (Statement->Operand == EFI_IFR_DATE_OP) ||\r
@@ -2510,6 +2532,7 @@ UiDisplayMenu (
           }\r
           BufferSize = StrLen (StringPtr) / 2;\r
           DevicePath = AllocatePool (BufferSize);\r
+          ASSERT (DevicePath != NULL);\r
 \r
           //\r
           // Convert from Device Path String to DevicePath Buffer in the reverse order.\r
@@ -2744,11 +2767,13 @@ UiDisplayMenu (
 \r
     case CfUiLeft:\r
       ControlFlag = CfCheckSelection;\r
+      ASSERT(MenuOption != NULL);\r
       if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) {\r
         if (MenuOption->Sequence != 0) {\r
           //\r
           // In the middle or tail of the Date/Time op-code set, go left.\r
           //\r
+          ASSERT(NewPos != NULL);\r
           NewPos = NewPos->BackLink;\r
         }\r
       }\r
@@ -2756,11 +2781,13 @@ UiDisplayMenu (
 \r
     case CfUiRight:\r
       ControlFlag = CfCheckSelection;\r
+      ASSERT(MenuOption != NULL);\r
       if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) {\r
         if (MenuOption->Sequence != 2) {\r
           //\r
           // In the middle or tail of the Date/Time op-code set, go left.\r
           //\r
+          ASSERT(NewPos != NULL);\r
           NewPos = NewPos->ForwardLink;\r
         }\r
       }\r
@@ -2771,6 +2798,7 @@ UiDisplayMenu (
 \r
       SavedListEntry = TopOfScreen;\r
 \r
+      ASSERT(NewPos != NULL);\r
       if (NewPos->BackLink != &gMenuOption) {\r
         NewLine = TRUE;\r
         //\r
@@ -2785,6 +2813,7 @@ UiDisplayMenu (
           NewPos = NewPos->BackLink;\r
         }\r
 \r
+        Difference = MoveToNextStatement (TRUE, &NewPos);\r
         PreviousMenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
         DistanceValue = PreviousMenuOption->Skip;\r
 \r
@@ -2796,30 +2825,6 @@ UiDisplayMenu (
         //\r
         DistanceValue += AdjustDateAndTimePosition (TRUE, &NewPos);\r
 \r
-        //\r
-        // Check the previous menu entry to see if it was a zero-length advance.  If it was,\r
-        // don't worry about a redraw.\r
-        //\r
-        if ((INTN) MenuOption->Row - (INTN) DistanceValue < (INTN) TopRow) {\r
-          Repaint     = TRUE;\r
-          TopOfScreen = NewPos;\r
-        }\r
-\r
-        Difference = MoveToNextStatement (TRUE, &NewPos);\r
-        PreviousMenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
-        DistanceValue += PreviousMenuOption->Skip;\r
-\r
-        if ((INTN) MenuOption->Row - (INTN) DistanceValue  < (INTN) TopRow) {\r
-          if (Difference > 0) {\r
-            //\r
-            // Previous focus MenuOption is above the TopOfScreen, so we need to scroll\r
-            //\r
-            TopOfScreen = NewPos;\r
-            Repaint     = TRUE;\r
-            SkipValue = 0;\r
-            OldSkipValue = 0;\r
-          }\r
-        }\r
         if (Difference < 0) {\r
           //\r
           // We want to goto previous MenuOption, but finally we go down.\r
@@ -2830,6 +2835,14 @@ UiDisplayMenu (
             TopOfScreen = gMenuOption.ForwardLink;\r
             Repaint     = TRUE;\r
           }\r
+        } else if ((INTN) MenuOption->Row - (INTN) DistanceValue - Difference < (INTN) TopRow) {\r
+          //\r
+          // Previous focus MenuOption is above the TopOfScreen, so we need to scroll\r
+          //\r
+          TopOfScreen = NewPos;\r
+          Repaint     = TRUE;\r
+          SkipValue = 0;\r
+          OldSkipValue = 0;\r
         }\r
 \r
         //\r
@@ -2857,6 +2870,7 @@ UiDisplayMenu (
     case CfUiPageUp:\r
       ControlFlag     = CfCheckSelection;\r
 \r
+      ASSERT(NewPos != NULL);\r
       if (NewPos->BackLink == &gMenuOption) {\r
         NewLine = FALSE;\r
         Repaint = FALSE;\r
@@ -2911,6 +2925,7 @@ UiDisplayMenu (
     case CfUiPageDown:\r
       ControlFlag     = CfCheckSelection;\r
 \r
+      ASSERT (NewPos != NULL);\r
       if (NewPos->ForwardLink == &gMenuOption) {\r
         NewLine = FALSE;\r
         Repaint = FALSE;\r
@@ -2971,14 +2986,15 @@ UiDisplayMenu (
         MenuOption      = MENU_OPTION_FROM_LINK (NewPos);\r
         NewLine         = TRUE;\r
         NewPos          = NewPos->ForwardLink;\r
-        NextMenuOption  = MENU_OPTION_FROM_LINK (NewPos);\r
 \r
-        DistanceValue  += NextMenuOption->Skip;\r
         DistanceValue  += MoveToNextStatement (FALSE, &NewPos);\r
+        NextMenuOption  = MENU_OPTION_FROM_LINK (NewPos);\r
+\r
         //\r
         // An option might be multi-line, so we need to reflect that data in the overall skip value\r
         //\r
-        UpdateOptionSkipLines (Selection, NextMenuOption, &OptionString, SkipValue);\r
+        UpdateOptionSkipLines (Selection, NextMenuOption, &OptionString, (UINTN) SkipValue);\r
+        DistanceValue  += NextMenuOption->Skip;\r
 \r
         Temp = MenuOption->Row + MenuOption->Skip + DistanceValue - 1;\r
         if ((MenuOption->Row + MenuOption->Skip == BottomRow + 1) &&\r
@@ -3020,26 +3036,13 @@ UiDisplayMenu (
                 //\r
                 // If we have a remainder, skip that many more op-codes until we drain the remainder\r
                 //\r
-                for (;\r
-                     Difference >= (INTN) SavedMenuOption->Skip;\r
-                     Difference = Difference - (INTN) SavedMenuOption->Skip\r
-                    ) {\r
+                while (Difference >= (INTN) SavedMenuOption->Skip) {\r
                   //\r
                   // Since the Difference is greater than or equal to this op-code's skip value, skip it\r
                   //\r
+                  Difference      = Difference - (INTN) SavedMenuOption->Skip;\r
                   TopOfScreen     = TopOfScreen->ForwardLink;\r
                   SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);\r
-                  if (Difference < (INTN) SavedMenuOption->Skip) {\r
-                    Difference = SavedMenuOption->Skip - Difference - 1;\r
-                    break;\r
-                  } else {\r
-                    if (Difference == (INTN) SavedMenuOption->Skip) {\r
-                      TopOfScreen     = TopOfScreen->ForwardLink;\r
-                      SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);\r
-                      Difference      = SavedMenuOption->Skip - Difference;\r
-                      break;\r
-                    }\r
-                  }\r
                 }\r
                 //\r
                 // Since we will act on this op-code in the next routine, and increment the\r
@@ -3072,6 +3075,8 @@ UiDisplayMenu (
               } else {\r
                 SkipValue++;\r
               }\r
+            } else if (SavedMenuOption->Skip == 1) {\r
+              SkipValue   = 0;\r
             } else {\r
               SkipValue   = 0;\r
               TopOfScreen = TopOfScreen->ForwardLink;\r
@@ -3115,6 +3120,7 @@ UiDisplayMenu (
       Status = SubmitForm (Selection->FormSet, Selection->Form);\r
 \r
       if (!EFI_ERROR (Status)) {\r
+        ASSERT(MenuOption != NULL);\r
         UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE);\r
         UpdateStatusBar (NV_UPDATE_REQUIRED, MenuOption->ThisTag->QuestionFlags, FALSE);\r
       } else {\r