]>
Commit | Line | Data |
---|---|---|
632820d1 | 1 | /** @file\r |
2 | Implementation of various string and line routines\r | |
ba0014b9 LG |
3 | \r |
4 | Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>\r | |
56ba3746 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
632820d1 | 6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include "HexEditor.h"\r | |
10 | \r | |
11 | extern BOOLEAN HEditorMouseAction;\r | |
12 | \r | |
a1d4bfcc | 13 | /**\r |
14 | Free a line and it's internal buffer.\r | |
ba0014b9 | 15 | \r |
a1d4bfcc | 16 | @param[in] Src The line to be freed.\r |
17 | **/\r | |
632820d1 | 18 | VOID\r |
19 | HLineFree (\r | |
20 | IN HEFI_EDITOR_LINE *Src\r | |
21 | )\r | |
632820d1 | 22 | {\r |
23 | if (Src == NULL) {\r | |
24 | return ;\r | |
25 | }\r | |
26 | \r | |
27 | SHELL_FREE_NON_NULL (Src);\r | |
28 | \r | |
29 | }\r | |
30 | \r | |
a1d4bfcc | 31 | /**\r |
32 | Advance to the next Count lines.\r | |
33 | \r | |
34 | @param[in] Count The line number to advance.\r | |
35 | \r | |
a048af3c | 36 | @retval NULL An error occurred.\r |
a1d4bfcc | 37 | @return A pointer to the line after advance.\r |
38 | **/\r | |
632820d1 | 39 | HEFI_EDITOR_LINE *\r |
a1d4bfcc | 40 | HLineAdvance (\r |
632820d1 | 41 | IN UINTN Count\r |
42 | )\r | |
632820d1 | 43 | {\r |
44 | UINTN Index;\r | |
45 | HEFI_EDITOR_LINE *Line;\r | |
46 | \r | |
47 | Line = HMainEditor.BufferImage->CurrentLine;\r | |
48 | if (Line == NULL) {\r | |
49 | return NULL;\r | |
50 | }\r | |
51 | \r | |
52 | for (Index = 0; Index < Count; Index++) {\r | |
53 | //\r | |
54 | // if already last line\r | |
55 | //\r | |
56 | if (Line->Link.ForwardLink == HMainEditor.BufferImage->ListHead) {\r | |
57 | return NULL;\r | |
58 | }\r | |
59 | \r | |
60 | Line = CR (Line->Link.ForwardLink, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);\r | |
61 | }\r | |
62 | \r | |
63 | return Line;\r | |
64 | }\r | |
65 | \r | |
a1d4bfcc | 66 | /**\r |
67 | Retreat to the previous Count lines.\r | |
68 | \r | |
69 | @param[in] Count The line number to retreat.\r | |
70 | \r | |
a048af3c | 71 | @retval NULL An error occurred.\r |
a1d4bfcc | 72 | @return A pointer to the line after retreat.\r |
73 | **/\r | |
632820d1 | 74 | HEFI_EDITOR_LINE *\r |
a1d4bfcc | 75 | HLineRetreat (\r |
632820d1 | 76 | IN UINTN Count\r |
77 | )\r | |
632820d1 | 78 | {\r |
79 | UINTN Index;\r | |
80 | HEFI_EDITOR_LINE *Line;\r | |
81 | \r | |
82 | Line = HMainEditor.BufferImage->CurrentLine;\r | |
83 | if (Line == NULL) {\r | |
84 | return NULL;\r | |
85 | }\r | |
86 | \r | |
87 | for (Index = 0; Index < Count; Index++) {\r | |
88 | //\r | |
89 | // already the first line\r | |
90 | //\r | |
91 | if (Line->Link.BackLink == HMainEditor.BufferImage->ListHead) {\r | |
92 | return NULL;\r | |
93 | }\r | |
94 | \r | |
95 | Line = CR (Line->Link.BackLink, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);\r | |
96 | }\r | |
97 | \r | |
98 | return Line;\r | |
99 | }\r | |
100 | \r | |
a1d4bfcc | 101 | /**\r |
102 | Advance/Retreat lines.\r | |
103 | \r | |
104 | @param[in] Count The line number to advance/retreat.\r | |
105 | >0 : advance\r | |
ba0014b9 | 106 | <0: retreat\r |
a1d4bfcc | 107 | \r |
a048af3c | 108 | @retval NULL An error occurred.\r |
a1d4bfcc | 109 | @return A pointer to the line after move.\r |
110 | **/\r | |
632820d1 | 111 | HEFI_EDITOR_LINE *\r |
112 | HMoveLine (\r | |
113 | IN INTN Count\r | |
114 | )\r | |
632820d1 | 115 | {\r |
116 | HEFI_EDITOR_LINE *Line;\r | |
117 | UINTN AbsCount;\r | |
118 | \r | |
119 | //\r | |
120 | // difference with MoveCurrentLine\r | |
121 | // just return Line\r | |
122 | // do not set currentline to Line\r | |
123 | //\r | |
124 | if (Count <= 0) {\r | |
33c031ee | 125 | AbsCount = (UINTN)ABS(Count);\r |
a1d4bfcc | 126 | Line = HLineRetreat (AbsCount);\r |
632820d1 | 127 | } else {\r |
a1d4bfcc | 128 | Line = HLineAdvance ((UINTN)Count);\r |
632820d1 | 129 | }\r |
130 | \r | |
131 | return Line;\r | |
132 | }\r | |
133 | \r | |
a1d4bfcc | 134 | /**\r |
135 | Advance/Retreat lines and set CurrentLine in BufferImage to it.\r | |
136 | \r | |
137 | @param[in] Count The line number to advance/retreat.\r | |
138 | >0 : advance\r | |
139 | <0: retreat\r | |
140 | \r | |
a048af3c | 141 | @retval NULL An error occurred.\r |
a1d4bfcc | 142 | @return A pointer to the line after move.\r |
143 | **/\r | |
632820d1 | 144 | HEFI_EDITOR_LINE *\r |
145 | HMoveCurrentLine (\r | |
146 | IN INTN Count\r | |
147 | )\r | |
632820d1 | 148 | {\r |
149 | HEFI_EDITOR_LINE *Line;\r | |
150 | UINTN AbsCount;\r | |
151 | \r | |
152 | //\r | |
153 | // <0: retreat\r | |
154 | // >0: advance\r | |
155 | //\r | |
156 | if (Count <= 0) {\r | |
33c031ee | 157 | AbsCount = (UINTN)ABS(Count);\r |
a1d4bfcc | 158 | Line = HLineRetreat (AbsCount);\r |
632820d1 | 159 | } else {\r |
a1d4bfcc | 160 | Line = HLineAdvance ((UINTN)Count);\r |
632820d1 | 161 | }\r |
162 | \r | |
163 | if (Line == NULL) {\r | |
164 | return NULL;\r | |
165 | }\r | |
166 | \r | |
167 | HMainEditor.BufferImage->CurrentLine = Line;\r | |
168 | \r | |
169 | return Line;\r | |
170 | }\r | |
171 | \r | |
172 | \r | |
a1d4bfcc | 173 | /**\r |
174 | Free all the lines in HBufferImage.\r | |
632820d1 | 175 | Fields affected:\r |
176 | Lines\r | |
177 | CurrentLine\r | |
178 | NumLines\r | |
ba0014b9 | 179 | ListHead\r |
632820d1 | 180 | \r |
a1d4bfcc | 181 | @param[in] ListHead The list head.\r |
182 | @param[in] Lines The lines.\r | |
632820d1 | 183 | \r |
a1d4bfcc | 184 | @retval EFI_SUCCESS The operation was successful.\r |
185 | **/\r | |
186 | EFI_STATUS\r | |
187 | HFreeLines (\r | |
188 | IN LIST_ENTRY *ListHead,\r | |
189 | IN HEFI_EDITOR_LINE *Lines\r | |
190 | )\r | |
632820d1 | 191 | {\r |
a1d4bfcc | 192 | LIST_ENTRY *Link;\r |
632820d1 | 193 | HEFI_EDITOR_LINE *Line;\r |
194 | \r | |
195 | //\r | |
196 | // release all the lines\r | |
197 | //\r | |
198 | if (Lines != NULL) {\r | |
199 | \r | |
200 | Line = Lines;\r | |
201 | Link = &(Line->Link);\r | |
202 | do {\r | |
203 | Line = CR (Link, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);\r | |
204 | Link = Link->ForwardLink;\r | |
205 | HLineFree (Line);\r | |
206 | } while (Link != ListHead);\r | |
207 | }\r | |
208 | \r | |
209 | ListHead->ForwardLink = ListHead;\r | |
210 | ListHead->BackLink = ListHead;\r | |
211 | \r | |
212 | return EFI_SUCCESS;\r | |
213 | }\r | |
214 | \r | |
a1d4bfcc | 215 | /**\r |
216 | Get the X information for the mouse.\r | |
632820d1 | 217 | \r |
a1d4bfcc | 218 | @param[in] GuidX The change.\r |
632820d1 | 219 | \r |
a1d4bfcc | 220 | @return the new information.\r |
221 | **/\r | |
632820d1 | 222 | INT32\r |
223 | HGetTextX (\r | |
224 | IN INT32 GuidX\r | |
225 | )\r | |
226 | {\r | |
227 | INT32 Gap;\r | |
228 | \r | |
229 | HMainEditor.MouseAccumulatorX += GuidX;\r | |
230 | Gap = (HMainEditor.MouseAccumulatorX * (INT32) HMainEditor.ScreenSize.Column) / (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionX);\r | |
231 | HMainEditor.MouseAccumulatorX = (HMainEditor.MouseAccumulatorX * (INT32) HMainEditor.ScreenSize.Column) % (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionX);\r | |
232 | HMainEditor.MouseAccumulatorX = HMainEditor.MouseAccumulatorX / (INT32) HMainEditor.ScreenSize.Column;\r | |
233 | return Gap;\r | |
234 | }\r | |
235 | \r | |
a1d4bfcc | 236 | /**\r |
237 | Get the Y information for the mouse.\r | |
238 | \r | |
239 | @param[in] GuidY The change.\r | |
240 | \r | |
241 | @return the new information.\r | |
242 | **/\r | |
632820d1 | 243 | INT32\r |
244 | HGetTextY (\r | |
245 | IN INT32 GuidY\r | |
246 | )\r | |
247 | {\r | |
248 | INT32 Gap;\r | |
249 | \r | |
250 | HMainEditor.MouseAccumulatorY += GuidY;\r | |
251 | Gap = (HMainEditor.MouseAccumulatorY * (INT32) HMainEditor.ScreenSize.Row) / (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionY);\r | |
252 | HMainEditor.MouseAccumulatorY = (HMainEditor.MouseAccumulatorY * (INT32) HMainEditor.ScreenSize.Row) % (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionY);\r | |
253 | HMainEditor.MouseAccumulatorY = HMainEditor.MouseAccumulatorY / (INT32) HMainEditor.ScreenSize.Row;\r | |
254 | \r | |
255 | return Gap;\r | |
256 | }\r |