328 lines
12 KiB
C
328 lines
12 KiB
C
/** @file
|
|
UI One Of Input Dialog
|
|
|
|
;******************************************************************************
|
|
;* Copyright (c) 2014 - 2020, Insyde Software Corp. All Rights Reserved.
|
|
;*
|
|
;* You may not reproduce, distribute, publish, display, perform, modify, adapt,
|
|
;* transmit, broadcast, present, recite, release, license or otherwise exploit
|
|
;* any part of this publication in any form, by any means, without the prior
|
|
;* written permission of Insyde Software Corporation.
|
|
;*
|
|
;******************************************************************************
|
|
*/
|
|
|
|
#include "MetroDialog.h"
|
|
|
|
STATIC H2O_ONE_OF_INPUT_DIALOG_CLASS *mH2OOneOfInputDialogClass = NULL;
|
|
#define CURRENT_CLASS mH2OOneOfInputDialogClass
|
|
|
|
VOID
|
|
FreeDialogEvent (
|
|
IN H2O_FORM_BROWSER_D **DialogEvt
|
|
);
|
|
|
|
#if FixedPcdGet32(PcdH2OLmdeMultiLayout) == 0
|
|
CHAR16 *mOneOfDialogChilds = L""
|
|
L"<ListView name='OneOfList' vscrollbar='true' tabstop='true' padding='15,0,0,0' child-padding='2' taborder='1'/>";
|
|
|
|
CHAR16 *mOneOfDialogWithoutSendFormChilds = L""
|
|
L"<VerticalLayout name='OneOfDialog'>"
|
|
L"<Control/>"
|
|
L"<HorizontalLayout height='wrap_content'>"
|
|
L"<Control/>"
|
|
L"<Control width='wrap_content' height='wrap_content'>"
|
|
L"<VerticalLayout name='Content' width='wrap_content' height='wrap_content' padding='20,30,20,30' child-padding='15' background-color='@menucolor'>"
|
|
L"<Label name='DialogTitle' text-align='center' height='wrap_content' width='match_parent' font-size='19' textcolor='0xFFFFFFFF'/>"
|
|
L"<Control height='10' background-image='@DialogSeparator' background-color='0x0' background-image-style='center'/>"
|
|
L"<ListView name='OneOfList' vscrollbar='true' width='wrap_content' height='wrap_content' padding='0,0,0,0' child-padding='2'/>"
|
|
L"</VerticalLayout>"
|
|
L"<Texture name='FormHalo' float='true' height='-1' width='-1' background-image='@FormHalo' scale9grid='23,26,22,31'/>"
|
|
L"</Control>"
|
|
L"<Control/>"
|
|
L"</HorizontalLayout>"
|
|
L"<Control/>"
|
|
L"</VerticalLayout>";
|
|
|
|
CHAR16 *mOneOfOptionChilds = L""
|
|
L"<HorizontalLayout height='40'>"
|
|
L"<Label name='Option' padding='0,20,0,20' text-align='singleline|center' height='40' font-size='19' background-color='0xFFE6E6E6' textcolor='0xFF404040' text-overflow='ellipsis'/>"
|
|
L"<Texture name='OptionSelectedIcon' float='true' left='260' top='12' width='21' height='17' position='absolute' visibility='false' background-image='@DialogSelectedIcon' background-color='0x0'/>"
|
|
L"</HorizontalLayout>";
|
|
|
|
CHAR16 *mOneOfOptionChildsWithoutSendForm = L""
|
|
L"<VerticalLayout height='40'>"
|
|
L"<Label name='Option' text-align='singleline' height='40' padding='0,10,0,10' width='match_parent' font-size='19' background-color='0xFFE6E6E6' textcolor='0xFF404040' text-overflow='ellipsis'/>"
|
|
L"</VerticalLayout>";
|
|
#endif
|
|
|
|
STATIC
|
|
VOID
|
|
H2OOneOfOptionOnSetState (
|
|
UI_CONTROL *Control,
|
|
UI_STATE SetState,
|
|
UI_STATE ClearState
|
|
)
|
|
{
|
|
UI_CONTROL *Child;
|
|
COLORREF Color;
|
|
EFI_IMAGE_INPUT *Image;
|
|
|
|
if (!((SetState & UISTATE_SELECTED) || (ClearState & UISTATE_SELECTED))) {
|
|
return ;
|
|
}
|
|
|
|
if (SetState & UISTATE_SELECTED) {
|
|
Child = UiFindChildByName (Control, L"Option");
|
|
UiSetAttribute (Child, L"marquee", L"true");
|
|
UiApplyAttributeList (Child, L"textcolor='0xFFFFFFFF' background-color='@menulightcolor' ");
|
|
if (PcdGet32(PcdH2OLmdeMultiLayout) == 1) {
|
|
UiApplyAttributeList (Child, L"textcolor='0xFF404040'");
|
|
}
|
|
if (mIsSendForm) {
|
|
Child = UiFindChildByName (Control, L"OptionSelectedIcon");
|
|
ASSERT (Child != NULL);
|
|
if (Child == NULL) {
|
|
return;
|
|
}
|
|
|
|
if (IsWindowVisible (Child->Wnd)) {
|
|
Color = GetColorValue (L"0xFFFFFFFF");
|
|
Image = GetImageByString (Child->BkImage);
|
|
if (Image != NULL) {
|
|
AdjustImage (Child, Image->Bitmap, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)&Color);
|
|
}
|
|
}
|
|
}
|
|
|
|
} else {
|
|
Child = UiFindChildByName (Control, L"Option");
|
|
UiSetAttribute (Child, L"marquee", L"false");
|
|
UiApplyAttributeList (Child, L"textcolor='0xFF404040' background-color='0xFFE6E6E6' ");
|
|
if (PcdGet32(PcdH2OLmdeMultiLayout) == 1) {
|
|
UiApplyAttributeList (Child, L"textcolor='0xFFFFFFFF' background-color='0x0'");
|
|
}
|
|
if (mIsSendForm) {
|
|
Child = UiFindChildByName (Control, L"OptionSelectedIcon");
|
|
ASSERT (Child != NULL);
|
|
if (Child == NULL) {
|
|
return;
|
|
}
|
|
|
|
if (IsWindowVisible (Child->Wnd)) {
|
|
Color = GetColorValue (L"@menulightcolor");
|
|
Image = GetImageByString (Child->BkImage);
|
|
if (Image != NULL) {
|
|
AdjustImage (Child, Image->Bitmap, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)&Color);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
STATIC
|
|
VOID
|
|
H2OOneOfOptionOnItemClick (
|
|
UI_LIST_VIEW *This,
|
|
UI_CONTROL *Item,
|
|
UINT32 Index
|
|
)
|
|
{
|
|
Index = (UINT32) GetWindowLongPtr (Item->Wnd, GWLP_USERDATA);
|
|
SendChangeQNotify (0, 0, &mFbDialog->BodyHiiValueArray[Index]);
|
|
}
|
|
|
|
STATIC
|
|
LRESULT
|
|
H2OOneOfInputProc (
|
|
IN HWND Wnd,
|
|
IN UINT Msg,
|
|
IN WPARAM WParam,
|
|
IN LPARAM LParam
|
|
)
|
|
{
|
|
UI_CONTROL *Control;
|
|
H2O_ONE_OF_INPUT_DIALOG *This;
|
|
UI_CONTROL *Layout;
|
|
UINTN Index;
|
|
CHAR16 Str[20];
|
|
EFI_IMAGE_INPUT *FormsetImage;
|
|
UI_CONTROL *CreatedControl;
|
|
INTN Result;
|
|
EFI_STATUS Status;
|
|
INT32 MaxWidth;
|
|
SIZE Size;
|
|
HDC Hdc;
|
|
INT32 Padding;
|
|
INT32 Border;
|
|
UI_CONTROL *Content;
|
|
SIZE ContentSize;
|
|
|
|
Control = GetUiControl (Wnd);
|
|
This = (H2O_ONE_OF_INPUT_DIALOG *)Control;
|
|
|
|
switch (Msg) {
|
|
|
|
case WM_CREATE:
|
|
This = (H2O_ONE_OF_INPUT_DIALOG *) AllocateZeroPool (sizeof (H2O_ONE_OF_INPUT_DIALOG));
|
|
if (This == NULL) {
|
|
break;
|
|
}
|
|
CopyMem (This, (VOID *)((CREATESTRUCT *)(LParam))->lpCreateParams, sizeof (UI_DIALOG));
|
|
CONTROL_CLASS (This) = (UI_CONTROL_CLASS *) GetClassLongPtr (Wnd, 0);
|
|
SetWindowLongPtr (Wnd, 0, (INTN)This);
|
|
SetWindowLongPtr (Wnd, GWL_STYLE, GetWindowLongPtr (Wnd, GWL_STYLE) & (~WS_CHILD));
|
|
SendMessage (Wnd, UI_NOTIFY_CREATE, WParam, LParam);
|
|
break;
|
|
|
|
case UI_NOTIFY_CREATE:
|
|
PARENT_CLASS_WNDPROC (CURRENT_CLASS, Wnd, Msg, WParam, LParam);
|
|
if (Control != NULL) {
|
|
if (mIsSendForm) {
|
|
XmlCreateControl (mCommonDialogWithHelpChilds, Control);
|
|
} else {
|
|
XmlCreateControl (mOneOfDialogWithoutSendFormChilds, Control);
|
|
}
|
|
}
|
|
break;
|
|
|
|
case UI_NOTIFY_WINDOWINIT:
|
|
if (mFbDialog->TitleString != NULL) {
|
|
Control = UiFindChildByName (This, L"DialogTitle");
|
|
UiSetAttribute (Control, L"text", mFbDialog->TitleString);
|
|
}
|
|
|
|
Control = UiFindChildByName (This, L"Content");
|
|
if (Control != NULL && gFB->CurrentQ != NULL) {
|
|
XmlCreateControl (mOneOfDialogChilds, Control);
|
|
}
|
|
|
|
Control = UiFindChildByName (This, L"DialogTextScrollView");
|
|
if (Control != NULL) {
|
|
Control->OnSetState = H2OCommonDialogWithHelpOnSetState;
|
|
}
|
|
|
|
if ((mFbDialog->DialogType & H2O_FORM_BROWSER_D_TYPE_FROM_H2O_DIALOG) == 0 && gFB->CurrentQ != NULL && gFB->CurrentQ->Help != NULL) {
|
|
Control = UiFindChildByName (This, L"DialogText");
|
|
UiSetAttribute (Control, L"text", gFB->CurrentQ->Help);
|
|
}
|
|
|
|
FormsetImage = GetCurrentFormSetImage ();
|
|
if (FormsetImage != NULL) {
|
|
Control = UiFindChildByName (This, L"DialogImage");
|
|
UnicodeSPrint (Str, sizeof (Str), L"0x%p", FormsetImage);
|
|
UiSetAttribute (Control, L"background-image", Str);
|
|
UiSetAttribute (Control, L"visibility", L"true");
|
|
}
|
|
|
|
Layout = UiFindChildByName (This, L"OneOfList");
|
|
if (Layout->VScrollBar != NULL) {
|
|
UiSetAttribute (Layout->VScrollBar, L"displayscrollbar", L"false");
|
|
CONTROL_CLASS_INVALIDATE (Layout);
|
|
}
|
|
|
|
CreatedControl = NULL;
|
|
((UI_LIST_VIEW *)Layout)->OnItemClick = H2OOneOfOptionOnItemClick;
|
|
for (Index = 0, Result = 1; Index < mFbDialog->BodyStringCount; Index++) {
|
|
if (gFB->CurrentP != NULL) {
|
|
CreatedControl = XmlCreateControl (mOneOfOptionChilds, Layout);
|
|
} else {
|
|
CreatedControl = XmlCreateControl (mOneOfOptionChildsWithoutSendForm, Layout);
|
|
}
|
|
if (CreatedControl == NULL) {
|
|
continue;
|
|
}
|
|
|
|
SetWindowLongPtr (CreatedControl->Wnd, GWLP_USERDATA, (INTN) Index);
|
|
CreatedControl->OnSetState = H2OOneOfOptionOnSetState;
|
|
|
|
Control = UiFindChildByName (CreatedControl, L"Option");
|
|
UiSetAttribute (Control, L"text", mFbDialog->BodyStringArray[Index]);
|
|
Status = CompareHiiValue (&mFbDialog->BodyHiiValueArray[Index], &mFbDialog->ConfirmHiiValue, &Result);
|
|
if (!EFI_ERROR (Status) && Result == 0) {
|
|
if (gFB->CurrentP != NULL) {
|
|
UiSetAttribute (Control, L"padding", L"0,45,0,45");
|
|
}
|
|
Control = UiFindChildByName (CreatedControl, L"OptionSelectedIcon");
|
|
if (Control != NULL) {
|
|
UiSetAttribute (Control, L"visibility", L"true");
|
|
}
|
|
|
|
LIST_VIEW_CLASS (Layout)->SetSelection (
|
|
(UI_LIST_VIEW *)Layout,
|
|
(INT32)Index,
|
|
TRUE
|
|
);
|
|
}
|
|
}
|
|
|
|
if (gFB->CurrentP == NULL && CreatedControl != NULL) {
|
|
//
|
|
// calculate maximum width of option
|
|
//
|
|
MaxWidth = 360;
|
|
Control = UiFindChildByName (CreatedControl, L"Option");
|
|
Padding = GetControlPaddingWidth (Control);
|
|
Border = GetControlBorderWidth (Control);
|
|
Hdc = CreateCompatibleDC(NULL);
|
|
Hdc->font->FontSize = GetControlFontSize (Control);
|
|
for (Index = 0; Index < mFbDialog->BodyStringCount; Index++) {
|
|
GetTextExtentPoint32 (Hdc, mFbDialog->BodyStringArray[Index], -1, &Size);
|
|
MaxWidth = MAX (MaxWidth, Size.cx + Padding + Border);
|
|
}
|
|
DeleteDC (Hdc);
|
|
UnicodeSPrint (Str, sizeof (Str), L"%d", MaxWidth);
|
|
UiSetAttribute (Layout, L"width", Str);
|
|
|
|
//
|
|
// calculate content width for estimate dialog title size correctly.
|
|
//
|
|
Content = UiFindChildByName (This, L"Content");
|
|
ContentSize.cx = 9999;
|
|
ContentSize.cy = WRAP_CONTENT;
|
|
ContentSize = CONTROL_CLASS (Content)->EstimateSize (Content, ContentSize);
|
|
UnicodeSPrint (Str, sizeof (Str), L"%d", ContentSize.cx - 60);
|
|
UiSetAttribute (Content, L"width", Str);
|
|
}
|
|
|
|
SetFocus (Layout->Wnd);
|
|
break;
|
|
|
|
case WM_HOTKEY:
|
|
if (HIWORD(LParam) == VK_ESCAPE) {
|
|
SendShutDNotify ();
|
|
return 0;
|
|
}
|
|
return 1;
|
|
|
|
case WM_DESTROY:
|
|
FreeDialogEvent (&mFbDialog);
|
|
return (BOOLEAN) PARENT_CLASS_WNDPROC (CURRENT_CLASS, Wnd, Msg, WParam, LParam);
|
|
|
|
default:
|
|
return (BOOLEAN) PARENT_CLASS_WNDPROC (CURRENT_CLASS, Wnd, Msg, WParam, LParam);
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
H2O_ONE_OF_INPUT_DIALOG_CLASS *
|
|
EFIAPI
|
|
GetH2OOneOfInputDialogClass (
|
|
VOID
|
|
)
|
|
{
|
|
if (CURRENT_CLASS != NULL) {
|
|
return CURRENT_CLASS;
|
|
}
|
|
|
|
InitUiClass ((UI_CONTROL_CLASS **)&CURRENT_CLASS, sizeof (*CURRENT_CLASS), L"H2OOneOfInputDialog", (UI_CONTROL_CLASS *)GetDialogClass());
|
|
if (CURRENT_CLASS == NULL) {
|
|
return NULL;
|
|
}
|
|
((UI_CONTROL_CLASS *)CURRENT_CLASS)->WndProc = H2OOneOfInputProc;
|
|
|
|
return CURRENT_CLASS;
|
|
}
|
|
|