Leaked source code of windows server 2003
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.

165 lines
3.7 KiB

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