Compare commits

...

5 Commits

6 changed files with 663 additions and 83 deletions

View File

@@ -70,18 +70,18 @@ ziU32 Zi8MatchPUDdata_ZHS(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar*
return 0;
}
if (language == 1) {
length &= 0x7F;
length *= 2;
}
if (continuation == 0) {
table = (ziPudHeader*)ZI_WORK->pudTable[ZI_WORK->pudCount - 1];
index = 0;
section = table->sections;
while (index < table->languageCount && section->language != language) {
index++;
while (index < table->languageCount) {
if (section->language == language) break;
section++;
index++;
}
if (table->languageCount <= index) {
if (!(index < table->languageCount)) {
Zi8LogError(0x4F6, __zi8_work_data);
return 0;
}
@@ -105,7 +105,9 @@ ziU32 Zi8MatchPUDdata_ZHS(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar*
word = entry + 2;
wordSize = ZiGetZHWordSize((ziWChar*)word, entrySize);
} else if (ZI_WORK->unk_0x31E != 0 && complete != 0 && wordSize > length && word[length] == 0x20) goto matchText;
if ((ziS32)length > (ziS32)wordSize || (complete != 0 && wordSize != length) || (complete == 0 && wordSize == length)) goto next;
if ((ziS32)length > (ziS32)wordSize) goto next;
if (complete != 0 && wordSize != length) goto next;
if (complete == 0 && wordSize == length) goto next;
if (language == 1) {
for (index = 0; index < length; index++) {
if (word[index] != ((ziU8*)pattern)[index]) goto next;
@@ -132,8 +134,9 @@ matched:
index = 0;
for (copied = 0; index < (ziS32)wordSize && copied < capacity; copied++) {
((ziU8*)output)[index] = word[index];
((ziU8*)output)[index + 1] = word[index + 1];
index += 2;
index++;
((ziU8*)output)[index] = word[index];
index++;
}
Zi8CopyZHSpelling(word, spelling, spellingCapacity, entrySize, wordSize);
} else {

View File

@@ -9,7 +9,7 @@ ziU32 ZiDAWGGetChild(ziU32 node) {
ziS32 offset;
base = node;
header = nodeHeaderTable[*(ziU8*)node >> 4];
header = (ziU16)nodeHeaderTable[*(ziU8*)node >> 4];
if (((ziU32)header & 1) == 0) {
node = 0;
} else {
@@ -23,7 +23,7 @@ ziU32 ZiDAWGGetChild(ziU32 node) {
if (((ziU32)header & 2) != 0) {
if ((*(ziU8*)node & 0x80) != 0) {
offset = (*(ziU8*)node & 0x7f) * 0x10000 + ((ziU32)*((ziU8*)node + 1) & 0xffff) * 0x100 + 0x8000;
offset += *((ziU8*)node + 2);
offset = *((ziU8*)node + 2) + offset;
} else {
offset = ((ziU32)*(ziU8*)node & 0xffff) * 0x100;
offset += (ziU32)*((ziU8*)node + 1);
@@ -44,16 +44,17 @@ ziU32 ZiDAWGGetChild(ziU32 node) {
ziU8* ZiDAWGGetSibling(ziU8* node) {
ziU16 header;
ziU8* cursor = node;
ziU8* base;
ziS32 depth;
ziS32 offset;
depth = 0;
offset = 0;
header = nodeHeaderTable[node[0] >> 4];
header = (ziU16)nodeHeaderTable[node[0] >> 4];
if ((header & 4) == 0) {
node = 0;
} else {
base = node;
if ((header & 8) != 0) {
if ((node[0] & 0xf) == 0xf) {
node += 2;
@@ -62,39 +63,39 @@ ziU8* ZiDAWGGetSibling(ziU8* node) {
}
if ((header & 2) != 0) {
if ((*node & 0x80) == 0) {
node += 2;
} else {
if ((*node & 0x80) != 0) {
node += 3;
} else {
node += 2;
}
}
if ((*node & 0x80) != 0) {
node += (*node & 0x7f) * 0x10000 + (ziU32)node[1] * 0x100 +
(ziU32)node[2] + 0x8000;
offset = (*node & 0x7f) * 0x10000 + (ziU32)node[1] * 0x100;
offset += 0x8000;
node = offset + (base + (ziU32)node[2]);
} else {
node += (ziU16)*node * 0x100 + (ziU32)node[1];
node = (base + (ziU16)*node * 0x100) + (ziU32)node[1];
}
} else {
cursor = node;
do {
header = nodeHeaderTable[cursor[0] >> 4];
if ((cursor[0] & 0xf) == 0xf) {
cursor += 2;
header = (ziU16)nodeHeaderTable[node[0] >> 4];
if ((node[0] & 0xf) == 0xf) {
node += 2;
offset += 2;
} else {
cursor++;
node++;
offset++;
}
if ((header & 1) != 0) {
if ((header & 2) == 0) {
depth++;
} else if ((*cursor & 0x80) != 0) {
cursor += 3;
} else if ((*node & 0x80) != 0) {
node += 3;
offset += 3;
} else {
cursor += 2;
node += 2;
offset += 2;
}
}
@@ -102,18 +103,17 @@ ziU8* ZiDAWGGetSibling(ziU8* node) {
if ((header & 4) == 0) {
depth--;
} else if ((header & 8) != 0) {
if ((*cursor & 0x80) != 0) {
cursor += 3;
if ((*node & 0x80) != 0) {
node += 3;
offset += 3;
} else {
cursor += 2;
node += 2;
offset += 2;
}
depth--;
}
} while (0 < depth);
node += offset;
} while (depth > 0);
node = base + offset;
}
}
@@ -141,8 +141,8 @@ ziU32 ZiDAWGgetCHARattribute(ziPtr context, ziU32 node, ziPtr __zi8_work_data) {
attribute = key << 24;
attribute |= ((ziU8*)((zi8DawgCtx*)context)->p0C)[key] << 16;
attribute += ((ziU32)((ziU8*)((zi8DawgCtx*)context)->p08)[key * 2] & 0xFFFF) << 8;
attribute += ((ziU8*)((zi8DawgCtx*)context)->p08)[key * 2 + 1];
attribute |= (((ziU32)((ziU8*)((zi8DawgCtx*)context)->p08)[key * 2] & 0xFFFF) << 8) +
((ziU8*)((zi8DawgCtx*)context)->p08)[key * 2 + 1];
Zi8LogError(0x64, __zi8_work_data);
return attribute;
}
@@ -158,58 +158,51 @@ ziU32 ZiDAWGGetGraphInfo(zi8DawgCtx* context, ziU8* entry, ziU16* keys) {
ziS32 result;
ziU32 end;
ziU8 depth;
ziU32 pair;
graph = ZiDAWGGetGraph(context);
result = 0;
pair = (((ziU16)entry[0] << 8) + entry[1]);
if (pair != 0) {
if ((((ziU16)entry[0] << 8) + entry[1]) != 0 ||
(((ziU16)entry[2] << 8) + entry[3]) != 0) {
return 0;
}
pair = (((ziU16)entry[2] << 8) + entry[3]);
if (pair == 0) {
end = (ziU32)(entry + (((ziU16)entry[4] << 8) + entry[5] + 1) * 10);
entry += 10;
depth = 0;
while ((depth < 2) && (*keys != 0)) {
if ((*keys < 0xeff1) || (0xf010 < *keys)) {
break;
}
while (1) {
if (*keys == (ziS32)(entry[3] + ((ziU16)entry[2] << 8))) {
break;
}
entry += (entry[1] + ((ziU16)entry[0] << 8)) * 10 + 10;
if (((ziU32)entry >= end) ||
(*keys == (ziS32)(entry[3] + ((ziU16)entry[2] << 8)))) {
end = (ziU32)(entry + (((ziU16)entry[4] << 8) + entry[5] + 1) * 10);
entry += 10;
depth = 0;
while ((depth < 2) && (*keys != 0)) {
if (!((*keys < 0xeff1) || (0xf010 < *keys))) {
while (((ziU32)entry < end) &&
(*keys != (ziS32)(((ziU16)entry[2] << 8) + entry[3]))) {
if (*keys == (ziS32)(((ziU16)entry[2] << 8) + entry[3])) {
break;
}
entry += (((ziU16)entry[0] << 8) + entry[1]) * 10 + 10;
}
if ((ziU32)entry >= end) {
return 0;
}
result = graph + (ziU32)entry[4] * 0x10000 + ((ziU16)entry[5] << 8) +
entry[6];
((zi8DawgCtx*)context)->unk_0x338 =
graph + (ziU32)entry[7] * 0x10000 + ((ziU16)entry[8] << 8) +
entry[9];
if (((zi8DawgCtx*)context)->unk_0x338 == graph) {
((zi8DawgCtx*)context)->unk_0x338 = 0;
}
if ((entry[1] + ((ziU16)entry[0] << 8)) == 0) {
break;
}
end = (ziU32)(entry + (entry[1] + ((ziU16)entry[0] << 8)) * 10 + 10);
entry += 10;
depth++;
keys++;
} else {
return 0;
}
if ((ziU32)entry >= end) {
return 0;
}
result = (graph + ((ziU32)entry[4] << 16)) +
(((ziU16)entry[5] << 8) + entry[6]);
context->unk_0x338 =
(graph + ((ziU32)entry[7] << 16)) +
(((ziU16)entry[8] << 8) + entry[9]);
if (context->unk_0x338 == graph) {
context->unk_0x338 = 0;
}
if ((((ziU16)entry[0] << 8) + entry[1]) == 0) {
break;
}
end = (ziU32)(entry + (((ziU16)entry[0] << 8) + entry[1]) * 10 + 10);
entry += 10;
depth++;
keys++;
}
return result;
}

View File

@@ -2,6 +2,15 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
__declspec(section ".sdata2") ziU8 ziWordFormat0 = 1;
__declspec(section ".sdata2") ziU8 ziWordFormat1 = 5;
__declspec(section ".sdata2") ziU8 ziWordFormat2 = 0;
__declspec(section ".sdata2") ziU8 ziWordFormat3 = 0;
__declspec(section ".sdata2") ziU8 ziWordFormat4 = 0;
__declspec(section ".sdata2") ziU8 ziWordFormat5 = 0;
__declspec(section ".sdata2") ziU8 ziWordFormat6 = 0;
__declspec(section ".sdata2") ziU8 ziWordFormat7 = 0;
typedef struct ziSearchState {
ziU32 flags;
ziWChar* word;
@@ -26,11 +35,11 @@ ziPtr Zi8GetTableAddress(ziU8, ziU8 ZI_NEED_WORK);
ziU16 Zi8Uni2Ord(ziWChar ZI_NEED_WORK);
ziBool Zi8IsWordW(ziWChar* word, ziU8 language ZI_NEED_WORK) {
int count;
int offset;
ziU8 group;
ziU8 remaining;
ziU16 value;
int count = 0;
int offset = 0;
ziU8 group = 0;
ziU8 remaining = 0;
ziU16 value = 0;
ziWChar* cursor;
ziSearchState search;
ziGetParam request;
@@ -39,9 +48,19 @@ ziBool Zi8IsWordW(ziWChar* word, ziU8 language ZI_NEED_WORK) {
int unmatched;
ziChineseEntry* entry;
ziU8* data;
ziU8 formats[8] = {1, 5, 0, 0, 0, 0, 0, 0};
ziU32 savedFormats = ZI_WORK->unk_0x1410;
ziU8 savedCount = ZI_WORK->unk_0x1418;
ziU8 formats[8];
ziU32 savedFormats;
ziU8 savedCount;
formats[0] = ziWordFormat0;
formats[1] = ziWordFormat1;
formats[2] = ziWordFormat2;
formats[3] = ziWordFormat3;
formats[4] = ziWordFormat4;
formats[5] = ziWordFormat5;
formats[6] = ziWordFormat6;
formats[7] = ziWordFormat7;
savedFormats = ZI_WORK->unk_0x1410;
savedCount = ZI_WORK->unk_0x1418;
search.flags = 0;
search.word = 0;
search.length = 0;

View File

@@ -23,7 +23,7 @@ ziU8 Zi8DetachOEMdata(ziU8 id ZI_NEED_WORK) {
}
ziU8 Zi8MatchOEMdata(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar* word, ziU16 capacity, ziBool complete, ziBool continuation ZI_NEED_WORK) {
ziWChar folded;
ziS32 index;
int index;
ziU32 position;
ziU32 fallback = 0;
if (!continuation) ZI_WORK->oemIdx = 0;

504
src/keyboard/tiKeyboard.cpp Normal file
View File

@@ -0,0 +1,504 @@
#define TI_PCTYPE_SAMPLE_CLASS
#define TI_CELLPHONE_SAMPLE_CLASS
#define TI_INPUTFORM_SAMPLE_CLASS
#define TI_CANDIDATEBOX_SAMPLE_CLASS
#define TI_TOOLBAR_SAMPLE_CLASS
#define TI_PREDICTLANG_SAMPLE_CLASS
#define TI_SIGNWINDOW_SAMPLE_CLASS
#include "keyboard/tiPcKeyboard.h"
#include "keyboard/tiCellPhone.h"
#include "keyboard/tiCandidateBox.h"
#include "keyboard/tiInputForm.h"
#include "keyboard/tiToolBar.h"
#include "keyboard/tiPredictLang.h"
#include "keyboard/tiSignWindow.h"
#include "keyboard/tiManager.h"
#include "keyboard/tiCandidateBox.h"
#include "keyboard/tiPredictLang.h"
#include "keyboard/tiSignWindow.h"
#include <revolution/gx.h>
#include <revolution/sc.h>
#include <new>
namespace textinput {
static EventObserver sDefaultObserver;
Manager::Manager(MEMAllocator* allocator, nw4r::lyt::MultiArcResourceAccessor* multiArc,
textinput::EventObserver* event)
: mpAllocator(allocator), mpMultiArcResourceAccessor(multiArc), mpEditBuffer(NULL), mpHWKeyboard(NULL),
mpPCKeyboard(NULL), mpCellPhoneKeyboard(NULL), mpInputForm(NULL), mpCandidateBox(NULL), mpToolBar(NULL),
mpPredictLanguageDialog(NULL), mpSignWindow(NULL), mpEventObserver(event),
meDestination(DST_JP), meLanguage(JP), mbAspectRatio4x3(true) {
if (event == NULL) {
mpEventObserver = &sDefaultObserver;
}
}
Manager::~Manager() {
if (mpPCKeyboard != NULL) {
mpPCKeyboard->~LayoutByNW4R();
MEMFreeToAllocator(mpAllocator, mpPCKeyboard);
}
if (mpCellPhoneKeyboard != NULL) {
mpCellPhoneKeyboard->~LayoutByNW4R();
MEMFreeToAllocator(mpAllocator, mpCellPhoneKeyboard);
}
if (mpInputForm != NULL) {
mpInputForm->~LayoutByNW4R();
MEMFreeToAllocator(mpAllocator, mpInputForm);
}
if (mpCandidateBox != NULL) {
mpCandidateBox->~LayoutByNW4R();
MEMFreeToAllocator(mpAllocator, mpCandidateBox);
}
if (mpToolBar != NULL) {
mpToolBar->~LayoutByNW4R();
MEMFreeToAllocator(mpAllocator, mpToolBar);
}
if (mpPredictLanguageDialog != NULL) {
mpPredictLanguageDialog->~LayoutByNW4R();
MEMFreeToAllocator(mpAllocator, mpPredictLanguageDialog);
}
if (mpSignWindow != NULL) {
mpSignWindow->~LayoutByNW4R();
MEMFreeToAllocator(mpAllocator, mpSignWindow);
}
if (mpHWKeyboard != NULL) {
mpHWKeyboard->~HWKeyboard();
MEMFreeToAllocator(mpAllocator, mpHWKeyboard);
}
if (mpEditBuffer != NULL) {
mpEditBuffer->~EditBuffer();
MEMFreeToAllocator(mpAllocator, mpEditBuffer);
}
}
keyboard::hwkey::HWKeyboard::~HWKeyboard() {}
void Manager::create(MEMAllocator* allocator) {
mpEditBuffer = createEditBuffer();
mpEditBuffer->inputform::EditBuffer::create(mpAllocator);
mpHWKeyboard = createHWKeyboard();
mpPCKeyboard = (keyboard::pctype::LayoutByNW4R*)createPCTypeKeyboard();
mpPCKeyboard->create(mpAllocator);
mpCellPhoneKeyboard = (keyboard::cellphonetype::LayoutByNW4R*)createCellPhoneTypeKeyboard();
mpCellPhoneKeyboard->create(mpAllocator);
mpInputForm = createInputForm();
mpInputForm->create(mpAllocator, mpEditBuffer);
mpCandidateBox = (candidatebox::LayoutByNW4R*)createCandidateBox();
mpCandidateBox->create(mpAllocator);
mpToolBar = (toolbar::LayoutByNW4R*)createToolBar();
mpToolBar->create(mpAllocator);
mpPredictLanguageDialog = (predictlang::LayoutByNW4R*)createPredictLanguageDialog();
mpPredictLanguageDialog->create(mpAllocator);
mpSignWindow = (keyboard::signwindow::LayoutByNW4R*)createSignWindow();
mpSignWindow->create(mpAllocator);
initAspect();
init();
}
void Manager::initAspect() {
if (SCGetAspectRatio() == SC_ASPECT_RATIO_16x9) {
setLayoutScaleFor16x9();
mbAspectRatio4x3 = false;
} else {
setLayoutScaleFor4x3();
mbAspectRatio4x3 = true;
}
}
void Manager::init() {
input::HKBManager::getInstance().ClearState();
mpInputForm->clearSender();
mpHWKeyboard->setCommandReceiver(mpInputForm);
mpPCKeyboard->setCommandReceiver(mpInputForm);
mpCellPhoneKeyboard->setCommandReceiver(mpInputForm);
mpCandidateBox->setCommandReceiver(mpInputForm);
mpPredictLanguageDialog->setCommandReceiver(mpInputForm);
mpSignWindow->setCommandReceiver(mpInputForm);
mpInputForm->setCandidateBox(mpCandidateBox);
mpPCKeyboard->setPredictLanguageDialog(mpPredictLanguageDialog);
mpPCKeyboard->setSignWindow(mpSignWindow);
mpCellPhoneKeyboard->setPredictLanguageDialog(mpPredictLanguageDialog);
mpCellPhoneKeyboard->setSignWindow(mpSignWindow);
if (mbAspectRatio4x3 == true) {
setLayoutScaleFor4x3();
} else {
setLayoutScaleFor16x9();
}
mpPredictLanguageDialog->setDestination(meDestination);
mpInputForm->setDestination(meDestination);
mpInputForm->setLanguage(meLanguage);
mpPCKeyboard->setLanguage(meLanguage);
mpCellPhoneKeyboard->setLanguage(meLanguage);
mpSignWindow->setLanguage(meLanguage);
mpCandidateBox->setLanguage(meLanguage);
mpToolBar->setLanguage(meLanguage);
mpPredictLanguageDialog->setLanguage(meLanguage);
mpHWKeyboard->setLanguage(meDestination, meLanguage);
mpHWKeyboard->init();
mpPCKeyboard->init();
mpCellPhoneKeyboard->init();
mpInputForm->init();
mpCandidateBox->init();
mpToolBar->init();
mpPredictLanguageDialog->init();
mpSignWindow->init();
setFixedPredictionJP(0, NULL);
setSecretInputMode(false);
}
void Manager::setFixedPredictionJP(int num, const char** predicts) {
static_cast<tistring::WithAtok*>(getInputForm()->getAtokString())->setFixPrediction(num, predicts);
}
void Manager::calc() {
if (mpToolBar->isQwerty()) {
mpPCKeyboard->calc();
} else {
mpCellPhoneKeyboard->calc();
}
mpToolBar->calc();
mpCandidateBox->calc();
mpInputForm->calc();
if (mpPredictLanguageDialog->isActive()) {
mpPredictLanguageDialog->calc();
}
if (mpSignWindow->isActive()) {
mpSignWindow->calc();
}
}
void Manager::draw() {
GXSetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
mpToolBar->draw();
mpInputForm->draw();
if (mpToolBar->isQwerty()) {
mpPCKeyboard->draw();
} else {
mpCellPhoneKeyboard->draw();
}
mpCandidateBox->draw();
if (mpPredictLanguageDialog->isActive()) {
mpPredictLanguageDialog->draw();
}
if (mpSignWindow->isActive()) {
mpSignWindow->draw();
}
}
bool Manager::updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release) {
bool qwerty = mpToolBar->isQwerty();
nw4rmanager::TiEventHandler::Input input;
input.field_0x00 = chan;
*(f32*)&input.dummy[0] = x;
*(f32*)&input.dummy[4] = y;
input.field_0x0C = trig;
input.field_0x10 = hold;
*(u32*)&input.dummy2[0] = release;
mpHWKeyboard->keyboard::hwkey::HWKeyboard::updateInput(chan, x, y, trig, hold, release, &input);
if (mpPredictLanguageDialog->isActive()) {
return mpPredictLanguageDialog
->updateInput(chan, x, y, trig, hold, release, &input);
}
mpInputForm->updateInputCommon(chan, trig, hold, release, &input);
if (mpSignWindow->isActive()) {
return mpSignWindow
->updateInput(chan, x, y, trig, hold, release, &input);
}
bool updatedKeyboard;
if (qwerty) {
updatedKeyboard = mpPCKeyboard->updateInput(chan, x, y, trig, hold, release, &input);
} else {
updatedKeyboard = mpCellPhoneKeyboard->updateInput(chan, x, y, trig, hold, release, &input);
}
bool updatedToolBar =
mpToolBar->updateInput(chan, x, y, trig, hold, release, &input);
bool updatedCandBox =
mpCandidateBox->updateInput(chan, x, y, trig, hold, release, &input);
bool updatedInputForm = mpInputForm->updateInput(chan, x, y, trig, hold, release, &input);
bool result = (updatedKeyboard | updatedToolBar | updatedCandBox | updatedInputForm) != 0;
if (mpToolBar->isQwerty() != qwerty) {
getInputForm()->onCommand((CommandReceiver::INPUT_COMMAND)6, NULL);
mpCandidateBox->checkValidation();
if (mpToolBar->isQwerty()) {
mpPCKeyboard->onActive();
} else {
mpCellPhoneKeyboard->onActive();
}
}
return result;
}
bool Manager::updateInput(input::HKBManager& hkbManager) {
bool qwerty = mpToolBar->isQwerty();
if (mpPredictLanguageDialog->isActive()) {
return mpPredictLanguageDialog
->updateInput(hkbManager);
}
if (mpSignWindow->isActive()) {
return mpSignWindow->updateInput(hkbManager);
}
bool updatedKeyboard;
if (qwerty) {
updatedKeyboard = mpPCKeyboard->updateInput(hkbManager);
} else {
updatedKeyboard = mpCellPhoneKeyboard->updateInput(hkbManager);
}
bool updatedToolBar = mpToolBar->updateInput(hkbManager);
bool updatedCandBox = mpCandidateBox->updateInput(hkbManager);
bool updatedInputForm = mpInputForm->updateInput(hkbManager);
bool result = (updatedKeyboard | updatedToolBar | updatedCandBox | updatedInputForm) != 0;
if (mpToolBar->isQwerty() != qwerty) {
getInputForm()->onCommand((CommandReceiver::INPUT_COMMAND)6, NULL);
mpCandidateBox->checkValidation();
if (mpToolBar->isQwerty()) {
mpPCKeyboard->onActive();
} else {
mpCellPhoneKeyboard->onActive();
}
}
return result;
}
wchar_t* Manager::getWCString() const {
return mpInputForm->getWCString();
}
void Manager::setWCString(const wchar_t* string) {
mpInputForm->inputform::Base::setString(string);
}
void Manager::setLanguage(Language language) {
meLanguage = language;
}
void Manager::setDestination(Destination destination) {
meDestination = destination;
}
void Manager::limitStringLength(u32 limitStringLength) {
mpInputForm->limitStringLength(limitStringLength);
}
void Manager::limitRowNum(u32 limitRowNum) {
mpInputForm->limitRowNum(limitRowNum);
}
void Manager::setAnimationOn(bool flag) {
mpPCKeyboard->setAnimOn(flag);
mpCellPhoneKeyboard->setAnimOn(flag);
mpInputForm->setAnimOn(flag);
mpCandidateBox->setAnimOn(flag);
mpToolBar->setAnimOn(flag);
mpPredictLanguageDialog
->setAnimOn(flag);
mpSignWindow
->setAnimOn(flag);
}
void Manager::setAspectRatio(bool b4x3) {
mbAspectRatio4x3 = b4x3;
if (mbAspectRatio4x3 == true) {
setLayoutScaleFor4x3();
} else {
setLayoutScaleFor16x9();
}
}
void Manager::setTitleText(wchar_t* titleText) {
nw4r::lyt::Pane* pane = mpInputForm->getPane("T_title_text");
nw4r::lyt::TextBox* textBox = nw4r::ut::DynamicCast<nw4r::lyt::TextBox*>(pane);
if (textBox != NULL) {
textBox->SetString(titleText, 0);
}
}
void Manager::setLayoutScaleFor16x9() {
mpPCKeyboard->setRootPaneScaleFor16x9();
mpCellPhoneKeyboard->setRootPaneScaleFor16x9();
mpInputForm->setRootPaneScaleFor16x9();
mpCandidateBox->setRootPaneScaleFor16x9();
mpToolBar->setRootPaneScaleFor16x9();
mpPredictLanguageDialog
->setRootPaneScaleFor16x9();
mpSignWindow
->setRootPaneScaleFor16x9();
}
void Manager::setLayoutScaleFor4x3() {
mpPCKeyboard->setRootPaneScaleFor4x3();
mpCellPhoneKeyboard->setRootPaneScaleFor4x3();
mpInputForm->setRootPaneScaleFor4x3();
mpCandidateBox->setRootPaneScaleFor4x3();
mpToolBar->setRootPaneScaleFor4x3();
mpPredictLanguageDialog
->setRootPaneScaleFor4x3();
mpSignWindow
->setRootPaneScaleFor4x3();
}
inputform::EditBuffer* Manager::createEditBuffer() {
return new (MEMAllocFromAllocator(mpAllocator, sizeof(inputform::EditBuffer))) inputform::EditBuffer();
}
keyboard::hwkey::HWKeyboard* Manager::createHWKeyboard() {
return new (MEMAllocFromAllocator(mpAllocator, sizeof(keyboard::hwkey::HWKeyboard))) keyboard::hwkey::HWKeyboard(this);
}
void* Manager::createPCTypeKeyboard() {
return new (MEMAllocFromAllocator(mpAllocator, sizeof(keyboard::pctype::Sample))) keyboard::pctype::Sample(this, mpMultiArcResourceAccessor, "fs_VK_ascii_keytop_a.brlyt", mpEventObserver);
}
void* Manager::createCellPhoneTypeKeyboard() {
return new (MEMAllocFromAllocator(mpAllocator, sizeof(keyboard::cellphonetype::Sample))) keyboard::cellphonetype::Sample(this, mpMultiArcResourceAccessor, "fs_VK_cellPhone_a.brlyt", mpEventObserver);
}
InputForm* Manager::createInputForm() {
return new (MEMAllocFromAllocator(mpAllocator, sizeof(inputform::Sample)))
inputform::Sample(this, mpMultiArcResourceAccessor, "fs_VK_textBox_a.brlyt", mpEventObserver, NULL);
}
void* Manager::createCandidateBox() {
return new (MEMAllocFromAllocator(mpAllocator, sizeof(candidatebox::Sample))) candidatebox::Sample(this, mpMultiArcResourceAccessor, "fs_VK_predictInput_a.brlyt", mpEventObserver);
}
void* Manager::createToolBar() {
return new (MEMAllocFromAllocator(mpAllocator, sizeof(toolbar::Sample))) toolbar::Sample(this, mpMultiArcResourceAccessor, "fs_VK_toolbar_a.brlyt", mpEventObserver);
}
void* Manager::createPredictLanguageDialog() {
return new (MEMAllocFromAllocator(mpAllocator, sizeof(predictlang::Sample))) predictlang::Sample(this, mpMultiArcResourceAccessor, "fs_prdicSelWidw_a.brlyt", mpEventObserver);
}
predictlang::Base::~Base() {}
void* Manager::createSignWindow() {
return new (MEMAllocFromAllocator(mpAllocator, sizeof(keyboard::signwindow::Sample))) keyboard::signwindow::Sample(this, mpMultiArcResourceAccessor, "fs_signWindow_a.brlyt", mpEventObserver);
}
void Manager::startPredictTurnOn(bool flag) {
if (getInputForm()->isPredictOn() != flag) {
getCandidateBox()->startTurnOn(flag);
}
}
bool Manager::isPredictTurning() const {
return getCandidateBox()->getOnOffButton().IsTurning();
}
void Manager::enableCompatibleFilter(bool compatibleFilter) {
inputform::DeadKeyStream::sbCompatibleFilterEnabled = compatibleFilter;
}
void Manager::enableKSXFilter(bool flag) {
static_cast<tistring::Decolated*>(mpEditBuffer->getString())->EnableKSXFilter(flag);
static_cast<tistring::Decolated*>(mpEditBuffer->getZiString())->EnableKSXFilter(flag);
}
bool Manager::isVacancy() const {
if (getInputForm() == NULL || getToolBar() == NULL) {
return true;
}
if (!getToolBar()->isQwerty()) {
if (getCellPhoneKeyboard()->isHoldingButton()) {
return false;
}
}
return getInputForm()->inputform::Base::isVacancy();
}
const InputForm* Manager::getInputForm() const {
return mpInputForm;
}
const keyboard::cellphonetype::LayoutByNW4R* Manager::getCellPhoneKeyboard() const {
return mpCellPhoneKeyboard;
}
void Manager::SetFont(nw4r::lyt::FontRefLink* fontLink) {
nw4r::ut::Font* font = fontLink->GetFont();
if (mpToolBar != NULL) {
mpToolBar->SetFontForce(font);
}
if (mpPCKeyboard != NULL) {
mpPCKeyboard->SetFontForce(font);
}
if (mpCandidateBox != NULL) {
mpCandidateBox->SetFontForce(font);
}
if (mpSignWindow != NULL) {
mpSignWindow
->SetFontForce(font);
}
if (mpInputForm != NULL) {
((nw4r::ut::CharWriter*)((char*)mpInputForm + 0x10))->SetFont(*font);
}
if (mpCellPhoneKeyboard != NULL) {
mpCellPhoneKeyboard->SetFontForce(font);
}
}
void* Manager::getPredictLanguageSelectDialog() {
return mpPredictLanguageDialog;
}
const void* Manager::getPredictLanguageSelectDialog() const {
return mpPredictLanguageDialog;
}
void* Manager::getSignKeyboard() {
return mpSignWindow;
}
const void* Manager::getSignKeyboard() const {
return mpSignWindow;
}
void Manager::setDefaultPredictionJP(int num, const char** predicts) {
static_cast<tistring::WithAtok*>(getInputForm()->getAtokString())->setDefaultPrediction(num, predicts);
}
void predictlang::Base::init() {}
void predictlang::Base::create(MEMAllocator* allocator) {
mpAllocator = allocator;
}
keyboard::signwindow::Sample::~Sample() {}
predictlang::Sample::~Sample() {}
toolbar::Sample::~Sample() {}
inputform::Sample::~Sample() {}
candidatebox::Sample::~Sample() {}
keyboard::cellphonetype::Sample::~Sample() {}
keyboard::pctype::Sample::~Sample() {}
} // namespace textinput

View File

@@ -50,3 +50,64 @@
Old leaf tip f2afe0e8 beat upstream on: zoemdata +34.2, ziswordw +10.5,
zi8uwd +7.3, zidawg1 +1.7, zi8pud2 +0.7, zi81key/zmtkey marginal.
Upstream won on: zi8alpha +4.5, zi8cgetc +16, zconvert +0.4, zkokeyp +0.1.
## clib2 session (zidawg1 + zi8pud2 decodes)
### zidawg1 (unit fuzzy 94.45 -> 95.27)
- ZiDAWGGetGraphInfo 81.8 -> 99.63: shared-fail `||` guard (`if ((e0<<8)+e1 != 0 || (e2<<8)+e3 != 0) return 0;`) gives orig's two-branch-one-block layout; else-return-wrap (`if (!(range)) { while-loop } else { return 0; }`) produces orig's cold-block ordering where plain early-return doesn't; inner scan is a compound `while ((ziU32)entry < end && *keys != (ziS32)((entry[2]<<8)+entry[3]))` (orig enters mid-body via forward b); byte-packed result needs paren grouping `(graph + (entry[4]<<16)) + ((entry[5]<<8)+entry[6])`.
- ZiDAWGgetCHARattribute 95.5 -> 98.33: `attribute |= ((ziU32)(ziU8)A << 8) + B` merged-assign form (single OR'd pair).
- ZiDAWGGetChild 93.6 -> 93.9: explicit `(ziU16)` cast on table load reproduces orig's redundant clrlwi-into-home.
- ZiDAWGGetSibling 86.9 -> 89.31: cursor-walker model — a separate `cursor` web walks the node bytes (orig r3 volatile), `offset` counts advances, `node` stays at base (orig r28 callee), result `node += offset` / `node = offset + (node + b2)`. Packed-add tree: write `offset = b0x + b1x; offset += 0x8000; node += b2; node = offset + node;` — MWCC reassociates a one-line expression folding +0x8000 onto the b1 term.
- Residual (documented wall): volatile-vs-callee web choice — orig homes `node` in r28 and walks `cursor` in r3 (volatile); MWCC picks the opposite. This is the "local-before-param" family: no calls in fn, allocator assigns homes purely by internal weights.
### zi8pud2 (unit fuzzy 81.7 -> 84.6, ZHS fn 72.6 -> 77.0)
- `length &= 0x7F` before `length *= 2` is dead — `(x<<1)&0xff ≡ (x&0x7f)<<1`; MWCC doesn't fold the mask. Removing it reproduces orig's `slwi+clrlwi`.
- Section-scan loop is `while (index < count) { if (lang==match) break; section++; index++; }` — break-on-match at top, count-check at bottom. A compound `A && B` while emits the wrong check order.
- Three consecutive `if (cond) goto L` statements merge into || evaluation with `beq`-to-next polarity; orig's `bne`-past shape comes from the nested-if form `if (A) { if (B) goto L } else { if (C) goto L }`.
- ZHS byte-copy loop advances `index` between the two stores (`[i]=w[i]; i++; [i]=w[i]; i++`) — `index+1` addressing emits recompute-adds instead.
- Residual: fn-wide web permutation (orig homes `output` as a per-use stack spill `lwz r3,0x10(r1)`; mine keeps it callee) + the `next:` cold-block placement — allocator/scheduling family.
### other units checked this session — all pure web-rotation ties (documented family)
- zi8getc2: Zi8IsDupWChar (8 diffs, r27<->r28 param/local swap), Zi8GetDataSignature (9, 3-web cyclic)
- zi8match: Zi8GetPyPhonetic (uniform r-shift), Zi8GetPyFinal (8, volatile operand-order)
- zconvert: UC2WC (8, r25<->r27), UC2Key (18, r27<->r28)
- zi8dawg: Zi8MatchROMdata1 (5, r26<->r27)
## ziswordw IsWordW formats-init decode (w0930)
- orig's 8-byte `formats` init reads 8 SEPARATE 1-byte GLOBAL objects in .sdata2 (lbl_81695018-1F),
not a pooled literal. Reproduce: `__declspec(section ".sdata2") ziU8 name = v;` (non-const!) file-scope
globals + per-element `formats[i] = name_i;` statements. Plain `const` folds to pooled literal @33 or
`li` immediates; `static const` pools too; array-indexed init-list also pools. declspec non-const is the
only form that emits per-symbol lbz/stb pairs (orig pairing: 2 loads then 2 stores).
- orig zero-inits 5 locals (count/offset/group/remaining/value = stw+stw+stb+stb+sth at fn top) —
declare them `= 0`.
- emission order: decl-init zeros -> formats copies -> saved ZI_WORK loads -> search.* = 0 -> Zi8LogError.
- Residual: MWCC remats `li r0,0` per store (orig keeps r0=0 live across contiguous zero-stores — the
intervening formats loads clobber r0 in my scheduling); r26-vs-r27 web rotation. 83.3 -> 83.7.
## zidawg1 GetSibling/GetChild decode continued (w1001)
- GetSibling 89.3 -> 91.7: orig walks the `node` PARAM in volatile r3 (no callee marshal — loop has no
calls) with a separate `base` local for the offset sum. Source: `base = node;` then all cursor ops on
`node` itself; final `node = base + offset`. Residual: MWCC memop/branch scheduling inside the do-loop
(~88 ordering diffs, homes now match r29/r30/r31/r28).
- Sum-tree groupings verified: orig's 0x80-node result is `offset + (base + byte2)` — paren form required.
GetChild byte-left add `offset = node[2] + offset` (7->6). `& 0xffff` mask on the b1 term is REQUIRED
(removal reassociates the whole tree, -27 fuzzy).
- OWNER RULES (w1001): no lbl_ names, no volatile use-site casts, no score-lifting objects. declspec
.sdata2 byte objects (ziWordFormatN) are semantically named — allowed.
## w1002 lever-stack pass on near-100 units (new owner rules)
Verified instruction-identical (fuzzy residual = symbol/name artifacts, no source lever):
- zconvert Zi8UC2WC (ndiff 0), zmtkey Zi8MTGetKeyLayout (ndiff 0, 24 relocs match).
Rotation family confirmed again (later-defined web -> lower callee reg in orig; MWCC assigns
creation-order upward here): IsDupWChar duplicate/character swap (8), GetDataSignature
signature/destination/language 3-web cycle (9), MatchROMdata1 groupIndex/result swap (5),
GetPyPhonetic ~50 regname diffs, GetPyFinal 8-diff scratch swap (orig evaluates table base
BEFORE row*8 in IR: base->r6, scale->r7; sum reuses base's reg; mine scales first).
Levers tried and refuted this pass: decl-order swap, decl-init fusion, moved-init,
local-copy of param (regressed 5->119), flat-pointer subscript (8->26), stmt-order swap
(8->12), u32 cast on index, comma-expr (build error), int-vs-ziBool width (8).
zkokeyp: 4 fns 6-9 regname diffs (same family); Zi8_814834AC (328) + Zi8GetKOcandidates
(642) are fn-wide web rotations — identical stack-slot layout (0x8..0x20) and near-equal
insn counts, no structural decode gap found in 814834AC (verified elementCount/2 signed-div,
9-stride entry calc, shift-loop per-iter bound recompute all match orig).