]>
Commit | Line | Data |
---|---|---|
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 | |
18 | CHAR16 *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 | |
28 | EFI_STATUS\r | |
29 | EFIAPI\r | |
30 | MainTitleBarInit (\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 | |
53 | VOID\r | |
54 | EFIAPI\r | |
55 | MainTitleBarCleanup (\r | |
56 | VOID\r | |
57 | )\r | |
58 | {\r | |
59 | SHELL_FREE_NON_NULL (Title);\r | |
60 | Title = NULL;\r | |
61 | }\r | |
62 | \r | |
63 | typedef struct {\r | |
64 | UINT32 Foreground : 4;\r | |
65 | UINT32 Background : 4;\r | |
66 | } TITLE_BAR_COLOR_ATTRIBUTES;\r | |
67 | \r | |
68 | typedef 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 | |
87 | EFI_STATUS\r | |
88 | EFIAPI\r | |
89 | MainTitleBarRefresh (\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 | |
110 | New.Colors.Foreground = Orig.Colors.Background;\r | |
111 | New.Colors.Background = Orig.Colors.Foreground;\r | |
112 | \r | |
113 | gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r | |
114 | \r | |
115 | //\r | |
116 | // clear the title line\r | |
117 | //\r | |
118 | EditorClearLine (1, LastCol, LastRow);\r | |
119 | \r | |
120 | if (Title != NULL) {\r | |
121 | //\r | |
122 | // print the new title bar prefix\r | |
123 | //\r | |
124 | ShellPrintEx (\r | |
125 | 0,\r | |
126 | 0,\r | |
127 | L"%s ",\r | |
128 | Title\r | |
129 | );\r | |
130 | }\r | |
131 | if (FileName == NULL) {\r | |
132 | gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r | |
133 | return EFI_SUCCESS;\r | |
134 | }\r | |
135 | //\r | |
136 | // First Extract the FileName from fullpath\r | |
137 | //\r | |
138 | FileNameTmp = FileName;\r | |
139 | for (TempInteger = StrLen (FileNameTmp) - 1; TempInteger >= 0; TempInteger--) {\r | |
140 | if (FileNameTmp[TempInteger] == L'\\') {\r | |
141 | break;\r | |
142 | }\r | |
143 | }\r | |
144 | \r | |
145 | FileNameTmp = FileNameTmp + TempInteger + 1;\r | |
146 | \r | |
147 | //\r | |
148 | // the space for file name is 20 characters\r | |
149 | //\r | |
150 | if (StrLen (FileNameTmp) <= 20) {\r | |
151 | ShellPrintEx (-1,-1, L"%s ", FileNameTmp);\r | |
152 | for (TempInteger = StrLen (FileNameTmp); TempInteger < 20; TempInteger++) {\r | |
153 | ShellPrintEx (-1,-1, L" ");\r | |
154 | }\r | |
155 | \r | |
156 | } else {\r | |
157 | for (TempInteger = 0; TempInteger < 17; TempInteger++) {\r | |
158 | ShellPrintEx (-1,-1, L"%c", FileNameTmp[TempInteger]);\r | |
159 | }\r | |
160 | //\r | |
161 | // print "..."\r | |
162 | //\r | |
163 | ShellPrintEx (-1,-1, L"... ");\r | |
164 | }\r | |
165 | //\r | |
166 | // print file type field\r | |
167 | //\r | |
168 | switch (FileType){\r | |
169 | case FileTypeAscii:\r | |
170 | case FileTypeUnicode:\r | |
171 | if (FileType == FileTypeAscii){\r | |
172 | ShellPrintEx (-1,-1, L" UNICODE ");\r | |
173 | }\r | |
174 | //\r | |
175 | // print read-only field for text files\r | |
176 | //\r | |
177 | if (ReadOnly) {\r | |
178 | ShellPrintEx (-1,-1, L"ReadOnly ");\r | |
179 | } else {\r | |
180 | ShellPrintEx (-1,-1, L" ");\r | |
181 | }\r | |
182 | break;\r | |
183 | case FileTypeDiskBuffer:\r | |
184 | case FileTypeMemBuffer:\r | |
185 | //\r | |
186 | // Print the offset.\r | |
187 | //\r | |
411a3c39 | 188 | ShellPrintEx (-1,-1, L"Offset %X | Size %X", Offset, Size);\r |
2442e62a | 189 | case FileTypeFileBuffer:\r |
190 | break;\r | |
e0c2cc6f | 191 | default:\r |
192 | break;\r | |
2442e62a | 193 | }\r |
194 | //\r | |
195 | // print modified field\r | |
196 | //\r | |
197 | if (Modified) {\r | |
198 | ShellPrintEx (-1,-1, L"Modified");\r | |
199 | }\r | |
200 | //\r | |
201 | // restore the old attribute\r | |
202 | //\r | |
203 | gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r | |
204 | \r | |
205 | return EFI_SUCCESS;\r | |
206 | }\r |