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.

243 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. libEditor.c
  5. --*/
  6. #ifndef _LIB_EDITOR
  7. #define _LIB_EDITOR
  8. #include "hexedit.h"
  9. extern EE_FILE_BUFFER FileBuffer;
  10. extern EE_BUFFER_IMAGE BufferImage;
  11. extern EE_TITLE_BAR TitleBar;
  12. extern EE_STATUS_BAR MainStatusBar;
  13. extern EE_INPUT_BAR MainInputBar;
  14. extern EE_MENU_BAR MainMenuBar;
  15. extern EE_CLIPBOARD Clipboard;
  16. STATIC EE_COLOR_ATTRIBUTES OriginalColors;
  17. STATIC INTN OriginalMode;
  18. STATIC EFI_STATUS MainEditorInit (EFI_HANDLE*);
  19. STATIC EFI_STATUS MainEditorCleanup (VOID);
  20. STATIC EFI_STATUS MainEditorKeyInput (VOID);
  21. STATIC EFI_STATUS MainEditorHandleInput (EFI_INPUT_KEY*);
  22. STATIC EFI_STATUS MainEditorRefresh (VOID);
  23. EE_EDITOR MainEditor = {
  24. NULL,
  25. &TitleBar,
  26. &MainMenuBar,
  27. &MainStatusBar,
  28. &MainInputBar,
  29. &FileBuffer,
  30. &Clipboard,
  31. {0,0},
  32. NULL,
  33. &BufferImage,
  34. FALSE,
  35. MainEditorInit,
  36. MainEditorCleanup,
  37. MainEditorKeyInput,
  38. MainEditorHandleInput,
  39. MainEditorRefresh
  40. };
  41. STATIC
  42. EFI_STATUS
  43. MainEditorInit (
  44. IN EFI_HANDLE *ImageHandle
  45. )
  46. {
  47. EFI_STATUS Status;
  48. MainEditor.ImageHandle = ImageHandle;
  49. Status = In->Reset(In,FALSE);
  50. if (EFI_ERROR(Status)) {
  51. Print (L"%ECould not obtain input device!%N\n");
  52. return EFI_LOAD_ERROR;
  53. }
  54. Status = Out->Reset(Out,FALSE);
  55. if (EFI_ERROR(Status)) {
  56. Print (L"%ECould not obtain output device!%N\n");
  57. return EFI_LOAD_ERROR;
  58. }
  59. MainEditor.ColorAttributes.Colors.Foreground = Out->Mode->Attribute & 0x000000ff;
  60. MainEditor.ColorAttributes.Colors.Background = (UINT8)(Out->Mode->Attribute >> 4);
  61. OriginalColors = MainEditor.ColorAttributes.Colors;
  62. OriginalMode = Out->Mode->Mode;
  63. MainEditor.ScreenSize = AllocatePool (sizeof(EE_POSITION));
  64. if (MainEditor.ScreenSize == NULL ) {
  65. Print (L"%ECould Not Allocate Memory for Screen Size\n%N");
  66. return EFI_OUT_OF_RESOURCES;
  67. }
  68. Out->QueryMode(Out,Out->Mode->Mode,&(MainEditor.ScreenSize->Column),&(MainEditor.ScreenSize->Row));
  69. Status = MainEditor.BufferImage->Init ();
  70. if ( EFI_ERROR(Status) ) {
  71. Print (L"%EMainEditor init failed on BufferImage init\n%N");
  72. return EFI_LOAD_ERROR;
  73. }
  74. Status = MainEditor.TitleBar->Init ();
  75. if ( EFI_ERROR(Status) ) {
  76. Print (L"%EMainEditor init failed on TitleBar init\n%N");
  77. return EFI_LOAD_ERROR;
  78. }
  79. Status = MainEditor.StatusBar->Init ();
  80. if ( EFI_ERROR(Status) ) {
  81. Print (L"%EMainEditor init failed on StatusBar init\n%N");
  82. return EFI_LOAD_ERROR;
  83. }
  84. Status = MainEditor.FileBuffer->Init();
  85. if ( EFI_ERROR(Status) ) {
  86. Print (L"%EMainEditor init failed on FileBuffer init\n%N");
  87. return EFI_LOAD_ERROR;
  88. }
  89. Status = MainEditor.MenuBar->Init();
  90. if ( EFI_ERROR(Status)) {
  91. Print (L"%EMainEditor init failed on MainMenu init\n%N");
  92. return EFI_LOAD_ERROR;
  93. }
  94. Status = MainEditor.InputBar->Init ();
  95. if ( EFI_ERROR(Status)) {
  96. Print (L"%EMainEditor init failed on InputBar init\n%N");
  97. return EFI_LOAD_ERROR;
  98. }
  99. Status = MainEditor.Clipboard->Init();
  100. if ( EFI_ERROR(Status)) {
  101. Print (L"%EMainEditor init failed on Clipboard init\n%N");
  102. return EFI_LOAD_ERROR;
  103. }
  104. Out->ClearScreen(Out);
  105. Out->EnableCursor(Out,TRUE);
  106. return EFI_SUCCESS;
  107. }
  108. STATIC
  109. EFI_STATUS
  110. MainEditorCleanup (
  111. VOID
  112. )
  113. {
  114. EFI_STATUS Status;
  115. Status = MainEditor.BufferImage->Cleanup();
  116. if (EFI_ERROR (Status)) {
  117. Print (L"BufferImage cleanup failed\n");
  118. }
  119. Print(L"BufferImage Cleanup OK");
  120. Status = MainEditor.TitleBar->Cleanup();
  121. if (EFI_ERROR (Status)) {
  122. Print (L"TitleBar cleanup failed\n");
  123. }
  124. Print(L"Title Bar Cleanup OK");
  125. Status = MainEditor.MenuBar->Cleanup();
  126. if (EFI_ERROR (Status)) {
  127. Print (L"MenuBar cleanup failed\n");
  128. }
  129. Status = MainEditor.InputBar->Cleanup();
  130. if (EFI_ERROR (Status)) {
  131. Print (L"InputBar cleanup failed\n");
  132. }
  133. Status = MainEditor.FileBuffer->Cleanup();
  134. if (EFI_ERROR (Status)) {
  135. Print (L"FileBuffer cleanup failed\n");
  136. }
  137. Print(L"FileBuffer Cleanup OK");
  138. Status = MainEditor.StatusBar->Cleanup();
  139. if (EFI_ERROR (Status)) {
  140. Print (L"StatusBar cleanup failed\n");
  141. }
  142. if ( OriginalMode != Out->Mode->Mode) {
  143. Out->SetMode(Out,OriginalMode);
  144. }
  145. Out->SetAttribute(Out,EFI_TEXT_ATTR(OriginalColors.Foreground,OriginalColors.Background));
  146. Out->ClearScreen (Out);
  147. return EFI_SUCCESS;
  148. }
  149. STATIC
  150. EFI_STATUS
  151. MainEditorKeyInput (
  152. VOID
  153. )
  154. {
  155. EFI_INPUT_KEY Key;
  156. EFI_STATUS Status;
  157. UINTN i =0;
  158. do {
  159. /* Get Key Input */
  160. WaitForSingleEvent(In->WaitForKey,0);
  161. Status = In->ReadKeyStroke(In,&Key);
  162. if ( EFI_ERROR(Status)) {
  163. continue;
  164. }
  165. if (IS_VALID_CHAR(Key.ScanCode)) {
  166. Status = MainEditor.FileBuffer->HandleInput(&Key);
  167. } else if (IS_DIRECTION_KEY(Key.ScanCode)) {
  168. Status = MainEditor.FileBuffer->HandleInput(&Key);
  169. } else if (IS_FUNCTION_KEY(Key.ScanCode)) {
  170. Status = MainEditor.MenuBar->HandleInput(&Key);
  171. } else {
  172. MainEditor.StatusBar->SetStatusString(L"Unknown Command");
  173. }
  174. }
  175. while (!EFI_ERROR(Status));
  176. return EFI_SUCCESS;
  177. }
  178. STATIC
  179. EFI_STATUS
  180. MainEditorHandleInput (
  181. IN EFI_INPUT_KEY* Key
  182. )
  183. {
  184. return EFI_SUCCESS;
  185. }
  186. STATIC
  187. EFI_STATUS
  188. MainEditorRefresh (
  189. VOID
  190. )
  191. {
  192. MainEditor.TitleBar->Refresh();
  193. MainEditor.MenuBar->Refresh();
  194. MainEditor.FileBuffer->Refresh();
  195. MainEditor.StatusBar->Refresh();
  196. return EFI_SUCCESS;
  197. }
  198. #endif /* _LIB_EDITOR */