Skip to content

Commit

Permalink
Windows: Fix EFI configuration editor various issues
Browse files Browse the repository at this point in the history
We always using Unicode functions to interact with UI. We convert UTF8 string to UTF16 and vis-versa.
Overwrite input string instead of using resize that caused old test to remain.
Fix case of readOnly by using correct message.
change position of OK/cancel button to match other dialogs.
Activate translation on this dialog.
  • Loading branch information
idrassi committed Sep 18, 2024
1 parent aaf42a8 commit 68e2e01
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Common/Common.rc
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ IDD_TEXT_EDIT_DLG DIALOGEX 0, 0, 372, 220
STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
PUSHBUTTON "OK",IDOK,306,201,58,14
PUSHBUTTON "OK",IDOK,244,201,58,14
CONTROL "",IDC_INFO_BOX_TEXT,"RichEdit20W",ES_MULTILINE | ES_WANTRETURN | ES_NUMBER | WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP,5,6,361,188
DEFPUSHBUTTON "Cancel",IDCANCEL,240,201,58,14
DEFPUSHBUTTON "Cancel",IDCANCEL,308,201,58,14
END


Expand Down
50 changes: 45 additions & 5 deletions src/Common/Dlgcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -4165,6 +4165,7 @@ BOOL CALLBACK TextEditDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
case WM_INITDIALOG:
{
prm = (TEXT_INFO_DIALOG_PARAM_PTR)lParam;
LocalizeDialog (hwndDlg, NULL);
// increase size limit of rich edit control
SendMessage(GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), EM_EXLIMITTEXT, 0, -1);

Expand All @@ -4175,9 +4176,43 @@ BOOL CALLBACK TextEditDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
if (prm->ReadOnly)
{
// switch rich edit control to ReadOnly
SendMessage(GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), ES_READONLY, TRUE, 0);
SendMessage(GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), EM_SETREADONLY , TRUE, 0);
// hide cancel button
ShowWindow(GetDlgItem(hwndDlg, IDCANCEL), SW_HIDE);
HWND hwndCancel = GetDlgItem(hwndDlg, IDCANCEL);
ShowWindow(hwndCancel, SW_HIDE);

// Reposition OK button to Cancel button's position
HWND hwndOK = GetDlgItem(hwndDlg, IDOK);
if (hwndOK && hwndCancel)
{
// Get Cancel button's position in screen coordinates
RECT rectCancel;
if (GetWindowRect(hwndCancel, &rectCancel))
{
// Convert Cancel button's position to dialog's client coordinates
POINT ptCancel = { rectCancel.left, rectCancel.top };
ScreenToClient(hwndDlg, &ptCancel);

// Get OK button's current size
RECT rectOK;
if (GetWindowRect(hwndOK, &rectOK))
{
int width = rectOK.right - rectOK.left;
int height = rectOK.bottom - rectOK.top;

// Move OK button to Cancel button's position
SetWindowPos(
hwndOK,
NULL,
ptCancel.x,
ptCancel.y,
width,
height,
SWP_NOZORDER | SWP_NOACTIVATE
);
}
}
}
}

SendMessage (hwndDlg, TC_APPMSG_LOAD_TEXT_BOX_CONTENT, 0, 0);
Expand All @@ -4189,8 +4224,12 @@ BOOL CALLBACK TextEditDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
{
if (!prm->ReadOnly)
{
prm->Text.resize(GetWindowTextLengthA (GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT)) + 1);
GetWindowTextA (GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), &(prm->Text)[0], (int) prm->Text.size());
// read content of the text box as UTF16 and then convert it to UTF8
HWND hEdit = GetDlgItem(hwndDlg, IDC_INFO_BOX_TEXT);
int size = GetWindowTextLengthW(hEdit);
std::vector<WCHAR> buffer(size + 1);
GetWindowTextW(hEdit, buffer.data(), size + 1);
prm->Text = WideToUtf8String(buffer.data());
}
NormalCursor ();
EndDialog (hwndDlg, IDOK);
Expand All @@ -4207,7 +4246,8 @@ BOOL CALLBACK TextEditDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa

case TC_APPMSG_LOAD_TEXT_BOX_CONTENT:
{
SetWindowTextA (GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), prm->Text.c_str());
// convert prm->Text to UTF16 using Utf8StringToWide
SetWindowTextW(GetDlgItem(hwndDlg, IDC_INFO_BOX_TEXT), Utf8StringToWide(prm->Text).c_str());
}
return 0;

Expand Down

0 comments on commit 68e2e01

Please sign in to comment.