Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. libInputBar.c
  5. Abstract:
  6. Definition of the user input bar (multi-plexes with the Status Bar)
  7. --*/
  8. #ifndef _LIB_INPUT_BAR
  9. #define _LIB_INPUT_BAR
  10. #include "editor.h"
  11. STATIC EFI_STATUS MainInputBarInit (VOID);
  12. STATIC EFI_STATUS MainInputBarCleanup (VOID);
  13. STATIC EFI_STATUS MainInputBarRefresh (VOID);
  14. STATIC EFI_STATUS MainInputBarHide (VOID);
  15. STATIC EFI_STATUS MainInputBarSetPrompt (CHAR16*);
  16. STATIC EFI_STATUS MainInputBarSetStringSize (UINTN);
  17. EFI_EDITOR_INPUT_BAR MainInputBar = {
  18. NULL,
  19. NULL,
  20. 0,
  21. MainInputBarInit,
  22. MainInputBarCleanup,
  23. MainInputBarRefresh,
  24. MainInputBarHide,
  25. MainInputBarSetPrompt,
  26. MainInputBarSetStringSize
  27. };
  28. EFI_EDITOR_INPUT_BAR MainInputBarConst = {
  29. NULL,
  30. NULL,
  31. 0,
  32. MainInputBarInit,
  33. MainInputBarCleanup,
  34. MainInputBarRefresh,
  35. MainInputBarHide,
  36. MainInputBarSetPrompt,
  37. MainInputBarSetStringSize
  38. };
  39. STATIC
  40. EFI_STATUS
  41. MainInputBarInit (
  42. VOID
  43. )
  44. {
  45. CopyMem (&MainInputBar, &MainInputBarConst, sizeof(MainInputBar));
  46. return EFI_SUCCESS;
  47. }
  48. STATIC
  49. EFI_STATUS
  50. MainInputBarCleanup (
  51. VOID
  52. )
  53. {
  54. MainInputBar.Hide ();
  55. if (MainInputBar.Prompt != NULL ) {
  56. FreePool ((VOID*)MainInputBar.Prompt);
  57. }
  58. return EFI_SUCCESS;
  59. }
  60. STATIC
  61. EFI_STATUS
  62. MainInputBarRefresh (
  63. VOID
  64. )
  65. {
  66. EFI_EDITOR_COLOR_UNION Orig,New;
  67. EFI_INPUT_KEY Key;
  68. UINTN Column;
  69. UINTN Size = 0;
  70. EFI_STATUS Status = EFI_SUCCESS;
  71. Orig = MainEditor.ColorAttributes;
  72. New.Colors.Foreground = Orig.Colors.Background;
  73. New.Colors.Background = Orig.Colors.Foreground;
  74. Out->SetAttribute (Out,New.Data);
  75. MainInputBar.Hide();
  76. Out->SetCursorPosition(Out,0,INPUT_BAR_LOCATION);
  77. Print(L"%s ",MainInputBar.Prompt);
  78. for ( ;; ) {
  79. WaitForSingleEvent(In->WaitForKey,0);
  80. Status = In->ReadKeyStroke(In,&Key);
  81. if ( EFI_ERROR(Status) ) {
  82. continue;
  83. }
  84. if ( Key.ScanCode == SCAN_CODE_ESC ) {
  85. Size = 0;
  86. FreePool(MainInputBar.ReturnString);
  87. Status = EFI_NOT_READY;
  88. break;
  89. }
  90. if ( Key.UnicodeChar == CHAR_LF || Key.UnicodeChar == CHAR_CR ) {
  91. break;
  92. } else if (Key.UnicodeChar == CHAR_BS) {
  93. if (Size > 0) {
  94. Size--;
  95. Column = Out->Mode->CursorColumn - 1;
  96. PrintAt(Column,INPUT_BAR_LOCATION,L" ");
  97. Out->SetCursorPosition(Out,Column,INPUT_BAR_LOCATION);
  98. }
  99. } else if (Key.UnicodeChar != 0) {
  100. if ( Size < MainInputBar.StringSize) {
  101. MainInputBar.ReturnString[Size] = Key.UnicodeChar;
  102. Size++;
  103. Print(L"%c",Key.UnicodeChar);
  104. }
  105. }
  106. }
  107. MainInputBar.StringSize = Size;
  108. if ( Size > 0 ) {
  109. MainInputBar.ReturnString[Size] = 0;
  110. }
  111. Out->SetAttribute (Out,Orig.Data);
  112. MainEditor.StatusBar->Refresh();
  113. return Status;
  114. }
  115. STATIC
  116. EFI_STATUS
  117. MainInputBarHide (
  118. VOID
  119. )
  120. {
  121. MainEditor.FileBuffer->ClearLine(INPUT_BAR_LOCATION);
  122. return EFI_SUCCESS;
  123. }
  124. STATIC
  125. EFI_STATUS
  126. MainInputBarSetPrompt (
  127. IN CHAR16* Str
  128. )
  129. {
  130. if ( MainInputBar.Prompt != NULL && MainInputBar.Prompt != (CHAR16*)BAD_POINTER) {
  131. FreePool (MainInputBar.Prompt);
  132. }
  133. MainInputBar.Prompt = PoolPrint (L"%s",Str);
  134. return EFI_SUCCESS;
  135. }
  136. STATIC
  137. EFI_STATUS
  138. MainInputBarSetStringSize (
  139. UINTN Size
  140. )
  141. {
  142. /* if ( MainInputBar.ReturnString != NULL && MainInputBar.ReturnString != (CHAR16*)BAD_POINTER) {
  143. * FreePool ( MainInputBar.ReturnString );
  144. * } */
  145. MainInputBar.StringSize = Size;
  146. MainInputBar.ReturnString = AllocatePool (Size+6);
  147. return EFI_SUCCESS;
  148. }
  149. #endif /* _LIB_INPUT_BAR */