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