2017-08-31 15:13:18 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2013-07-29 04:01:49 +00:00
|
|
|
#include "Common/CommonWindows.h"
|
|
|
|
#include "Windows/InputBox.h"
|
|
|
|
#include "Windows/resource.h"
|
2013-08-26 17:00:16 +00:00
|
|
|
#include "util/text/utf8.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-08-26 17:00:16 +00:00
|
|
|
static std::wstring textBoxContents;
|
|
|
|
static std::wstring out;
|
|
|
|
static std::wstring windowTitle;
|
2013-08-17 19:20:24 +00:00
|
|
|
static bool defaultSelected;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
static INT_PTR CALLBACK InputBoxFunc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (message) {
|
|
|
|
case WM_INITDIALOG:
|
2013-08-26 17:00:16 +00:00
|
|
|
SetWindowText(GetDlgItem(hDlg, IDC_INPUTBOX), textBoxContents.c_str());
|
|
|
|
SetWindowText(hDlg, windowTitle.c_str());
|
2013-08-17 19:20:24 +00:00
|
|
|
if (defaultSelected == false) PostMessage(GetDlgItem(hDlg,IDC_INPUTBOX),EM_SETSEL,-1,-1);
|
2012-11-01 15:19:01 +00:00
|
|
|
return TRUE;
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case IDOK:
|
2013-08-26 17:00:16 +00:00
|
|
|
{
|
|
|
|
wchar_t temp[256];
|
|
|
|
GetWindowText(GetDlgItem(hDlg, IDC_INPUTBOX), temp, 255);
|
|
|
|
out = temp;
|
|
|
|
}
|
|
|
|
EndDialog(hDlg, IDOK);
|
2012-11-01 15:19:01 +00:00
|
|
|
return TRUE;
|
|
|
|
case IDCANCEL:
|
2013-08-26 17:00:16 +00:00
|
|
|
EndDialog(hDlg, IDCANCEL);
|
2012-11-01 15:19:01 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <bool hex>
|
|
|
|
void InputBoxFunc()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-26 17:00:16 +00:00
|
|
|
bool InputBox_GetString(HINSTANCE hInst, HWND hParent, const wchar_t *title, const std::string &defaultValue, std::string &outvalue, bool selected)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-08-17 19:20:24 +00:00
|
|
|
defaultSelected = selected;
|
2013-08-26 17:00:16 +00:00
|
|
|
if (defaultValue.size() < 255)
|
|
|
|
textBoxContents = ConvertUTF8ToWString(defaultValue);
|
2012-11-01 15:19:01 +00:00
|
|
|
else
|
2013-08-26 17:00:16 +00:00
|
|
|
textBoxContents = L"";
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-08-17 19:20:24 +00:00
|
|
|
if (title != NULL)
|
2013-08-26 17:00:16 +00:00
|
|
|
windowTitle = title;
|
2013-08-17 19:20:24 +00:00
|
|
|
else
|
2013-08-26 17:00:16 +00:00
|
|
|
windowTitle = L"";
|
2013-08-17 19:20:24 +00:00
|
|
|
|
2013-08-26 17:00:16 +00:00
|
|
|
if (IDOK == DialogBox(hInst, (LPCWSTR)IDD_INPUTBOX, hParent, InputBoxFunc)) {
|
|
|
|
outvalue = ConvertWStringToUTF8(out);
|
2012-11-01 15:19:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-26 17:00:16 +00:00
|
|
|
bool InputBox_GetString(HINSTANCE hInst, HWND hParent, const wchar_t *title, const std::string &defaultValue, std::string &outvalue)
|
2013-08-06 02:45:51 +00:00
|
|
|
{
|
2013-08-26 17:00:16 +00:00
|
|
|
const wchar_t *defaultTitle = L"Input value";
|
2013-08-17 19:20:24 +00:00
|
|
|
defaultSelected = true;
|
2013-08-06 03:17:26 +00:00
|
|
|
|
2013-08-26 17:00:16 +00:00
|
|
|
textBoxContents = ConvertUTF8ToWString(defaultValue);
|
2013-08-06 03:17:26 +00:00
|
|
|
|
2013-08-26 17:00:16 +00:00
|
|
|
if (title && wcslen(title) <= 0)
|
|
|
|
windowTitle = defaultTitle;
|
|
|
|
else if (title && wcslen(title) < 255)
|
|
|
|
windowTitle = title;
|
2013-08-06 03:17:26 +00:00
|
|
|
else
|
2013-08-26 17:00:16 +00:00
|
|
|
windowTitle = defaultTitle;
|
2013-08-06 03:17:26 +00:00
|
|
|
|
2013-08-26 17:00:16 +00:00
|
|
|
if (IDOK == DialogBox(hInst, (LPCWSTR)IDD_INPUTBOX, hParent, InputBoxFunc)) {
|
|
|
|
outvalue = ConvertWStringToUTF8(out);
|
2013-08-06 02:45:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-27 11:20:41 +00:00
|
|
|
bool InputBox_GetWString(HINSTANCE hInst, HWND hParent, const wchar_t *title, const std::wstring &defaultValue, std::wstring &outvalue)
|
|
|
|
{
|
|
|
|
const wchar_t *defaultTitle = L"Input value";
|
|
|
|
defaultSelected = true;
|
|
|
|
|
|
|
|
textBoxContents = defaultValue;
|
|
|
|
|
|
|
|
if (title && wcslen(title) <= 0)
|
|
|
|
windowTitle = defaultTitle;
|
|
|
|
else if (title && wcslen(title) < 255)
|
|
|
|
windowTitle = title;
|
|
|
|
else
|
|
|
|
windowTitle = defaultTitle;
|
|
|
|
|
|
|
|
if (IDOK == DialogBox(hInst, (LPCWSTR)IDD_INPUTBOX, hParent, InputBoxFunc)) {
|
|
|
|
outvalue = out;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-24 17:18:48 +00:00
|
|
|
bool InputBox_GetHex(HINSTANCE hInst, HWND hParent, const wchar_t* title, u32 defaultvalue, u32& outvalue)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-08-26 17:00:16 +00:00
|
|
|
wchar_t temp[256];
|
2020-05-24 17:18:48 +00:00
|
|
|
wsprintf(temp, L"%08x", defaultvalue);
|
2013-08-26 17:00:16 +00:00
|
|
|
textBoxContents = temp;
|
|
|
|
|
|
|
|
INT_PTR value = DialogBox(hInst, (LPCWSTR)IDD_INPUTBOX, hParent, InputBoxFunc);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
if (value == IDOK)
|
|
|
|
{
|
2013-10-06 22:02:23 +00:00
|
|
|
if (swscanf(out.c_str(), L"0x%08x", &outvalue) == 1)
|
|
|
|
return true;
|
|
|
|
if (swscanf(out.c_str(), L"%08x", &outvalue) == 1)
|
|
|
|
return true;
|
|
|
|
return false;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
2020-05-24 17:18:48 +00:00
|
|
|
else
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-08-26 17:00:16 +00:00
|
|
|
outvalue = 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-05-24 17:18:48 +00:00
|
|
|
}
|