]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.c
ShellPkg: Fix ARM build errors.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / EditTitleBar.c
CommitLineData
2442e62a 1/** @file\r
2 Implements titlebar interface functions.\r
3\r
4 Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "EditTitleBar.h"\r
16#include "UefiShellDebug1CommandsLib.h"\r
17\r
18CHAR16 *Title = NULL;\r
19\r
20/**\r
21 Initialize a title bar.\r
22\r
23 @param[in] Prompt The prompt to print in the title bar.\r
24\r
25 @retval EFI_SUCCESS The initialization was successful.\r
26 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
27**/\r
28EFI_STATUS\r
29EFIAPI\r
30MainTitleBarInit (\r
31 CONST CHAR16 *Prompt\r
32 )\r
33{\r
34 SHELL_FREE_NON_NULL (Title);\r
35 if (Prompt == NULL) {\r
36 Title = CatSPrint (NULL, L"");\r
37 } else {\r
38 //\r
39 // set Title\r
40 //\r
41 Title = CatSPrint (NULL, L"%s", Prompt);\r
42 }\r
43 if (Title == NULL) {\r
44 return EFI_OUT_OF_RESOURCES;\r
45 }\r
46\r
47 return EFI_SUCCESS;\r
48}\r
49\r
50/**\r
51 Clean up the memory used.\r
52**/\r
53VOID\r
54EFIAPI\r
55MainTitleBarCleanup (\r
56 VOID\r
57 )\r
58{\r
59 SHELL_FREE_NON_NULL (Title);\r
60 Title = NULL;\r
61}\r
62\r
63typedef struct {\r
64 UINT32 Foreground : 4;\r
65 UINT32 Background : 4;\r
66} TITLE_BAR_COLOR_ATTRIBUTES;\r
67\r
68typedef union {\r
69 TITLE_BAR_COLOR_ATTRIBUTES Colors;\r
70 UINTN Data;\r
71} TITLE_BAR_COLOR_UNION;\r
72\r
73/**\r
74 Refresh function for MainTitleBar\r
75\r
76 @param[in] FileName The open file's name (or NULL).\r
77 @param[in] FileType The type fo the file.\r
78 @param[in] ReadOnly TRUE if the file is read only. FALSE otherwise.\r
79 @param[in] Modified TRUE if the file was modified. FALSE otherwise.\r
80 @param[in] LastCol The last printable column.\r
81 @param[in] LastRow The last printable row.\r
980d554e 82 @param[in] Offset The offset into the file. (only for mem/disk)\r
83 @param[in] Size The file's size. (only for mem/disk)\r
2442e62a 84\r
85 @retval EFI_SUCCESS The operation was successful.\r
86**/\r
87EFI_STATUS\r
88EFIAPI\r
89MainTitleBarRefresh (\r
90 IN CONST CHAR16 *FileName OPTIONAL,\r
91 IN CONST EDIT_FILE_TYPE FileType,\r
980d554e 92 IN CONST BOOLEAN ReadOnly,\r
93 IN CONST BOOLEAN Modified,\r
94 IN CONST UINTN LastCol,\r
95 IN CONST UINTN LastRow,\r
96 IN CONST UINTN Offset,\r
97 IN CONST UINTN Size\r
2442e62a 98 )\r
99{\r
100 TITLE_BAR_COLOR_UNION Orig;\r
101 TITLE_BAR_COLOR_UNION New;\r
102 CONST CHAR16 *FileNameTmp;\r
103 INTN TempInteger;\r
104\r
105\r
106 //\r
107 // backup the old screen attributes\r
108 //\r
109 Orig.Data = gST->ConOut->Mode->Attribute;\r
28981267 110 New.Data = 0;\r
2442e62a 111 New.Colors.Foreground = Orig.Colors.Background;\r
112 New.Colors.Background = Orig.Colors.Foreground;\r
113\r
114 gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r
115\r
116 //\r
117 // clear the title line\r
118 //\r
119 EditorClearLine (1, LastCol, LastRow);\r
120\r
121 if (Title != NULL) {\r
122 //\r
123 // print the new title bar prefix\r
124 //\r
125 ShellPrintEx (\r
126 0,\r
127 0,\r
128 L"%s ",\r
129 Title\r
130 );\r
131 }\r
132 if (FileName == NULL) {\r
133 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
134 return EFI_SUCCESS;\r
135 }\r
136 //\r
137 // First Extract the FileName from fullpath\r
138 //\r
139 FileNameTmp = FileName;\r
140 for (TempInteger = StrLen (FileNameTmp) - 1; TempInteger >= 0; TempInteger--) {\r
141 if (FileNameTmp[TempInteger] == L'\\') {\r
142 break;\r
143 }\r
144 }\r
145\r
146 FileNameTmp = FileNameTmp + TempInteger + 1;\r
147\r
148 //\r
149 // the space for file name is 20 characters\r
150 //\r
151 if (StrLen (FileNameTmp) <= 20) {\r
152 ShellPrintEx (-1,-1, L"%s ", FileNameTmp);\r
153 for (TempInteger = StrLen (FileNameTmp); TempInteger < 20; TempInteger++) {\r
154 ShellPrintEx (-1,-1, L" ");\r
155 }\r
156\r
157 } else {\r
158 for (TempInteger = 0; TempInteger < 17; TempInteger++) {\r
159 ShellPrintEx (-1,-1, L"%c", FileNameTmp[TempInteger]);\r
160 }\r
161 //\r
162 // print "..."\r
163 //\r
164 ShellPrintEx (-1,-1, L"... ");\r
165 }\r
166 //\r
167 // print file type field\r
168 //\r
169 switch (FileType){\r
170 case FileTypeAscii:\r
171 case FileTypeUnicode:\r
172 if (FileType == FileTypeAscii){\r
173 ShellPrintEx (-1,-1, L" UNICODE ");\r
174 }\r
175 //\r
176 // print read-only field for text files\r
177 //\r
178 if (ReadOnly) {\r
179 ShellPrintEx (-1,-1, L"ReadOnly ");\r
180 } else {\r
181 ShellPrintEx (-1,-1, L" ");\r
182 }\r
183 break;\r
184 case FileTypeDiskBuffer:\r
185 case FileTypeMemBuffer:\r
186 //\r
187 // Print the offset.\r
188 //\r
411a3c39 189 ShellPrintEx (-1,-1, L"Offset %X | Size %X", Offset, Size);\r
2442e62a 190 case FileTypeFileBuffer:\r
191 break;\r
e0c2cc6f 192 default:\r
193 break;\r
2442e62a 194 }\r
195 //\r
196 // print modified field\r
197 //\r
198 if (Modified) {\r
199 ShellPrintEx (-1,-1, L"Modified");\r
200 }\r
201 //\r
202 // restore the old attribute\r
203 //\r
204 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
205\r
206 return EFI_SUCCESS;\r
207}\r