1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00

cellOskDialogLoadAsync fix

Takes into account text limit and initial text
This commit is contained in:
RipleyTom 2017-08-21 01:10:28 +02:00 committed by Ivan
parent 86ef07b166
commit 5681801b85
4 changed files with 21 additions and 12 deletions

View File

@ -83,7 +83,7 @@ public:
virtual ~MsgDialogBase();
virtual void Create(const std::string& msg) = 0;
virtual void CreateOsk(const std::string& msg, char16_t* osk_text) = 0;
virtual void CreateOsk(const std::string& msg, char16_t* osk_text, u32 charlimit) = 0;
virtual void ProgressBarSetMsg(u32 progressBarIndex, const std::string& msg) = 0;
virtual void ProgressBarReset(u32 progressBarIndex) = 0;
virtual void ProgressBarInc(u32 progressBarIndex, u32 delta) = 0;

View File

@ -14,14 +14,21 @@ s32 cellOskDialogLoadAsync(u32 container, vm::ptr<CellOskDialogParam> dialogPara
{
cellOskDialog.warning("cellOskDialogLoadAsync(container=0x%x, dialogParam=*0x%x, inputFieldInfo=*0x%x)", container, dialogParam, inputFieldInfo);
u32 maxLength = (inputFieldInfo->limit_length >= 512) ? 511 : (u32)inputFieldInfo->limit_length;
std::memset(s_osk_text, 0, sizeof(s_osk_text));
if (inputFieldInfo->init_text.addr() != 0)
for (u32 i = 0; (i < maxLength) && (inputFieldInfo->init_text[i] != 0); i++)
s_osk_text[i] = inputFieldInfo->init_text[i];
const auto osk = Emu.GetCallbacks().get_msg_dialog();
bool result = false;
osk->on_close = [&](s32 status)
{
sysutil_send_system_cmd(status == CELL_MSGDIALOG_BUTTON_OK ? CELL_SYSUTIL_OSKDIALOG_FINISHED : CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED, 0);
if (status != CELL_MSGDIALOG_BUTTON_OK) sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED, 0);
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_FINISHED, 0);
result = true;
};
@ -32,7 +39,7 @@ s32 cellOskDialogLoadAsync(u32 container, vm::ptr<CellOskDialogParam> dialogPara
Emu.CallAfter([&]()
{
osk->CreateOsk("On Screen Keyboard", s_osk_text);
osk->CreateOsk("On Screen Keyboard", s_osk_text, maxLength);
});
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_LOADED, 0);

View File

@ -199,7 +199,7 @@ void msg_dialog_frame::Create(const std::string& msg)
#endif
}
void msg_dialog_frame::CreateOsk(const std::string& msg, char16_t* osk_text)
void msg_dialog_frame::CreateOsk(const std::string& msg, char16_t* osk_text, u32 charlimit)
{
static const auto& lineEditWidth = []() {return QLabel("This is the very length of the lineedit due to hidpi reasons.").sizeHint().width(); };
@ -220,6 +220,8 @@ void msg_dialog_frame::CreateOsk(const std::string& msg, char16_t* osk_text)
//Text Input
QLineEdit* input = new QLineEdit(osk_dialog);
input->setFixedWidth(lineEditWidth());
input->setMaxLength(charlimit);
input->setText(QString::fromStdU16String(std::u16string(osk_text_return)));
input->setFocus();
//Ok Button
@ -239,14 +241,14 @@ void msg_dialog_frame::CreateOsk(const std::string& msg, char16_t* osk_text)
osk_dialog->setLayout(layout);
//Events
connect(input, &QLineEdit::textChanged, [=] {
std::memset(osk_text_return, 0, 512 * sizeof(char16_t)); // TODO: use max length instead of default 512
std::memcpy(osk_text_return, reinterpret_cast<const char16_t*>(input->text().constData()), input->text().size() * sizeof(char16_t));
on_osk_input_entered();
});
connect(input, &QLineEdit::returnPressed, [=] { on_close(CELL_MSGDIALOG_BUTTON_OK); osk_dialog->accept(); });
connect(button_ok, &QAbstractButton::clicked, [=] { on_close(CELL_MSGDIALOG_BUTTON_OK); osk_dialog->accept(); });
connect(input, &QLineEdit::textChanged, [=] { on_osk_input_entered(); });
connect(input, &QLineEdit::returnPressed, osk_dialog, &QDialog::accept);
connect(button_ok, &QAbstractButton::clicked, osk_dialog, &QDialog::accept);
connect(osk_dialog, &QDialog::rejected, [=] {if (!type.disable_cancel) { on_close(CELL_MSGDIALOG_BUTTON_ESCAPE); }});
connect(osk_dialog, &QDialog::accepted, [=] {
std::memcpy(osk_text_return, reinterpret_cast<const char16_t*>(input->text().constData()), ((input->text()).size() + 1) * sizeof(char16_t));
on_close(CELL_MSGDIALOG_BUTTON_OK);
});
//Fix size
osk_dialog->layout()->setSizeConstraint(QLayout::SetFixedSize);

View File

@ -54,7 +54,7 @@ public:
msg_dialog_frame(QWindow* taskbarTarget);
~msg_dialog_frame();
virtual void Create(const std::string& msg) override;
virtual void CreateOsk(const std::string& msg, char16_t* osk_text) override;
virtual void CreateOsk(const std::string& msg, char16_t* osk_text, u32 charlimit) override;
virtual void ProgressBarSetMsg(u32 progressBarIndex, const std::string& msg) override;
virtual void ProgressBarReset(u32 progressBarIndex) override;
virtual void ProgressBarInc(u32 progressBarIndex, u32 delta) override;