- 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;
- BOOLEAN ReturnCode;
- PVOID ScreenBuffer;
-
- // Save the screen contents
- ScreenBuffer = MmHeapAlloc(UiScreenWidth * UiScreenHeight * 2);
- TuiSaveScreen(ScreenBuffer);
-
- // Find the height
- for (i=0; i<strlen(MessageText); i++)
- {
- if (MessageText[i] == '\n')
- height++;
- }
-
- // Find the width
- for (i=0,j=0,k=0; i<height; i++)
- {
- while ((MessageText[j] != '\n') && (MessageText[j] != 0))
- {
- j++;
- k++;
- }
-
- if (k > width)
- width = k;
-
- k = 0;
- j++;
- }
-
- // Calculate box area
- x1 = (UiScreenWidth - (width+2))/2;
- x2 = x1 + width + 3;
- y1 = ((UiScreenHeight - height - 2)/2) + 1;
- y2 = y1 + height + 4;
-
- // Draw the box
- TuiDrawBox(x1, y1, x2, y2, D_VERT, D_HORZ, TRUE, TRUE, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor));
-
- // Draw the text
- for (i=0,j=0; i<strlen(MessageText)+1; i++)
- {
- if ((MessageText[i] == '\n') || (MessageText[i] == 0))
- {
- temp[j] = 0;
- j = 0;
- UiDrawText(x1+2, y1+1+curline, temp, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor));
- curline++;
- }
- else
- temp[j++] = MessageText[i];
- }
-
- EditBoxTextCount = 0;
- EditBoxLine = y2 - 2;
- EditBoxStartX = x1 + 3;
- EditBoxEndX = x2 - 3;
- UiFillArea(EditBoxStartX, EditBoxLine, EditBoxEndX, EditBoxLine, ' ', ATTR(UiEditBoxTextColor, UiEditBoxBgColor));
-
- // Show the cursor
- EditBoxCursorX = EditBoxStartX;
- MachVideoSetTextCursorPosition(EditBoxCursorX, EditBoxLine);
- MachVideoHideShowTextCursor(TRUE);
-
- // Draw status text
- UiDrawStatusText("Press ENTER to continue, or ESC to cancel");
-
- VideoCopyOffScreenBufferToVRAM();
-
- for (;;)
- {
- if (MachConsKbHit())
- {
- key = MachConsGetCh();
- if(key == KEY_EXTENDED)
- {
- key = MachConsGetCh();
- }
-
- if(key == KEY_ENTER)
- {
- ReturnCode = TRUE;
- break;
- }
- else if(key == KEY_ESC)
- {
- ReturnCode = FALSE;
- break;
- }
- else if (key == KEY_BACKSPACE) // Remove a character
- {
- if (EditBoxTextCount)
- {
- EditBoxTextCount--;
- EditTextBuffer[EditBoxTextCount] = 0;
- }
- else
- {
- MachBeep();
- }
- }
- else // Add this key to the buffer
- {
- if (EditBoxTextCount < Length - 1)
- {
- EditTextBuffer[EditBoxTextCount] = key;
- EditBoxTextCount++;
- EditTextBuffer[EditBoxTextCount] = 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);
- EditBoxCursorX = EditBoxEndX;
- }
- else
- {
- EditBoxTextDisplayIndex = 0;
- EditBoxCursorX = EditBoxStartX + EditBoxTextCount;
- }
- UiDrawText(EditBoxStartX, EditBoxLine, &EditTextBuffer[EditBoxTextDisplayIndex], ATTR(UiEditBoxTextColor, UiEditBoxBgColor));
-
- // Move the cursor
- MachVideoSetTextCursorPosition(EditBoxCursorX, EditBoxLine);
-
- TuiUpdateDateTime();
-
- VideoCopyOffScreenBufferToVRAM();
-
- MachHwIdle();
- }
-
- // Hide the cursor again
- MachVideoHideShowTextCursor(FALSE);
-
- // Restore the screen contents
- TuiRestoreScreen(ScreenBuffer);
- MmHeapFree(ScreenBuffer);
-
- return ReturnCode;
+ 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;
+
+ // Save the screen contents
+ ScreenBuffer = FrLdrTempAlloc(UiScreenWidth * UiScreenHeight * 2,
+ TAG_TUI_SCREENBUFFER);
+ TuiSaveScreen(ScreenBuffer);
+
+ // Find the height
+ for (i=0; i<strlen(MessageText); i++)
+ {
+ if (MessageText[i] == '\n')
+ height++;
+ }
+
+ // Find the width
+ for (i=0,j=0,k=0; i<height; i++)
+ {
+ while ((MessageText[j] != '\n') && (MessageText[j] != 0))
+ {
+ j++;
+ k++;
+ }
+
+ if (k > width)
+ width = k;
+
+ k = 0;
+ j++;
+ }
+
+ // Calculate box area
+ x1 = (UiScreenWidth - (width+2))/2;
+ x2 = x1 + width + 3;
+ y1 = ((UiScreenHeight - height - 2)/2) + 1;
+ y2 = y1 + height + 4;
+
+ // Draw the box
+ TuiDrawBox(x1, y1, x2, y2, D_VERT, D_HORZ, TRUE, TRUE, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor));
+
+ // Draw the text
+ for (i=0,j=0; i<strlen(MessageText)+1; i++)
+ {
+ if ((MessageText[i] == '\n') || (MessageText[i] == 0))
+ {
+ temp[j] = 0;
+ j = 0;
+ UiDrawText(x1+2, y1+1+curline, temp, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor));
+ curline++;
+ }
+ else
+ temp[j++] = MessageText[i];
+ }
+
+ EditBoxTextLength = (ULONG)strlen(EditTextBuffer);
+ EditBoxTextLength = min(EditBoxTextLength, Length - 1);
+ EditBoxTextPosition = 0;
+ EditBoxLine = y2 - 2;
+ EditBoxStartX = x1 + 3;
+ EditBoxEndX = x2 - 3;
+
+ // Draw the edit box background and the text
+ UiFillArea(EditBoxStartX, EditBoxLine, EditBoxEndX, EditBoxLine, ' ', ATTR(UiEditBoxTextColor, UiEditBoxBgColor));
+ UiDrawText2(EditBoxStartX, EditBoxLine, EditBoxEndX - EditBoxStartX + 1, EditTextBuffer, ATTR(UiEditBoxTextColor, UiEditBoxBgColor));
+
+ // Show the cursor
+ EditBoxCursorX = EditBoxStartX;
+ MachVideoSetTextCursorPosition(EditBoxCursorX, EditBoxLine);
+ MachVideoHideShowTextCursor(TRUE);
+
+ // Draw status text
+ UiDrawStatusText("Press ENTER to continue, or ESC to cancel");
+
+ 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();
+ }
+
+ if (key == KEY_ENTER)
+ {
+ ReturnCode = TRUE;
+ break;
+ }
+ else if (key == KEY_ESC)
+ {
+ ReturnCode = FALSE;
+ break;
+ }
+ else if (key == KEY_BACKSPACE) // Remove a character
+ {
+ if ( (EditBoxTextLength > 0) && (EditBoxTextPosition > 0) &&
+ (EditBoxTextPosition <= EditBoxTextLength) )
+ {
+ EditBoxTextPosition--;
+ memmove(EditTextBuffer + EditBoxTextPosition,
+ EditTextBuffer + EditBoxTextPosition + 1,
+ EditBoxTextLength - EditBoxTextPosition);
+ EditBoxTextLength--;
+ EditTextBuffer[EditBoxTextLength] = 0;
+ }
+ else
+ {
+ MachBeep();
+ }
+ }
+ else if (Extended && key == KEY_DELETE) // Remove a character
+ {
+ if ( (EditBoxTextLength > 0) &&
+ (EditBoxTextPosition < EditBoxTextLength) )
+ {
+ memmove(EditTextBuffer + EditBoxTextPosition,
+ EditTextBuffer + EditBoxTextPosition + 1,
+ EditBoxTextLength - EditBoxTextPosition);
+ EditBoxTextLength--;
+ EditTextBuffer[EditBoxTextLength] = 0;
+ }
+ else
+ {
+ MachBeep();
+ }
+ }
+ else if (Extended && key == KEY_HOME) // Go to the start of the buffer
+ {
+ EditBoxTextPosition = 0;
+ }
+ else if (Extended && key == KEY_END) // Go to the end of the buffer
+ {
+ EditBoxTextPosition = EditBoxTextLength;
+ }
+ else if (Extended && key == KEY_RIGHT) // Go right
+ {
+ if (EditBoxTextPosition < EditBoxTextLength)
+ EditBoxTextPosition++;
+ else
+ MachBeep();
+ }
+ else if (Extended && key == KEY_LEFT) // Go left
+ {
+ if (EditBoxTextPosition > 0)
+ EditBoxTextPosition--;
+ else
+ MachBeep();
+ }
+ else if (!Extended) // 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();
+ }
+ }
+ else
+ {
+ MachBeep();
+ }
+ }
+
+ // Draw the edit box background
+ UiFillArea(EditBoxStartX, EditBoxLine, EditBoxEndX, EditBoxLine, ' ', ATTR(UiEditBoxTextColor, UiEditBoxBgColor));
+
+ // Fill the text in
+ if (EditBoxTextPosition > (EditBoxEndX - EditBoxStartX))
+ {
+ EditBoxTextDisplayIndex = EditBoxTextPosition - (EditBoxEndX - EditBoxStartX);
+ EditBoxCursorX = EditBoxEndX;
+ }
+ else
+ {
+ EditBoxTextDisplayIndex = 0;
+ EditBoxCursorX = EditBoxStartX + EditBoxTextPosition;
+ }
+ UiDrawText2(EditBoxStartX, EditBoxLine, EditBoxEndX - EditBoxStartX + 1, &EditTextBuffer[EditBoxTextDisplayIndex], ATTR(UiEditBoxTextColor, UiEditBoxBgColor));
+
+ // Move the cursor
+ MachVideoSetTextCursorPosition(EditBoxCursorX, EditBoxLine);
+
+ TuiUpdateDateTime();
+
+ VideoCopyOffScreenBufferToVRAM();
+
+ MachHwIdle();
+ }
+
+ // Hide the cursor again
+ MachVideoHideShowTextCursor(FALSE);
+
+ // Restore the screen contents
+ TuiRestoreScreen(ScreenBuffer);
+ FrLdrTempFree(ScreenBuffer, TAG_TUI_SCREENBUFFER);
+
+ return ReturnCode;