aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.inf1
-rw-r--r--Library/UefiShellUfmCommandLib/dialog-box.c101
-rw-r--r--Library/UefiShellUfmCommandLib/dialog-box.h47
3 files changed, 149 insertions, 0 deletions
diff --git a/Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.inf b/Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.inf
index c3d623e..3e8bb60 100644
--- a/Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.inf
+++ b/Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.inf
@@ -15,6 +15,7 @@
menu-bar.c
command-bar.c
widget/input.c
+ dialog-box.c
panel.c
dir.c
fs.c
diff --git a/Library/UefiShellUfmCommandLib/dialog-box.c b/Library/UefiShellUfmCommandLib/dialog-box.c
new file mode 100644
index 0000000..0da3fae
--- /dev/null
+++ b/Library/UefiShellUfmCommandLib/dialog-box.c
@@ -0,0 +1,101 @@
+#include <Library/UefiLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include "dialog-box.h"
+
+#define COLOR_WHITE_CYAN (EFI_TEXT_ATTR(EFI_WHITE, EFI_CYAN))
+#define COLOR_WHITE_LIGHTGRAY (EFI_TEXT_ATTR(EFI_WHITE, EFI_LIGHTGRAY))
+
+CONST CHAR16 ok_button_msg[] = L"[ OK ]";
+CONST CHAR16 cl_button_msg[] = L"[ Cancel ]";
+
+struct dbox_ctx *dbox_alloc(struct screen *scr, CONST CHAR16 *title,
+ CONST CHAR16 *label, BOOLEAN wid_input, CONST CHAR16 *input_text)
+{
+ struct dbox_ctx *dbox;
+ UINTN y;
+ CONST UINTN dbox_height = wid_input ? 6 : 5;
+ CONST UINTN dbox_width = 52; // why 52?
+ CONST UINTN len_ok = StrLen(ok_button_msg), len_cl = StrLen(cl_button_msg);
+ UINTN start_x, start_y, start_ok;
+ BOOLEAN res = FALSE;
+
+ ASSERT(scr != NULL);
+
+ dbox = AllocateZeroPool(sizeof(struct dbox_ctx));
+ if(!dbox)
+ return NULL;
+
+ do { // START DO
+
+ start_x = (scr->columns - dbox_width) / 2;
+ start_y = (scr->lines - dbox_height) / 2;
+ dbox->wbg = newwin(scr, dbox_width, dbox_height, start_x, start_y);
+ if(!dbox->wbg)
+ break;
+ wborder(dbox->wbg,
+ BOXDRAW_VERTICAL, BOXDRAW_VERTICAL, BOXDRAW_HORIZONTAL, BOXDRAW_HORIZONTAL,
+ BOXDRAW_DOWN_RIGHT, BOXDRAW_DOWN_LEFT, BOXDRAW_UP_RIGHT, BOXDRAW_UP_LEFT
+ );
+ mvwprintf(dbox->wbg, 1 + ((dbox_width - StrLen(title)) / 2), 0, L"%s", title);
+ mvwprintf(dbox->wbg, 2, 1, L"%s", label);
+ whline(dbox->wbg, 1, dbox_height - 3, BOXDRAW_HORIZONTAL, -1, dbox_width - 2);
+
+ if(wid_input) {
+ dbox->in = input_alloc(scr, start_x + 2, start_y + 2,
+ dbox_width - 4, COLOR_WHITE_CYAN, input_text);
+ if(!dbox->in)
+ break;
+ }
+
+ start_ok = start_x + 1 + ((dbox_width - len_ok - 1 - len_cl) / 2);
+ dbox->wok = newwin(scr, len_ok, 1, start_ok, start_y + dbox_height - 2);
+ if(!dbox->wok)
+ break;
+ mvwprintf(dbox->wok, 0, 0, ok_button_msg);
+
+ dbox->wcl = newwin(scr, len_cl, 1, start_ok + 1 + len_ok, start_y + dbox_height - 2);
+ if(!dbox->wcl)
+ break;
+ mvwprintf(dbox->wcl, 0, 0, cl_button_msg);
+
+ for(y = 0; y < dbox_height; y++)
+ whline(dbox->wbg, 0, y, 0, COLOR_WHITE_LIGHTGRAY, 0);
+
+ res = TRUE;
+
+ } while(0); // END DO
+
+ if(!res) {
+ dbox_release(dbox);
+ return NULL;
+ }
+
+ return dbox;
+}
+
+VOID dbox_release(struct dbox_ctx *dbox)
+{
+ ASSERT(dbox != NULL);
+
+ if(dbox->wbg)
+ delwin(dbox->wbg);
+ if(dbox->in)
+ input_release(dbox->in);
+ if(dbox->wok)
+ delwin(dbox->wok);
+ if(dbox->wcl)
+ delwin(dbox->wcl);
+
+ FreePool(dbox);
+}
+
+VOID dbox_refresh(struct dbox_ctx *dbox)
+{
+ wrefresh(dbox->wbg);
+ if(dbox->in)
+ input_update(dbox->in);
+ wrefresh(dbox->wok);
+ wrefresh(dbox->wcl);
+}
diff --git a/Library/UefiShellUfmCommandLib/dialog-box.h b/Library/UefiShellUfmCommandLib/dialog-box.h
new file mode 100644
index 0000000..d6d6e43
--- /dev/null
+++ b/Library/UefiShellUfmCommandLib/dialog-box.h
@@ -0,0 +1,47 @@
+#ifndef UFM_DIALOG_BOX_H
+#define UFM_DIALOG_BOX_H
+
+#include <Uefi.h>
+#include "widget/input.h"
+
+struct dbox_ctx {
+ struct window *wbg;
+ struct widget_input *in;
+ struct window *wok, *wcl;
+};
+
+/*
+ * Creates a dialog box with given parameters. Appears exactly in the
+ * middle of the screen
+ *
+ * scr: the information of the screen
+ * title: the pointer to title string
+ * label: the pointer to label string
+ * wid_input: TRUE if the dialog box needs an input widget. FALSE if not
+ * input_text: the pointer to initial string in the input widget. If
+ wid_input is false, the variable is ignored
+ *
+ * return: A pointer to the allocated structure or NULL if allocation fails
+*/
+struct dbox_ctx *dbox_alloc(struct screen *scr, CONST CHAR16 *title,
+ CONST CHAR16 *label, BOOLEAN wid_input, CONST CHAR16 *input_text);
+
+/*
+ * Deletes the dialog box, frees the structure
+ *
+ * dbox: the dialog box on which to operate
+ *
+ * return: VOID
+*/
+VOID dbox_release(struct dbox_ctx *dbox);
+
+/*
+ * Does the output of dialog box to the terminal
+ *
+ * dbox: the dialog box on which to operate
+ *
+ * return: VOID
+*/
+VOID dbox_refresh(struct dbox_ctx *dbox);
+
+#endif /* UFM_DIALOG_BOX_H */