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.

236 lines
5.8 KiB

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