Add a new "System" request for a username-password dialog box

This commit is contained in:
Henrik Rydgård committed 2023-06-22 08:58:29 +02:00
1 parent d35c17229c
commit 2708f0b93e
7 files changed
+93 -7

No files matched your search

+8 -2
View File
@@ -72,12 +72,13 @@ const char *RequestTypeAsString(SystemRequestType type);
extern RequestManager g_requestManager;
// Wrappers for easy requests.
// NOTE: Semantics have changed - this no longer calls the callback on cancellation.
// NOTE: Semantics have changed - this no longer calls the callback on cancellation, instead you
// can specify a different callback for that.
inline void System_InputBoxGetString(const std::string &title, const std::string &defaultValue, RequestCallback callback, RequestFailedCallback failedCallback = nullptr) {
g_requestManager.MakeSystemRequest(SystemRequestType::INPUT_TEXT_MODAL, callback, failedCallback, title, defaultValue, 0);
}
// This one will pop up a special image brwoser if available. You can also pick
// This one will pop up a special image browser if available. You can also pick
// images with the file browser below.
inline void System_BrowseForImage(const std::string &title, RequestCallback callback, RequestFailedCallback failedCallback = nullptr) {
g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_IMAGE, callback, failedCallback, title, "", 0);
@@ -99,6 +100,11 @@ inline void System_BrowseForFolder(const std::string &title, RequestCallback cal
g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_FOLDER, callback, failedCallback, title, "", 0);
}
// The returned string is username + '\n' + password.
inline void System_AskUsernamePassword(const std::string &title, RequestCallback callback, RequestFailedCallback failedCallback = nullptr) {
g_requestManager.MakeSystemRequest(SystemRequestType::ASK_USERNAME_PASSWORD, callback, failedCallback, title, "", 0);
}
inline void System_CopyStringToClipboard(const std::string &string) {
g_requestManager.MakeSystemRequest(SystemRequestType::COPY_TO_CLIPBOARD, nullptr, nullptr, string, "", 0);
}
+2
View File
@@ -58,6 +58,7 @@ void System_LaunchUrl(LaunchUrlType urlType, const char *url);
enum class SystemRequestType {
INPUT_TEXT_MODAL,
ASK_USERNAME_PASSWORD,
BROWSE_FOR_IMAGE,
BROWSE_FOR_FILE,
BROWSE_FOR_FOLDER,
@@ -129,6 +130,7 @@ enum SystemProperty {
SYSPROP_HAS_BACK_BUTTON,
SYSPROP_HAS_KEYBOARD,
SYSPROP_HAS_OPEN_DIRECTORY,
SYSPROP_HAS_LOGIN_DIALOG,
SYSPROP_CAN_CREATE_SHORTCUT,
+48
View File
@@ -5,9 +5,12 @@
#include "Common/Data/Encoding/Utf8.h"
static std::wstring textBoxContents;
static std::wstring passwordContents;
static std::wstring out;
static std::wstring windowTitle;
static bool defaultSelected;
static std::string g_userName;
static std::string g_passWord;
static INT_PTR CALLBACK InputBoxFunc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
@@ -138,3 +141,48 @@ bool InputBox_GetHex(HINSTANCE hInst, HWND hParent, const wchar_t* title, u32 de
return false;
}
}
static INT_PTR CALLBACK UserPasswordBoxFunc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_INITDIALOG:
SetWindowText(GetDlgItem(hDlg, IDC_INPUTBOX), L"");
SetWindowText(GetDlgItem(hDlg, IDC_PASSWORDBOX), L"");
SetWindowText(hDlg, windowTitle.c_str());
PostMessage(GetDlgItem(hDlg, IDC_INPUTBOX), EM_SETSEL, -1, -1);
PostMessage(GetDlgItem(hDlg, IDC_PASSWORDBOX), EM_SETSEL, -1, -1);
return TRUE;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
{
wchar_t temp[256];
GetWindowText(GetDlgItem(hDlg, IDC_INPUTBOX), temp, 255);
g_userName = ConvertWStringToUTF8(temp);
GetWindowText(GetDlgItem(hDlg, IDC_PASSWORDBOX), temp, 255);
g_passWord = ConvertWStringToUTF8(temp);
}
EndDialog(hDlg, IDOK);
return TRUE;
case IDCANCEL:
EndDialog(hDlg, IDCANCEL);
return TRUE;
}
default:
return FALSE;
}
}
bool UserPasswordBox_GetStrings(HINSTANCE hInst, HWND hParent, const wchar_t *title, std::string *username, std::string *password) {
windowTitle = title;
INT_PTR value = DialogBox(hInst, (LPCWSTR)IDD_USERPASSWORDBOX, hParent, UserPasswordBoxFunc);
if (value == IDOK) {
*username = g_userName;
*password = g_passWord;
return true;
} else {
return false;
}
}
+2 -1
View File
@@ -3,9 +3,10 @@
#include <string>
#include "Common/CommonWindows.h"
// All I/O is in UTF-8
bool InputBox_GetString(HINSTANCE hInst, HWND hParent, const wchar_t *title, const std::string &defaultvalue, std::string &outvalue, bool selected);
bool InputBox_GetString(HINSTANCE hInst, HWND hParent, const wchar_t *title, const std::string &defaultvalue, std::string &outvalue);
bool InputBox_GetWString(HINSTANCE hInst, HWND hParent, const wchar_t *title, const std::wstring &defaultvalue, std::wstring &outvalue);
bool InputBox_GetHex(HINSTANCE hInst, HWND hParent, const wchar_t *title, u32 defaultvalue, u32 &outvalue);
bool UserPasswordBox_GetStrings(HINSTANCE hInst, HWND hParent, const wchar_t *title, std::string *username, std::string *password);
+13
View File
@@ -358,6 +358,8 @@ bool System_GetPropertyBool(SystemProperty prop) {
return true;
case SYSPROP_HAS_BACK_BUTTON:
return true;
case SYSPROP_HAS_LOGIN_DIALOG:
return true;
case SYSPROP_APP_GOLD:
#ifdef GOLD
return true;
@@ -498,6 +500,17 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
}
}).detach();
return true;
case SystemRequestType::ASK_USERNAME_PASSWORD:
std::thread([=] {
std::string username;
std::string password;
if (UserPasswordBox_GetStrings(MainWindow::GetHInstance(), MainWindow::GetHWND(), ConvertUTF8ToWString(param1).c_str(), &username, &password)) {
g_requestManager.PostSystemSuccess(requestId, (username + '\n' + password).c_str());
} else {
g_requestManager.PostSystemFailure(requestId);
}
}).detach();
return true;
case SystemRequestType::BROWSE_FOR_IMAGE:
std::thread([=] {
std::string out;
+17 -4
View File
@@ -322,15 +322,28 @@ BEGIN
CONTROL "",IDC_MEMVIEW_STATUS,"msctls_statusbar32",WS_CHILD | WS_VISIBLE,0,286,700,24
END
IDD_INPUTBOX DIALOGEX 0, 0, 163, 55
IDD_INPUTBOX DIALOGEX 0, 0, 223, 55
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Input value"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "Value",IDC_VALUENAME,7,7,89,8
EDITTEXT IDC_INPUTBOX,7,16,149,13,ES_AUTOHSCROLL
DEFPUSHBUTTON "OK",IDOK,51,34,50,14
PUSHBUTTON "Cancel",IDCANCEL,106,34,50,14
EDITTEXT IDC_INPUTBOX,7,16,209,13,ES_AUTOHSCROLL
DEFPUSHBUTTON "OK",IDOK,111,34,50,14
PUSHBUTTON "Cancel",IDCANCEL,166,34,50,14
END
IDD_USERPASSWORDBOX DIALOGEX 0, 0, 223, 95
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Login"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "Username", IDC_VALUENAME, 7, 7, 89, 8
EDITTEXT IDC_INPUTBOX, 7, 17, 209, 13, ES_AUTOHSCROLL
LTEXT "Password", IDC_PASSWORDNAME, 7, 34, 89, 8
EDITTEXT IDC_PASSWORDBOX, 7, 46, 209, 13, ES_AUTOHSCROLL | ES_PASSWORD
DEFPUSHBUTTON "OK", IDOK, 111, 74, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 166, 74, 50, 14
END
IDD_VFPU DIALOGEX 0, 0, 250, 420
+3
View File
@@ -36,6 +36,7 @@
#define ID_DEBUG_RESETSYMBOLTABLE 212
#define IDI_STOP 223
#define IDD_INPUTBOX 226
#define IDD_USERPASSWORDBOX 227
#define IDD_VFPU 231
#define IDD_BREAKPOINT 233
#define ID_FILE_LOAD_DIR 234
@@ -75,10 +76,12 @@
#define IDC_INPUTBOX 1098
#define IDC_MODENORMAL 1099
#define IDC_MODESYMBOLS 1100
#define IDC_PASSWORDBOX 1101
#define IDC_SEARCH_RESULTS 1102
#define IDC_REGIONS 1142
#define IDC_REGLIST 1146
#define IDC_VALUENAME 1148
#define IDC_PASSWORDNAME 1149
#define IDC_SHOWVFPU 1161
#define IDC_BREAKPOINTLIST 1164
#define IDC_DEBUGMEMVIEW 1165