1 /** @file
2     Defines BufferImage - the view of the file that is visible at any point,
3     as well as the event handlers for editing the file
4 
5   Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
6   SPDX-License-Identifier: BSD-2-Clause-Patent
7 
8 **/
9 
10 #ifndef _LIB_BUFFER_IMAGE_H_
11 #define _LIB_BUFFER_IMAGE_H_
12 
13 #include "HexEditor.h"
14 
15 /**
16   Initialization function for HBufferImage
17 
18   @retval EFI_SUCCESS       The operation was successful.
19   @retval EFI_LOAD_ERROR    A load error occurred.
20 **/
21 EFI_STATUS
22 HBufferImageInit (
23   VOID
24   );
25 
26 /**
27   Cleanup function for HBufferImage
28 
29   @retval EFI_SUCCESS  The operation was successful.
30 **/
31 EFI_STATUS
32 HBufferImageCleanup (
33   VOID
34   );
35 
36 /**
37   Refresh function for HBufferImage.
38 
39   @retval EFI_SUCCESS     The operation was successful.
40   @retval EFI_LOAD_ERROR  A Load error occurred.
41 
42 **/
43 EFI_STATUS
44 HBufferImageRefresh (
45   VOID
46   );
47 
48 /**
49   Dispatch input to different handler
50 
51   @param[in] Key    The input key:
52                      the keys can be:
53                        ASCII KEY
54                         Backspace/Delete
55                         Direction key: up/down/left/right/pgup/pgdn
56                         Home/End
57                         INS
58 
59   @retval EFI_SUCCESS           The operation was successful.
60   @retval EFI_LOAD_ERROR        A load error occurred.
61   @retval EFI_OUT_OF_RESOURCES  A Memory allocation failed.
62 **/
63 EFI_STATUS
64 HBufferImageHandleInput (
65   IN  EFI_INPUT_KEY *Key
66   );
67 
68 /**
69   Backup function for HBufferImage. Only a few fields need to be backup.
70   This is for making the file buffer refresh as few as possible.
71 
72   @retval EFI_SUCCESS  The operation was successful.
73 **/
74 EFI_STATUS
75 HBufferImageBackup (
76   VOID
77   );
78 
79 /**
80   Read an image into a buffer friom a source.
81 
82   @param[in] FileName     Pointer to the file name.  OPTIONAL and ignored if not FileTypeFileBuffer.
83   @param[in] DiskName     Pointer to the disk name.  OPTIONAL and ignored if not FileTypeDiskBuffer.
84   @param[in] DiskOffset   Offset into the disk.  OPTIONAL and ignored if not FileTypeDiskBuffer.
85   @param[in] DiskSize     Size of the disk buffer.  OPTIONAL and ignored if not FileTypeDiskBuffer.
86   @param[in] MemOffset    Offset into the Memory.  OPTIONAL and ignored if not FileTypeMemBuffer.
87   @param[in] MemSize      Size of the Memory buffer.  OPTIONAL and ignored if not FileTypeMemBuffer.
88   @param[in] BufferType   The type of buffer to save.  IGNORED.
89   @param[in] Recover      TRUE for recovermode, FALSE otherwise.
90 
91   @return EFI_SUCCESS     The operation was successful.
92 **/
93 EFI_STATUS
94 HBufferImageRead (
95   IN CONST CHAR16                   *FileName,
96   IN CONST CHAR16                   *DiskName,
97   IN UINTN                          DiskOffset,
98   IN UINTN                          DiskSize,
99   IN UINTN                          MemOffset,
100   IN UINTN                          MemSize,
101   IN EDIT_FILE_TYPE                 BufferType,
102   IN BOOLEAN                        Recover
103   );
104 
105 /**
106   Save the current image.
107 
108   @param[in] FileName     Pointer to the file name.  OPTIONAL and ignored if not FileTypeFileBuffer.
109   @param[in] DiskName     Pointer to the disk name.  OPTIONAL and ignored if not FileTypeDiskBuffer.
110   @param[in] DiskOffset   Offset into the disk.  OPTIONAL and ignored if not FileTypeDiskBuffer.
111   @param[in] DiskSize     Size of the disk buffer.  OPTIONAL and ignored if not FileTypeDiskBuffer.
112   @param[in] MemOffset    Offset into the Memory.  OPTIONAL and ignored if not FileTypeMemBuffer.
113   @param[in] MemSize      Size of the Memory buffer.  OPTIONAL and ignored if not FileTypeMemBuffer.
114   @param[in] BufferType   The type of buffer to save.  IGNORED.
115 
116   @return EFI_SUCCESS     The operation was successful.
117 **/
118 EFI_STATUS
119 HBufferImageSave (
120   IN CHAR16                         *FileName,
121   IN CHAR16                         *DiskName,
122   IN UINTN                          DiskOffset,
123   IN UINTN                          DiskSize,
124   IN UINTN                          MemOffset,
125   IN UINTN                          MemSize,
126   IN EDIT_FILE_TYPE                 BufferType
127   );
128 
129 /**
130   According to cursor's file position, adjust screen display.
131 
132   @param[in] NewFilePosRow    Row of file position ( start from 1 ).
133   @param[in] NewFilePosCol    Column of file position ( start from 1 ).
134   @param[in] HighBits         Cursor will on high4 bits or low4 bits.
135 **/
136 VOID
137 HBufferImageMovePosition (
138   IN UINTN    NewFilePosRow,
139   IN UINTN    NewFilePosCol,
140   IN BOOLEAN  HighBits
141   );
142 
143 
144 /**
145   Create a new line and append it to the line list.
146     Fields affected:
147     NumLines
148     Lines
149 
150   @retval NULL    create line failed.
151   @return         the line created.
152 
153 **/
154 HEFI_EDITOR_LINE  *
155 HBufferImageCreateLine (
156   VOID
157   );
158 
159 /**
160   Free the current image.
161 
162   @retval EFI_SUCCESS   The operation was successful.
163 **/
164 EFI_STATUS
165 HBufferImageFree (
166   VOID
167   );
168 
169 /**
170   Delete character from buffer.
171 
172   @param[in] Pos      Position, Pos starting from 0.
173   @param[in] Count    The Count of characters to delete.
174   @param[out] DeleteBuffer    The DeleteBuffer.
175 
176   @retval EFI_SUCCESS Success
177 **/
178 EFI_STATUS
179 HBufferImageDeleteCharacterFromBuffer (
180   IN  UINTN         Pos,
181   IN  UINTN         Count,
182   OUT UINT8         *DeleteBuffer
183   );
184 
185 /**
186   Add character to buffer, add before pos.
187 
188   @param[in] Pos        Position, Pos starting from 0.
189   @param[in] Count      Count of characters to add.
190   @param[in] AddBuffer  Add buffer.
191 
192   @retval EFI_SUCCESS   Success.
193 **/
194 EFI_STATUS
195 HBufferImageAddCharacterToBuffer (
196   IN  UINTN          Pos,
197   IN  UINTN          Count,
198   IN  UINT8          *AddBuffer
199   );
200 
201 /**
202   Change the raw buffer to a list of lines for the UI.
203 
204   @param[in] Buffer   The pointer to the buffer to fill.
205   @param[in] Bytes    The size of the buffer in bytes.
206 
207   @retval EFI_SUCCESS           The operation was successful.
208   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.
209 **/
210 EFI_STATUS
211 HBufferImageBufferToList (
212   IN VOID   *Buffer,
213   IN UINTN  Bytes
214   );
215 
216 /**
217   Change the list of lines from the UI to a raw buffer.
218 
219   @param[in] Buffer   The pointer to the buffer to fill.
220   @param[in] Bytes    The size of the buffer in bytes.
221 
222   @retval EFI_SUCCESS   The operation was successful.
223 **/
224 EFI_STATUS
225 HBufferImageListToBuffer (
226   IN VOID   *Buffer,
227   IN UINTN  Bytes
228   );
229 
230 /**
231   Move the mouse in the image buffer.
232 
233   @param[in] TextX    The x-coordinate.
234   @param[in] TextY    The y-coordinate.
235 **/
236 VOID
237 HBufferImageAdjustMousePosition (
238   IN INT32 TextX,
239   IN INT32 TextY
240   );
241 
242 /**
243   Function to decide if a column number is stored in the high bits.
244 
245   @param[in] Column     The column to examine.
246   @param[out] FCol      The actual column number.
247 
248   @retval TRUE      The actual column was in high bits and is now in FCol.
249   @retval FALSE     There was not a column number in the high bits.
250 **/
251 BOOLEAN
252 HBufferImageIsAtHighBits (
253   IN  UINTN Column,
254   OUT UINTN *FCol
255   );
256 
257 /**
258   Get the size of the open buffer.
259 
260   @retval The size in bytes.
261 **/
262 UINTN
263 HBufferImageGetTotalSize (
264   VOID
265   );
266 
267 #endif
268