rpcsx/rpcs3/Emu/Cell/Modules/cellOskDialog.cpp

433 lines
13 KiB
C++
Raw Normal View History

#include "stdafx.h"
2017-05-15 13:58:32 +02:00
#include "Emu/System.h"
2018-12-30 02:34:15 +01:00
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "pad_thread.h"
2017-05-15 13:58:32 +02:00
#include "cellSysutil.h"
#include "cellOskDialog.h"
#include "cellMsgDialog.h"
LOG_CHANNEL(cellOskDialog);
template<>
void fmt_class_string<CellOskDialogError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_OSKDIALOG_ERROR_IME_ALREADY_IN_USE);
STR_CASE(CELL_OSKDIALOG_ERROR_GET_SIZE_ERROR);
STR_CASE(CELL_OSKDIALOG_ERROR_UNKNOWN);
STR_CASE(CELL_OSKDIALOG_ERROR_PARAM);
}
return unknown;
});
}
static CellOskDialogInputFieldResult s_osk_input_result;
2017-01-23 19:11:42 +01:00
static char16_t s_osk_text[CELL_OSKDIALOG_STRING_SIZE];
static char16_t s_osk_text_old[CELL_OSKDIALOG_STRING_SIZE];
error_code cellOskDialogLoadAsync(u32 container, vm::ptr<CellOskDialogParam> dialogParam, vm::ptr<CellOskDialogInputFieldInfo> inputFieldInfo)
{
cellOskDialog.warning("cellOskDialogLoadAsync(container=0x%x, dialogParam=*0x%x, inputFieldInfo=*0x%x)", container, dialogParam, inputFieldInfo);
2018-12-30 22:27:37 +01:00
if (!inputFieldInfo || !inputFieldInfo->message || !inputFieldInfo->init_text || inputFieldInfo->limit_length > CELL_OSKDIALOG_STRING_SIZE)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
const auto osk = fxm::import<MsgDialogBase>(Emu.GetCallbacks().get_msg_dialog);
// Can't open another dialog if this one is already open.
if (!osk || osk->state.load() == MsgDialogState::Open)
2018-12-30 22:27:37 +01:00
{
return CELL_SYSUTIL_ERROR_BUSY;
}
2019-01-04 14:05:37 +01:00
// Get max length of the return value
2018-12-30 22:27:37 +01:00
u32 maxLength = (inputFieldInfo->limit_length >= CELL_OSKDIALOG_STRING_SIZE) ? 511 : (u32)inputFieldInfo->limit_length;
2019-01-04 14:05:37 +01:00
// Get init text and prepare return value
s_osk_input_result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK;
2017-01-23 19:11:42 +01:00
std::memset(s_osk_text, 0, sizeof(s_osk_text));
std::memset(s_osk_text_old, 0, sizeof(s_osk_text_old));
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];
s_osk_text_old[i] = inputFieldInfo->init_text[i];
}
}
2019-01-04 14:05:37 +01:00
// Get message to display above the input field
// Guarantees 0 terminated (+1). In praxis only 128 but for now lets display all of it
char16_t message[CELL_OSKDIALOG_STRING_SIZE + 1];
std::memset(message, 0, sizeof(message));
if (inputFieldInfo->message.addr() != 0)
{
for (u32 i = 0; (i < CELL_OSKDIALOG_STRING_SIZE) && (inputFieldInfo->message[i] != 0); i++)
{
message[i] = inputFieldInfo->message[i];
}
}
bool result = false;
2018-12-30 02:34:15 +01:00
osk->on_close = [wptr = std::weak_ptr<MsgDialogBase>(osk)](s32 status)
{
2018-12-30 02:34:15 +01:00
const auto osk = wptr.lock();
if (osk && osk->state.compare_and_swap_test(MsgDialogState::Open, MsgDialogState::Close))
{
fxm::remove<MsgDialogBase>();
}
if (status != CELL_MSGDIALOG_BUTTON_OK)
{
s_osk_input_result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_CANCELED;
if (false/* TODO: check for seperate window */)
{
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED, 0);
}
}
else
{
if (s_osk_text[0] == 0 && false/* TODO: check for seperate window */)
{
cellOskDialog.warning("cellOskDialogLoadAsync: input result is CELL_OSKDIALOG_INPUT_FIELD_RESULT_NO_INPUT_TEXT");
s_osk_input_result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_NO_INPUT_TEXT;
}
}
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_FINISHED, 0);
2018-12-30 02:34:15 +01:00
pad::SetIntercepted(false);
};
2017-03-16 10:34:47 +01:00
osk->on_osk_input_entered = [&]()
{
if (false/* TODO: check for seperate window */)
{
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_INPUT_ENTERED, 0);
}
2017-03-16 10:34:47 +01:00
};
2018-12-30 02:34:15 +01:00
pad::SetIntercepted(true);
Emu.CallAfter([&]()
{
2019-01-04 14:05:37 +01:00
osk->CreateOsk("On Screen Keyboard", message, s_osk_text, maxLength);
2018-12-30 02:34:15 +01:00
result = true;
});
2017-03-16 10:34:47 +01:00
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_LOADED, 0);
while (!result)
{
2017-02-05 15:06:03 +01:00
thread_ctrl::wait_for(1000);
}
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code getText(vm::ptr<CellOskDialogCallbackReturnParam> OutputInfo, bool is_unload)
{
if (!OutputInfo || OutputInfo->numCharsResultString < 0)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
if (is_unload)
{
OutputInfo->result = s_osk_input_result;
}
else
{
if (memcmp(s_osk_text_old, s_osk_text, sizeof(s_osk_text)) == 0)
{
OutputInfo->result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_NO_INPUT_TEXT;
}
else
{
OutputInfo->result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK;
}
}
const bool is_valid = OutputInfo->pResultString && (OutputInfo->result == CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK || (is_unload && OutputInfo->result == CELL_OSKDIALOG_INPUT_FIELD_RESULT_NO_INPUT_TEXT));
for (s32 i = 0; i < sizeof(s_osk_text); i++)
2017-05-15 13:58:32 +02:00
{
s_osk_text_old[i] = s_osk_text[i];
if (is_valid && i < OutputInfo->numCharsResultString)
{
OutputInfo->pResultString[i] = s_osk_text[i];
}
}
2017-03-16 10:34:47 +01:00
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_UNLOADED, 0);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogUnloadAsync(vm::ptr<CellOskDialogCallbackReturnParam> OutputInfo)
{
cellOskDialog.warning("cellOskDialogUnloadAsync(OutputInfo=*0x%x)", OutputInfo);
return getText(OutputInfo, true);
}
error_code cellOskDialogGetSize(vm::ptr<u16> width, vm::ptr<u16> height, u32 /*CellOskDialogType*/ dialogType)
{
cellOskDialog.warning("cellOskDialogGetSize(width=*0x%x, height=*0x%x, dialogType=*0x%x)", width, height, dialogType);
2018-12-30 22:27:37 +01:00
if (!width || !height)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
if (dialogType >= CELL_OSKDIALOG_TYPE_SEPARATE_SINGLELINE_TEXT_WINDOW)
{
*width = 0;
}
else
{
*width = 1;
}
*height = 1;
2018-12-30 22:27:37 +01:00
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogAbort()
{
cellOskDialog.warning("cellOskDialogAbort()");
2018-12-30 02:34:15 +01:00
const auto dlg = fxm::get<MsgDialogBase>();
// Check for open dialog. In this case the dialog is only "Open" if it was not aborted before.
if (!dlg || dlg->state.load() == MsgDialogState::Abort)
2018-12-30 02:34:15 +01:00
{
return CELL_MSGDIALOG_ERROR_DIALOG_NOT_OPENED;
}
// If the dialog has the Open state then it is in use. Only dialogs with the Close state can be aborted.
2018-12-30 02:34:15 +01:00
if (!dlg->state.compare_and_swap_test(MsgDialogState::Open, MsgDialogState::Abort))
{
return CELL_SYSUTIL_ERROR_BUSY;
}
s_osk_input_result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_ABORT;
2018-12-30 02:34:15 +01:00
verify(HERE), fxm::remove<MsgDialogBase>();
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_FINISHED, 0);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogSetDeviceMask(u32 deviceMask)
{
cellOskDialog.todo("cellOskDialogSetDeviceMask(deviceMask=0x%x)", deviceMask);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogSetSeparateWindowOption(vm::ptr<CellOskDialogSeparateWindowOption> windowOption)
{
cellOskDialog.todo("cellOskDialogSetSeparateWindowOption(windowOption=*0x%x)", windowOption);
// TODO: when games set the option to use seperate windows we will have to handle input signals and cancel signals
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogSetInitialInputDevice(vm::ptr<CellOskDialogInputDevice> inputDevice)
{
cellOskDialog.todo("cellOskDialogSetInitialInputDevice(inputDevice=*0x%x)", inputDevice);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogSetInitialKeyLayout(vm::ptr<CellOskDialogInitialKeyLayout> initialKeyLayout)
{
cellOskDialog.todo("cellOskDialogSetInitialKeyLayout(initialKeyLayout=*0x%x)", initialKeyLayout);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogDisableDimmer()
{
cellOskDialog.todo("cellOskDialogDisableDimmer()");
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogSetKeyLayoutOption(u32 option)
{
cellOskDialog.todo("cellOskDialogSetKeyLayoutOption(option=0x%x)", option);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogAddSupportLanguage(u32 supportLanguage)
{
cellOskDialog.todo("cellOskDialogAddSupportLanguage(supportLanguage=0x%x)", supportLanguage);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogSetLayoutMode(s32 layoutMode)
{
cellOskDialog.todo("cellOskDialogSetLayoutMode(layoutMode=%d)", layoutMode);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogGetInputText(vm::ptr<CellOskDialogCallbackReturnParam> OutputInfo)
{
cellOskDialog.warning("cellOskDialogGetInputText(OutputInfo=*0x%x)", OutputInfo);
return getText(OutputInfo, false);
}
error_code cellOskDialogExtInputDeviceUnlock()
{
cellOskDialog.todo("cellOskDialogExtInputDeviceUnlock()");
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtRegisterKeyboardEventHookCallback(u16 hookEventMode, vm::ptr<cellOskDialogHardwareKeyboardEventHookCallback> pCallback)
{
2017-01-26 15:53:07 +01:00
cellOskDialog.todo("cellOskDialogExtRegisterKeyboardEventHookCallback(hookEventMode=%u, pCallback=*0x%x)", hookEventMode, pCallback);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtRegisterKeyboardEventHookCallbackEx(u16 hookEventMode, vm::ptr<cellOskDialogHardwareKeyboardEventHookCallback> pCallback)
{
cellOskDialog.todo("cellOskDialogExtRegisterKeyboardEventHookCallbackEx(hookEventMode=%u, pCallback=*0x%x)", hookEventMode, pCallback);
return CELL_OK;
}
error_code cellOskDialogExtAddJapaneseOptionDictionary(vm::cpptr<char> filePath)
{
2017-01-26 15:53:07 +01:00
cellOskDialog.todo("cellOskDialogExtAddJapaneseOptionDictionary(filePath=**0x%0x)", filePath);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtEnableClipboard()
{
cellOskDialog.todo("cellOskDialogExtEnableClipboard()");
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtSendFinishMessage(s32 /*CellOskDialogFinishReason*/ finishReason)
{
2017-01-26 15:53:07 +01:00
cellOskDialog.todo("cellOskDialogExtSendFinishMessage(finishReason=%d)", finishReason);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtAddOptionDictionary(vm::cptr<CellOskDialogImeDictionaryInfo> dictionaryInfo)
{
cellOskDialog.todo("cellOskDialogExtAddOptionDictionary(dictionaryInfo=*0x%x)", dictionaryInfo);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtSetInitialScale(f32 initialScale)
{
2017-01-26 15:53:07 +01:00
cellOskDialog.todo("cellOskDialogExtSetInitialScale(initialScale=%f)", initialScale);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtInputDeviceLock()
{
cellOskDialog.todo("cellOskDialogExtInputDeviceLock()");
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtSetBaseColor(f32 red, f32 blue, f32 green, f32 alpha)
{
2017-01-26 15:53:07 +01:00
cellOskDialog.warning("cellOskDialogExtSetBaseColor(red=%f, blue=%f, green=%f, alpha=%f)", red, blue, green, alpha);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtRegisterConfirmWordFilterCallback(vm::ptr<cellOskDialogConfirmWordFilterCallback> pCallback)
{
2017-01-26 15:53:07 +01:00
cellOskDialog.todo("cellOskDialogExtRegisterConfirmWordFilterCallback(pCallback=*0x%x)", pCallback);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtUpdateInputText()
{
2017-01-26 15:53:07 +01:00
cellOskDialog.todo("cellOskDialogExtUpdateInputText()");
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtDisableHalfByteKana()
{
2017-01-26 15:53:07 +01:00
cellOskDialog.todo("cellOskDialogExtDisableHalfByteKana()");
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtSetPointerEnable(b8 enable)
{
cellOskDialog.todo("cellOskDialogExtSetPointerEnable(enable=%d)", enable);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtUpdatePointerDisplayPos(/*const CellOskDialogPoint pos*/)
{
2018-12-30 02:34:15 +01:00
cellOskDialog.todo("cellOskDialogExtUpdatePointerDisplayPos(posX=%f, posY=%f)"/*, pos.x, pos.y*/);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtEnableHalfByteKana()
{
cellOskDialog.todo("cellOskDialogExtEnableHalfByteKana()");
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
error_code cellOskDialogExtRegisterForceFinishCallback(vm::ptr<cellOskDialogForceFinishCallback> pCallback)
{
2017-01-26 15:53:07 +01:00
cellOskDialog.todo("cellOskDialogExtRegisterForceFinishCallback(pCallback=*0x%x)", pCallback);
2017-05-15 13:58:32 +02:00
return CELL_OK;
}
void cellSysutil_OskDialog_init()
{
REG_FUNC(cellSysutil, cellOskDialogLoadAsync);
REG_FUNC(cellSysutil, cellOskDialogUnloadAsync);
REG_FUNC(cellSysutil, cellOskDialogGetSize);
REG_FUNC(cellSysutil, cellOskDialogAbort);
REG_FUNC(cellSysutil, cellOskDialogSetDeviceMask);
REG_FUNC(cellSysutil, cellOskDialogSetSeparateWindowOption);
REG_FUNC(cellSysutil, cellOskDialogSetInitialInputDevice);
REG_FUNC(cellSysutil, cellOskDialogSetInitialKeyLayout);
REG_FUNC(cellSysutil, cellOskDialogDisableDimmer);
REG_FUNC(cellSysutil, cellOskDialogSetKeyLayoutOption);
REG_FUNC(cellSysutil, cellOskDialogAddSupportLanguage);
REG_FUNC(cellSysutil, cellOskDialogSetLayoutMode);
REG_FUNC(cellSysutil, cellOskDialogGetInputText);
}
2016-03-21 20:43:03 +01:00
DECLARE(ppu_module_manager::cellOskDialog)("cellOskExtUtility", []()
{
REG_FUNC(cellOskExtUtility, cellOskDialogExtInputDeviceUnlock);
REG_FUNC(cellOskExtUtility, cellOskDialogExtRegisterKeyboardEventHookCallback);
REG_FUNC(cellOskExtUtility, cellOskDialogExtRegisterKeyboardEventHookCallbackEx);
2016-03-21 20:43:03 +01:00
REG_FUNC(cellOskExtUtility, cellOskDialogExtAddJapaneseOptionDictionary);
REG_FUNC(cellOskExtUtility, cellOskDialogExtEnableClipboard);
REG_FUNC(cellOskExtUtility, cellOskDialogExtSendFinishMessage);
REG_FUNC(cellOskExtUtility, cellOskDialogExtAddOptionDictionary);
REG_FUNC(cellOskExtUtility, cellOskDialogExtSetInitialScale);
REG_FUNC(cellOskExtUtility, cellOskDialogExtInputDeviceLock);
REG_FUNC(cellOskExtUtility, cellOskDialogExtSetBaseColor);
REG_FUNC(cellOskExtUtility, cellOskDialogExtRegisterConfirmWordFilterCallback);
REG_FUNC(cellOskExtUtility, cellOskDialogExtUpdateInputText);
REG_FUNC(cellOskExtUtility, cellOskDialogExtDisableHalfByteKana);
REG_FUNC(cellOskExtUtility, cellOskDialogExtSetPointerEnable);
REG_FUNC(cellOskExtUtility, cellOskDialogExtUpdatePointerDisplayPos);
REG_FUNC(cellOskExtUtility, cellOskDialogExtEnableHalfByteKana);
REG_FUNC(cellOskExtUtility, cellOskDialogExtRegisterForceFinishCallback);
});