]>
Commit | Line | Data |
---|---|---|
2442e62a | 1 | /** @file\r |
2 | Implements titlebar interface functions.\r | |
3 | \r | |
c011b6c9 | 4 | (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>\r |
17e59b33 | 5 | Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>\r |
2442e62a | 6 | This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "EditTitleBar.h"\r | |
17 | #include "UefiShellDebug1CommandsLib.h"\r | |
18 | \r | |
19 | CHAR16 *Title = NULL;\r | |
20 | \r | |
21 | /**\r | |
22 | Initialize a title bar.\r | |
23 | \r | |
24 | @param[in] Prompt The prompt to print in the title bar.\r | |
25 | \r | |
26 | @retval EFI_SUCCESS The initialization was successful.\r | |
27 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
28 | **/\r | |
29 | EFI_STATUS\r | |
2442e62a | 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 | |
2442e62a | 54 | MainTitleBarCleanup (\r |
55 | VOID\r | |
56 | )\r | |
57 | {\r | |
58 | SHELL_FREE_NON_NULL (Title);\r | |
59 | Title = NULL;\r | |
60 | }\r | |
61 | \r | |
62 | typedef struct {\r | |
63 | UINT32 Foreground : 4;\r | |
64 | UINT32 Background : 4;\r | |
65 | } TITLE_BAR_COLOR_ATTRIBUTES;\r | |
66 | \r | |
67 | typedef union {\r | |
68 | TITLE_BAR_COLOR_ATTRIBUTES Colors;\r | |
69 | UINTN Data;\r | |
70 | } TITLE_BAR_COLOR_UNION;\r | |
71 | \r | |
72 | /**\r | |
73 | Refresh function for MainTitleBar\r | |
74 | \r | |
75 | @param[in] FileName The open file's name (or NULL).\r | |
76 | @param[in] FileType The type fo the file.\r | |
77 | @param[in] ReadOnly TRUE if the file is read only. FALSE otherwise.\r | |
78 | @param[in] Modified TRUE if the file was modified. FALSE otherwise.\r | |
79 | @param[in] LastCol The last printable column.\r | |
80 | @param[in] LastRow The last printable row.\r | |
980d554e | 81 | @param[in] Offset The offset into the file. (only for mem/disk)\r |
82 | @param[in] Size The file's size. (only for mem/disk)\r | |
2442e62a | 83 | \r |
84 | @retval EFI_SUCCESS The operation was successful.\r | |
85 | **/\r | |
86 | EFI_STATUS\r | |
2442e62a | 87 | MainTitleBarRefresh (\r |
88 | IN CONST CHAR16 *FileName OPTIONAL,\r | |
89 | IN CONST EDIT_FILE_TYPE FileType,\r | |
980d554e | 90 | IN CONST BOOLEAN ReadOnly,\r |
91 | IN CONST BOOLEAN Modified,\r | |
92 | IN CONST UINTN LastCol,\r | |
93 | IN CONST UINTN LastRow,\r | |
94 | IN CONST UINTN Offset,\r | |
95 | IN CONST UINTN Size\r | |
2442e62a | 96 | )\r |
97 | {\r | |
98 | TITLE_BAR_COLOR_UNION Orig;\r | |
99 | TITLE_BAR_COLOR_UNION New;\r | |
100 | CONST CHAR16 *FileNameTmp;\r | |
101 | INTN TempInteger;\r | |
102 | \r | |
103 | \r | |
104 | //\r | |
105 | // backup the old screen attributes\r | |
106 | //\r | |
107 | Orig.Data = gST->ConOut->Mode->Attribute;\r | |
28981267 | 108 | New.Data = 0;\r |
17e59b33 JC |
109 | New.Colors.Foreground = Orig.Colors.Background & 0xF;\r |
110 | New.Colors.Background = Orig.Colors.Foreground & 0x7;\r | |
2442e62a | 111 | \r |
17e59b33 | 112 | gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r |
2442e62a | 113 | \r |
114 | //\r | |
115 | // clear the title line\r | |
116 | //\r | |
117 | EditorClearLine (1, LastCol, LastRow);\r | |
118 | \r | |
119 | if (Title != NULL) {\r | |
120 | //\r | |
121 | // print the new title bar prefix\r | |
122 | //\r | |
123 | ShellPrintEx (\r | |
124 | 0,\r | |
125 | 0,\r | |
126 | L"%s ",\r | |
127 | Title\r | |
128 | );\r | |
129 | }\r | |
130 | if (FileName == NULL) {\r | |
131 | gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r | |
132 | return EFI_SUCCESS;\r | |
133 | }\r | |
134 | //\r | |
135 | // First Extract the FileName from fullpath\r | |
136 | //\r | |
137 | FileNameTmp = FileName;\r | |
138 | for (TempInteger = StrLen (FileNameTmp) - 1; TempInteger >= 0; TempInteger--) {\r | |
139 | if (FileNameTmp[TempInteger] == L'\\') {\r | |
140 | break;\r | |
141 | }\r | |
142 | }\r | |
143 | \r | |
144 | FileNameTmp = FileNameTmp + TempInteger + 1;\r | |
145 | \r | |
146 | //\r | |
147 | // the space for file name is 20 characters\r | |
148 | //\r | |
149 | if (StrLen (FileNameTmp) <= 20) {\r | |
150 | ShellPrintEx (-1,-1, L"%s ", FileNameTmp);\r | |
151 | for (TempInteger = StrLen (FileNameTmp); TempInteger < 20; TempInteger++) {\r | |
152 | ShellPrintEx (-1,-1, L" ");\r | |
153 | }\r | |
154 | \r | |
155 | } else {\r | |
156 | for (TempInteger = 0; TempInteger < 17; TempInteger++) {\r | |
157 | ShellPrintEx (-1,-1, L"%c", FileNameTmp[TempInteger]);\r | |
158 | }\r | |
159 | //\r | |
160 | // print "..."\r | |
161 | //\r | |
162 | ShellPrintEx (-1,-1, L"... ");\r | |
163 | }\r | |
164 | //\r | |
165 | // print file type field\r | |
166 | //\r | |
167 | switch (FileType){\r | |
168 | case FileTypeAscii:\r | |
169 | case FileTypeUnicode:\r | |
170 | if (FileType == FileTypeAscii){\r | |
abbea36e CP |
171 | ShellPrintEx (-1,-1, L" ASCII ");\r |
172 | } else {\r | |
2442e62a | 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 |