From 1cac15db4bc74f0b83eee1b30b851b8b22c6cd40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Mon, 1 Apr 2013 19:31:32 +0000 Subject: [PATCH] [FREELDR] Add support for HOME and END keys in menus, and allow going to the end (resp. to the beginning) if we are on the first (resp. on the last) item and we press up (resp. down). Enjoy :) svn path=/trunk/; revision=58635 --- reactos/boot/freeldr/freeldr/ui/directui.c | 43 +++++++++++++++------- reactos/boot/freeldr/freeldr/ui/tuimenu.c | 31 +++++++++++++--- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/reactos/boot/freeldr/freeldr/ui/directui.c b/reactos/boot/freeldr/freeldr/ui/directui.c index 19f9b0825b6..d6fb2a4249a 100644 --- a/reactos/boot/freeldr/freeldr/ui/directui.c +++ b/reactos/boot/freeldr/freeldr/ui/directui.c @@ -397,7 +397,8 @@ NTAPI UiProcessMenuKeyboardEvent(IN PUI_MENU_INFO MenuInfo, IN UiMenuKeyPressFilterCallback KeyPressFilter) { - ULONG KeyEvent = 0, Selected, Count; + ULONG KeyEvent = 0; + ULONG Selected, Count; /* Check for a keypress */ if (MachConsKbHit()) @@ -405,9 +406,7 @@ UiProcessMenuKeyboardEvent(IN PUI_MENU_INFO MenuInfo, /* Check if the timeout is not already complete */ if (MenuInfo->MenuTimeRemaining != -1) { - // - // Cancel it and remove it - // + /* Cancel it and remove it */ MenuInfo->MenuTimeRemaining = -1; UiDrawMenuBox(MenuInfo); } @@ -418,7 +417,10 @@ UiProcessMenuKeyboardEvent(IN PUI_MENU_INFO MenuInfo, /* Is it extended? Then get the extended key */ if (!KeyEvent) KeyEvent = MachConsGetCh(); - /* Call the supplied key filter callback function to see if it is going to handle this keypress. */ + /* + * Call the supplied key filter callback function to see + * if it is going to handle this keypress. + */ if ((KeyPressFilter) && (KeyPressFilter(KeyEvent))) { /* It processed the key character, so redraw and exit */ @@ -427,41 +429,56 @@ UiProcessMenuKeyboardEvent(IN PUI_MENU_INFO MenuInfo, } /* Process the key */ - if ((KeyEvent == KEY_UP) || (KeyEvent == KEY_DOWN)) + if ((KeyEvent == KEY_UP ) || (KeyEvent == KEY_DOWN) || + (KeyEvent == KEY_HOME) || (KeyEvent == KEY_END )) { /* Get the current selected item and count */ Selected = MenuInfo->SelectedMenuItem; Count = MenuInfo->MenuItemCount - 1; - /* Check if this was a key up and there's a selected menu item */ - if ((KeyEvent == KEY_UP) && (Selected)) + /* Check the key and change the selected menu item */ + if ((KeyEvent == KEY_UP) && (Selected > 0)) { - /* Update the menu (Deselect previous item) */ + /* Deselect previous item and go up */ MenuInfo->SelectedMenuItem--; UiDrawMenuItem(MenuInfo, Selected); Selected--; - /* Skip past any separators */ - if ((Selected) && + // Skip past any separators + if ((Selected > 0) && (MenuInfo->MenuItemList[Selected] == NULL)) { MenuInfo->SelectedMenuItem--; } } + else if ( ((KeyEvent == KEY_UP) && (Selected == 0)) || + (KeyEvent == KEY_END) ) + { + /* Go to the end */ + MenuInfo->SelectedMenuItem = Count; + UiDrawMenuItem(MenuInfo, Selected); + } else if ((KeyEvent == KEY_DOWN) && (Selected < Count)) { - /* Update the menu (deselect previous item) */ + /* Deselect previous item and go down */ MenuInfo->SelectedMenuItem++; UiDrawMenuItem(MenuInfo, Selected); Selected++; - /* Skip past any separators */ + // Skip past any separators if ((Selected < Count) && (MenuInfo->MenuItemList[Selected] == NULL)) { MenuInfo->SelectedMenuItem++; } } + else if ( ((KeyEvent == KEY_DOWN) && (Selected == Count)) || + (KeyEvent == KEY_HOME) ) + { + /* Go to the beginning */ + MenuInfo->SelectedMenuItem = 0; + UiDrawMenuItem(MenuInfo, Selected); + } /* Select new item and update video buffer */ UiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem); diff --git a/reactos/boot/freeldr/freeldr/ui/tuimenu.c b/reactos/boot/freeldr/freeldr/ui/tuimenu.c index ad7822e79a2..69ab50bfa59 100644 --- a/reactos/boot/freeldr/freeldr/ui/tuimenu.c +++ b/reactos/boot/freeldr/freeldr/ui/tuimenu.c @@ -495,7 +495,8 @@ TuiProcessMenuKeyboardEvent(PUI_MENU_INFO MenuInfo, // // Process the key // - if ((KeyEvent == KEY_UP) || (KeyEvent == KEY_DOWN)) + if ((KeyEvent == KEY_UP ) || (KeyEvent == KEY_DOWN) || + (KeyEvent == KEY_HOME) || (KeyEvent == KEY_END )) { // // Get the current selected item and count @@ -504,28 +505,37 @@ TuiProcessMenuKeyboardEvent(PUI_MENU_INFO MenuInfo, Count = MenuInfo->MenuItemCount - 1; // - // Check if this was a key up and there's a selected menu item + // Check the key and change the selected menu item // - if ((KeyEvent == KEY_UP) && (Selected)) + if ((KeyEvent == KEY_UP) && (Selected > 0)) { // - // Update the menu (Deselect previous item) + // Deselect previous item and go up // MenuInfo->SelectedMenuItem--; TuiDrawMenuItem(MenuInfo, Selected); Selected--; // Skip past any separators - if ((Selected) && + if ((Selected > 0) && (MenuInfo->MenuItemList[Selected] == NULL)) { MenuInfo->SelectedMenuItem--; } } + else if ( ((KeyEvent == KEY_UP) && (Selected == 0)) || + (KeyEvent == KEY_END) ) + { + // + // Go to the end + // + MenuInfo->SelectedMenuItem = Count; + TuiDrawMenuItem(MenuInfo, Selected); + } else if ((KeyEvent == KEY_DOWN) && (Selected < Count)) { // - // Update the menu (deselect previous item) + // Deselect previous item and go down // MenuInfo->SelectedMenuItem++; TuiDrawMenuItem(MenuInfo, Selected); @@ -538,6 +548,15 @@ TuiProcessMenuKeyboardEvent(PUI_MENU_INFO MenuInfo, MenuInfo->SelectedMenuItem++; } } + else if ( ((KeyEvent == KEY_DOWN) && (Selected == Count)) || + (KeyEvent == KEY_HOME) ) + { + // + // Go to the beginning + // + MenuInfo->SelectedMenuItem = 0; + TuiDrawMenuItem(MenuInfo, Selected); + } // // Select new item and update video buffer