Author: hbelusca Date: Tue Apr 2 22:49:03 2013 New Revision: 58658
URL: http://svn.reactos.org/svn/reactos?rev=58658&view=rev Log: [FREELDR] - Further improve FreeLdr's edit-boxes editing capabilities, by supporting insert-mode (only at the moment), backspace and delete to remove a character, moving left or right, going to the beginning or to the end of the string. - Add a helper function DrawText2 to allow for displaying partial string (giving a maximum number of characters to display).
Enjoy :)
Modified: trunk/reactos/boot/freeldr/freeldr/include/keycodes.h trunk/reactos/boot/freeldr/freeldr/include/ui.h trunk/reactos/boot/freeldr/freeldr/include/ui/gui.h trunk/reactos/boot/freeldr/freeldr/include/ui/noui.h trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h trunk/reactos/boot/freeldr/freeldr/ui/directui.c trunk/reactos/boot/freeldr/freeldr/ui/gui.c trunk/reactos/boot/freeldr/freeldr/ui/minitui.c trunk/reactos/boot/freeldr/freeldr/ui/noui.c trunk/reactos/boot/freeldr/freeldr/ui/tui.c trunk/reactos/boot/freeldr/freeldr/ui/ui.c
Modified: trunk/reactos/boot/freeldr/freeldr/include/keycodes.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/keycodes.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/keycodes.h [iso-8859-1] Tue Apr 2 22:49:03 2013 @@ -20,28 +20,31 @@ #pragma once
// Key codes -#define KEY_EXTENDED 0x00 -#define KEY_ENTER 0x0D -#define KEY_BACKSPACE 0x08 -#define KEY_SPACE 0x20 +#define KEY_EXTENDED 0x00 +#define KEY_ENTER 0x0D +#define KEY_BACKSPACE 0x08 +#define KEY_DELETE 0x53 +#define KEY_SPACE 0x20 #define KEY_LEFTSHIFT 0x2A #define KEY_HOME 0x47 -#define KEY_UP 0x48 -#define KEY_DOWN 0x50 -#define KEY_LEFT 0x4B -#define KEY_RIGHT 0x4D -#define KEY_ESC 0x1B -#define KEY_CAPS_LOCK 0x3A -#define KEY_F1 0x3B -#define KEY_F2 0x3C -#define KEY_F3 0x3D -#define KEY_F4 0x3E -#define KEY_F5 0x3F -#define KEY_F6 0x40 -#define KEY_F7 0x41 -#define KEY_F8 0x42 -#define KEY_F9 0x43 +#define KEY_UP 0x48 +#define KEY_DOWN 0x50 +#define KEY_LEFT 0x4B +#define KEY_RIGHT 0x4D +#define KEY_ESC 0x1B +#define KEY_CAPS_LOCK 0x3A +#define KEY_F1 0x3B +#define KEY_F2 0x3C +#define KEY_F3 0x3D +#define KEY_F4 0x3E +#define KEY_F5 0x3F +#define KEY_F6 0x40 +#define KEY_F7 0x41 +#define KEY_F8 0x42 +#define KEY_F9 0x43 #define KEY_F10 0x44 -#define KEY_KEYPAD_PLUS 0x4e -#define KEY_END 0x4f +#define KEY_F11 0x57 +#define KEY_F12 0x58 +#define KEY_KEYPAD_PLUS 0x4E +#define KEY_END 0x4F #define KEY_SEND 0xE7
Modified: trunk/reactos/boot/freeldr/freeldr/include/ui.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/ui.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/ui.h [iso-8859-1] Tue Apr 2 22:49:03 2013 @@ -61,6 +61,7 @@ VOID UiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); // Draws a shadow on the bottom and right sides of the area specified VOID UiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr); // Draws a box around the area specified VOID UiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr); // Draws text at coordinates specified +VOID UiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr); // Draws text at coordinates specified VOID UiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr); // Draws centered text at the coordinates specified and clips the edges VOID UiDrawStatusText(PCSTR StatusText); // Draws text at the very bottom line on the screen VOID UiUpdateDateTime(VOID); // Updates the date and time @@ -123,6 +124,7 @@ VOID (*DrawShadow)(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); VOID (*DrawBox)(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr); VOID (*DrawText)(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr); + VOID (*DrawText2)(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr); VOID (*DrawCenteredText)(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr); VOID (*DrawStatusText)(PCSTR StatusText); VOID (*UpdateDateTime)(VOID);
Modified: trunk/reactos/boot/freeldr/freeldr/include/ui/gui.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/ui/gui.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/ui/gui.h [iso-8859-1] Tue Apr 2 22:49:03 2013 @@ -32,6 +32,7 @@ VOID GuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); // Draws a shadow on the bottom and right sides of the area specified VOID GuiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr); // Draws a box around the area specified VOID GuiDrawText(ULONG X, ULONG Y, PUCHAR Text, UCHAR Attr); // Draws text at coordinates specified +VOID GuiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PUCHAR Text, UCHAR Attr); // Draws text at coordinates specified VOID GuiDrawStatusText(PCSTR StatusText); // Draws text at the very bottom line on the screen VOID GuiUpdateDateTime(VOID); // Updates the date and time VOID GuiSaveScreen(PUCHAR Buffer); // Saves the screen so that it can be restored later
Modified: trunk/reactos/boot/freeldr/freeldr/include/ui/noui.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/ui/noui.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/ui/noui.h [iso-8859-1] Tue Apr 2 22:49:03 2013 @@ -22,6 +22,7 @@ VOID NoUiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); VOID NoUiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr); VOID NoUiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr); +VOID NoUiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr); VOID NoUiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr); VOID NoUiDrawStatusText(PCSTR StatusText); VOID NoUiUpdateDateTime(VOID);
Modified: trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h [iso-8859-1] Tue Apr 2 22:49:03 2013 @@ -35,6 +35,7 @@ VOID TuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); // Draws a shadow on the bottom and right sides of the area specified VOID TuiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr); // Draws a box around the area specified VOID TuiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr); // Draws text at coordinates specified +VOID TuiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr); // Draws text at coordinates specified VOID TuiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr); // Draws centered text at the coordinates specified and clips the edges VOID TuiDrawStatusText(PCSTR StatusText); // Draws text at the very bottom line on the screen VOID TuiUpdateDateTime(VOID); // Updates the date and time
Modified: trunk/reactos/boot/freeldr/freeldr/ui/directui.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/ui/dir... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/ui/directui.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/ui/directui.c [iso-8859-1] Tue Apr 2 22:49:03 2013 @@ -84,11 +84,28 @@ { ULONG i, j;
- /* Draw the text character by character, but don't exceed the width */ + /* Draw the text character by character, but don't exceed the width */ for (i = X, j = 0; Text[j] && i < UiScreenWidth; i++, j++) { - /* Write the character */ - MachVideoPutChar(Text[j], Attr, i, Y); + /* Write the character */ + MachVideoPutChar(Text[j], Attr, i, Y); + } +} + +VOID +UiDrawText2(IN ULONG X, + IN ULONG Y, + IN ULONG MaxNumChars, + IN PCSTR Text, + IN UCHAR Attr) +{ + ULONG i, j; + + /* Draw the text character by character, but don't exceed the width */ + for (i = X, j = 0; Text[j] && i < UiScreenWidth && (MaxNumChars > 0 ? j < MaxNumChars : TRUE); i++, j++) + { + /* Write the character */ + MachVideoPutChar(Text[j], Attr, i, Y); } }
Modified: trunk/reactos/boot/freeldr/freeldr/ui/gui.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/ui/gui... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/ui/gui.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/ui/gui.c [iso-8859-1] Tue Apr 2 22:49:03 2013 @@ -37,6 +37,10 @@ }
VOID GuiDrawText(ULONG X, ULONG Y, PUCHAR Text, UCHAR Attr) +{ +} + +VOID GuiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PUCHAR Text, UCHAR Attr) { }
@@ -80,13 +84,15 @@
const UIVTBL GuiVtbl = { - /*GuiInitialize, + /* + GuiInitialize, GuiUnInitialize, GuiDrawBackdrop, GuiFillArea, GuiDrawShadow, GuiDrawBox, GuiDrawText, + GuiDrawText2, GuiDrawCenteredText, GuiDrawStatusText, GuiUpdateDateTime, @@ -99,9 +105,12 @@ GuiTextToFillStyle, GuiFadeInBackdrop, GuiFadeOut, - GuiDisplayMenu,*/ + GuiDisplayMenu, + GuiDrawMenu, + */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL }; #endif
Modified: trunk/reactos/boot/freeldr/freeldr/ui/minitui.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/ui/min... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/ui/minitui.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/ui/minitui.c [iso-8859-1] Tue Apr 2 22:49:03 2013 @@ -143,6 +143,7 @@ TuiDrawShadow, TuiDrawBox, TuiDrawText, + TuiDrawText2, TuiDrawCenteredText, MiniTuiDrawStatusText, TuiUpdateDateTime,
Modified: trunk/reactos/boot/freeldr/freeldr/ui/noui.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/ui/nou... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/ui/noui.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/ui/noui.c [iso-8859-1] Tue Apr 2 22:49:03 2013 @@ -34,6 +34,10 @@ }
VOID NoUiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr) +{ +} + +VOID NoUiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr) { }
Modified: trunk/reactos/boot/freeldr/freeldr/ui/tui.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/ui/tui... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/ui/tui.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/ui/tui.c [iso-8859-1] Tue Apr 2 22:49:03 2013 @@ -318,7 +318,26 @@ ULONG i, j;
// Draw the text - for (i=X, j=0; Text[j] && i<UiScreenWidth; i++,j++) + for (i = X, j = 0; Text[j] && i < UiScreenWidth; i++, j++) + { + ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)] = (UCHAR)Text[j]; + ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)+1] = Attr; + } +} + +/* + * DrawText2() + * This function assumes coordinates are zero-based. + * MaxNumChars is the maximum number of characters to display. + * If MaxNumChars == 0, then display the whole string. + */ +VOID TuiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr) +{ + PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer; + ULONG i, j; + + // Draw the text + for (i = X, j = 0; Text[j] && i < UiScreenWidth && (MaxNumChars > 0 ? j < MaxNumChars : TRUE); i++, j++) { ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)] = (UCHAR)Text[j]; ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)+1] = Attr; @@ -789,19 +808,20 @@
BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length) { - int width = 8; - unsigned int height = 1; - int curline = 0; - int k; - size_t i , j; - int x1, x2, y1, y2; - char temp[260]; - char key; - int EditBoxLine; - ULONG EditBoxStartX, EditBoxEndX; - int EditBoxCursorX; - unsigned int EditBoxTextCount; - int EditBoxTextDisplayIndex; + INT width = 8; + ULONG height = 1; + INT curline = 0; + INT k; + size_t i , j; + INT x1, x2, y1, y2; + CHAR temp[260]; + CHAR key; + BOOLEAN Extended; + INT EditBoxLine; + ULONG EditBoxStartX, EditBoxEndX; + INT EditBoxCursorX; + ULONG EditBoxTextLength, EditBoxTextPosition; + INT EditBoxTextDisplayIndex; BOOLEAN ReturnCode; PVOID ScreenBuffer;
@@ -855,7 +875,8 @@ temp[j++] = MessageText[i]; }
- EditBoxTextCount = 0; + EditBoxTextLength = 0; + EditBoxTextPosition = 0; EditBoxLine = y2 - 2; EditBoxStartX = x1 + 3; EditBoxEndX = x2 - 3; @@ -871,13 +892,20 @@
VideoCopyOffScreenBufferToVRAM();
+ // + // Enter the text. Please keep in mind that the default input mode + // of the edit boxes is in insertion mode, that is, you can insert + // text without erasing the existing one. + // for (;;) { if (MachConsKbHit()) { + Extended = FALSE; key = MachConsGetCh(); if(key == KEY_EXTENDED) { + Extended = TRUE; key = MachConsGetCh(); }
@@ -893,46 +921,94 @@ } else if (key == KEY_BACKSPACE) // Remove a character { - if (EditBoxTextCount) + if ( (EditBoxTextLength > 0) && (EditBoxTextPosition > 0) && + (EditBoxTextPosition <= EditBoxTextLength) ) { - EditBoxTextCount--; - EditTextBuffer[EditBoxTextCount] = 0; + EditBoxTextPosition--; + memmove(EditTextBuffer + EditBoxTextPosition, + EditTextBuffer + EditBoxTextPosition + 1, + EditBoxTextLength - EditBoxTextPosition); + EditBoxTextLength--; + EditTextBuffer[EditBoxTextLength] = 0; } else { MachBeep(); } } - else // Add this key to the buffer - { - if (EditBoxTextCount < Length - 1) + else if (Extended && key == KEY_DELETE) // Remove a character + { + if ( (EditBoxTextLength > 0) && + (EditBoxTextPosition < EditBoxTextLength) ) { - EditTextBuffer[EditBoxTextCount] = key; - EditBoxTextCount++; - EditTextBuffer[EditBoxTextCount] = 0; + memmove(EditTextBuffer + EditBoxTextPosition, + EditTextBuffer + EditBoxTextPosition + 1, + EditBoxTextLength - EditBoxTextPosition); + EditBoxTextLength--; + EditTextBuffer[EditBoxTextLength] = 0; } else { MachBeep(); } } + else if (key == KEY_HOME) // Go to the start of the buffer + { + EditBoxTextPosition = 0; + } + else if (key == KEY_END) // Go to the end of the buffer + { + EditBoxTextPosition = EditBoxTextLength; + } + else if (key == KEY_RIGHT) // Go right + { + if (EditBoxTextPosition < EditBoxTextLength) + EditBoxTextPosition++; + else + MachBeep(); + } + else if (key == KEY_LEFT) // Go left + { + if (EditBoxTextPosition > 0) + EditBoxTextPosition--; + else + MachBeep(); + } + else // Add this key to the buffer + { + if ( (EditBoxTextLength < Length - 1) && + (EditBoxTextPosition < Length - 1) ) + { + memmove(EditTextBuffer + EditBoxTextPosition + 1, + EditTextBuffer + EditBoxTextPosition, + EditBoxTextLength - EditBoxTextPosition); + EditTextBuffer[EditBoxTextPosition] = key; + EditBoxTextPosition++; + EditBoxTextLength++; + EditTextBuffer[EditBoxTextLength] = 0; + } + else + { + MachBeep(); + } + } }
// Draw the edit box background UiFillArea(EditBoxStartX, EditBoxLine, EditBoxEndX, EditBoxLine, ' ', ATTR(UiEditBoxTextColor, UiEditBoxBgColor));
// Fill the text in - if (EditBoxTextCount > (EditBoxEndX - EditBoxStartX)) - { - EditBoxTextDisplayIndex = EditBoxTextCount - (EditBoxEndX - EditBoxStartX); + if (EditBoxTextPosition > (EditBoxEndX - EditBoxStartX)) + { + EditBoxTextDisplayIndex = EditBoxTextPosition - (EditBoxEndX - EditBoxStartX); EditBoxCursorX = EditBoxEndX; } else { EditBoxTextDisplayIndex = 0; - EditBoxCursorX = EditBoxStartX + EditBoxTextCount; - } - UiDrawText(EditBoxStartX, EditBoxLine, &EditTextBuffer[EditBoxTextDisplayIndex], ATTR(UiEditBoxTextColor, UiEditBoxBgColor)); + EditBoxCursorX = EditBoxStartX + EditBoxTextPosition; + } + UiDrawText2(EditBoxStartX, EditBoxLine, EditBoxEndX - EditBoxStartX + 1, &EditTextBuffer[EditBoxTextDisplayIndex], ATTR(UiEditBoxTextColor, UiEditBoxBgColor));
// Move the cursor MachVideoSetTextCursorPosition(EditBoxCursorX, EditBoxLine); @@ -963,6 +1039,7 @@ TuiDrawShadow, TuiDrawBox, TuiDrawText, + TuiDrawText2, TuiDrawCenteredText, TuiDrawStatusText, TuiUpdateDateTime,
Modified: trunk/reactos/boot/freeldr/freeldr/ui/ui.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/ui/ui.... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/ui/ui.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/ui/ui.c [iso-8859-1] Tue Apr 2 22:49:03 2013 @@ -62,6 +62,7 @@ NoUiDrawShadow, NoUiDrawBox, NoUiDrawText, + NoUiDrawText2, NoUiDrawCenteredText, NoUiDrawStatusText, NoUiUpdateDateTime, @@ -260,6 +261,11 @@ UiVtbl.DrawText(X, Y, Text, Attr); }
+VOID UiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr) +{ + UiVtbl.DrawText2(X, Y, MaxNumChars, Text, Attr); +} + VOID UiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr) { UiVtbl.DrawCenteredText(Left, Top, Right, Bottom, TextString, Attr);