#ifndef TEXTINPUT_INPUT_FORM_H #define TEXTINPUT_INPUT_FORM_H #include #include #include #include "tiTextInputBase.h" #include "tiTextDrawer.h" #include "tiCandidateBox.h" #include "tiNw4rManager.h" #include "tiZiString.h" #include "tiSEId.h" #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) extern "C" wchar_t KPRGetChar(KPRQueue* queue); extern "C" void KPRPutChar(KPRQueue* queue, wchar_t character); extern "C" void KPRClearQueue(KPRQueue* queue); extern "C" void KPRInitRegionUS(); extern "C" u8 KPRLookAhead(KPRQueue* queue, wchar_t* character, wchar_t* combining); #endif namespace textinput { #ifdef TIMANAGER_IMPLEMENTATION class Manager; #endif namespace inputform { #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) class Base; class EventHandler; class LayoutByNW4R; #endif class EditBuffer { #ifdef TIMANAGER_IMPLEMENTATION friend class textinput::Manager; public: EditBuffer() : mpString(NULL), mpUnfixString(NULL), mpZiString(NULL), mpAllocator(NULL) {} #endif #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) friend class LayoutByNW4R; friend class Base; #endif public: #if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) void create(MEMAllocator* allocator); #endif #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) virtual ~EditBuffer(); #else ~EditBuffer(); #endif private: void* mpString; // 0x04 void* mpUnfixString; // 0x08 void* mpZiString; // 0x0C MEMAllocator* mpAllocator; // 0x10 }; class DeadKeyStream { #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) public: DeadKeyStream() { KPRInitRegionUS(); init(); } static wchar_t ToCombineClass(Language language, wchar_t code); static wchar_t ToIndependentClass(wchar_t code); inline wchar_t getChar(); void init(); u8 lookAhead() { return KPRLookAhead(&mKPRQueue, NULL, NULL); } void putChar(wchar_t character) { KPRPutChar(&mKPRQueue, character); } bool isEmpty() const { return mKPRQueue.oCount == 0; } void clear() { KPRClearQueue(&mKPRQueue); } private: #ifdef TIMANAGER_IMPLEMENTATION friend class textinput::Manager; #endif static bool sbCompatibleFilterEnabled; static inline bool isCompatible(wchar_t character); #elif defined(TI_PC_KEYBOARD_IMPLEMENTATION) public: static wchar_t ToIndependentClass(wchar_t code); #endif private: KPRQueue mKPRQueue; // 0x00 }; class Base : public CommandReceiver, public textdrawer::Base, public candidatebox::CandidateBoxCaller { public: typedef enum PredictMode { PM_Off, PM_Atok, PM_USEn, PM_USFr, PM_USSp, PM_En, PM_De, PM_Fr, PM_Sp, PM_It, PM_Nl, PM_11, // Cn? PM_12, // Kr? PM_End } PredictMode; // TODO - location? enum InputMode { IM_Direct, IM_ROMAN, IM_End, }; // TODO - location? enum ScrollFlag { SF_NoScroll, SF_ScrollOn, SF_ScrollByBS, SF_End, }; struct Info_ { u16 Back; u16 Next; u16 StrCount; u16 DispRowCount; }; // TODO - location class RowInfoManager { #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) friend class LayoutByNW4R; friend class Base; public: RowInfoManager(u16 maxLength) : mpInfo(NULL), mMaxLength(maxLength), mpAllocator(NULL) {} #ifdef TIINPUTFORM_IMPLEMENTATION void init() __attribute__((never_inline)); #else void init(); #endif ~RowInfoManager(); #endif private: Info_* mpInfo; // 0x00 u16 mMaxLength; // 0x04 MEMAllocator* mpAllocator; // 0x08 }; #ifdef TISIGNWINDOW_IMPLEMENTATION bool isAtokActive() const; #endif #if defined(MYTILETTERFORM_IMPLEMENTATION) || defined(MYTIINPUTFORM_IMPLEMENTATION) virtual void create(MEMAllocator* allocator); virtual void init(); virtual void onCommand(INPUT_COMMAND command, void* data); #endif virtual ~Base(); #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) Base(Manager* manager); virtual void create(MEMAllocator* allocator); virtual void init(); virtual void onCommand(INPUT_COMMAND command, void* data); void setCursorPos(tistring::Decolated* string, u32 pos); void calcCursorTimer(); bool isAtokActive() const; bool isVacancy() const; void dirtyCacheAll(); tistring::Decolated* getCurrentString(bool inputting); void moveCandidateToIdx(s32 index); void onPressDownHWKB(); void onPressLeftHWKB(); void onPressRightHWKB(); void toggleAtokMode_(u8 operation); void onSpaceKeyHWKB(u32 modifiers); void onHKBCtrlCode(HVKCode code, u32 modifiers); void confirmInput_(); void confirmInputting_(wchar_t character, bool direct, u16 letterMode, bool confirmOnly, void* holdingKey); void inputCharZi_(wchar_t character, u32 modifiers); void inputCharDefault_(wchar_t character, u32 modifiers); void inputInputting_(wchar_t character); inline bool hasZiPredictions() const; inline bool usesZiPrediction() const; inline void resetPredictionContext(); inline void resetInputRelation(); #endif virtual void create(MEMAllocator* allocator, EditBuffer* editBuffer); virtual void updateCandidateState_(); virtual wchar_t* getWCString() const; virtual void* getAtokString(); virtual wchar_t getCandidate() const; virtual u32 getCursorPos(); virtual void setFont(const nw4r::ut::Font& font); virtual bool isEditMode(); virtual bool checkHeadOfSentence(bool); virtual void setDestination(Destination destination); virtual void limitStringLength(u32 limitStringLength); virtual void limitRowNum(u32 limitRowNum); virtual void doWordWrap(bool wordWrap); virtual void setLineDrawInfo(bool lineDraw, u32 lineCount); virtual void setLanguage(Language language); virtual void setPredictMode(PredictMode predictMode); virtual PredictMode getPredictMode(); virtual u32 isOverRowLimit(u32 limitRowNum, const wchar_t* string); virtual bool findURL(u32*, u32*, const wchar_t*, u32, u32); virtual bool isInScroll(); virtual void setAtokDictionary(void* atokDict, int atokDictSize, void* apotDict, int apotDictSize, void* nintendoDict, int nintendoDictSize); virtual void closeAtokDictionary(); virtual bool isAtokDictionaryOpened(); void setZiDictionary(void* ziOemDict, void* ziDict) { mpZiString->openDictionary(ziDict, ziOemDict); initZiString(); resetContextPredict_(); } void initZiString(); void resetContextPredict_(); void notifyChangeMode(); void setCursorSelectFlg(bool flag) { mbCursorSelected = flag; } void deselectCandidate(); virtual void enableSpaceByRight(bool rightWithSpace); virtual void onClose(); #ifdef TI_PC_KEYBOARD_IMPLEMENTATION tistring::WithAtok* getCurrentString(bool fixed); virtual bool canConvert() { return getCurrentString(false) == mpUnfixString; } #else virtual bool canConvert(); #endif virtual void setString(const wchar_t* string); virtual void draw(); virtual void calc(); virtual void doBeforeDrawProcess(const wchar_t*, u32, const DrawInfo& drawInfo); virtual void doAfterDrawProcess(const wchar_t*, u32, const DrawInfo& drawInfo); virtual void preDraw(u32); virtual void finishDraw(u32); virtual void doLineFeed(); virtual bool onCursor(CursorPos* cursorPos); virtual bool isOverLine(const DrawInfo& drawInfo); virtual void drawCursor(f32 x, f32 y); virtual void doScroll(Scroll* scroll); virtual void autoScroll(); virtual bool doWordWrap(const wchar_t* string, u32, f32); f32 getWordWrapRectWidth() const { return mRect.right - mRect.left; } virtual void drawFixString(u32); virtual void onSE(sound::SE seId); #ifdef MYTIMANAGER_IMPLEMENTATION void dirtyCacheAll(); #endif virtual void clear(); virtual u32 calcCursorPos(f32 x, f32 y); virtual nw4r::math::VEC2 getGlobalLeftTopPos() const; virtual nw4r::math::VEC2 getScale() const; virtual void moveCursorUp(); virtual void moveCursorDown(); virtual void onPressUp(); virtual void onPressDown(); virtual void onPressLeft(); virtual void onPressRight(); virtual void makeUpCursorPos(CursorPos* cursorPos, u32 pos, s32 startLine, s32 endLine); #if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION) protected: #if !defined(TIINPUTFORM_IMPLEMENTATION) && !defined(TIMANAGER_IMPLEMENTATION) void setCursorPos(tistring::Decolated* string, u32 pos); void calcCursorTimer(); #endif void resetRelation(); #else private: #endif #if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION) nw4r::ut::Rect mRect; #else Rect mRect; #endif nw4r::math::MTX34 mMtx; // 0x130 Destination meDestination; // 0x160 tistring::Decolated* mpString; // 0x164 tistring::WithAtok* mpUnfixString; // 0x168 tistring::WithZi* mpZiString; // 0x16C InputMode meInputMode; // 0x170 PredictMode mePredictMode; // 0x174 #ifdef TIMANAGER_IMPLEMENTATION friend class textinput::Manager; #endif bool mbPredictOn; // 0x178 bool mbDoWordWrap; // 0x179 bool mbRightWithSpace; // 0x17A bool mbPadding; // 0x17B f32 mfCursorX; // 0x17C f32 mfCursorY; // 0x180 f32 mfScrollX; // 0x184 f32 mfScrollY; // 0x188 util::Animation mScrollAnm; // 0x18C f32 mfSustainTimer; // 0x1AC ScrollFlag meScrollFlag; // 0x1B0 u32 muWordWrapCounter; // 0x1B4 u32 muLimitStringLength; // 0x1B8 u32 muLimitRowNum; // 0x1BC GXColor mSelectedColor; // 0x1C0 f32 mfCursorTimer; // 0x1C4 u8 muGlobalAlpha; // 0x1C8 u8 muPaddint; // 0x1C9 nw4r::ut::Color mCharColor; // 0x1CC MEMAllocator* mpAllocator; // 0x1D0 Manager* mpManager; // 0x1D4 DeadKeyStream mDKStream; // 0x1D8 Language meLanguage; // 0x1F0 bool mbZuSelected; // 0x1F4 bool mbCursorSelected; // 0x1F5 RowInfoManager mriManager; // 0x1F8 Info_* mpCursorLine; // 0x204 Info_* mpDrawEndLine; // 0x208 u16 mCursorLinePos; // 0x20C bool mbLineDraw; // 0x20E u32 muSpecifyLineDrawCount; // 0x210 u32 muCursorTimer; // 0x214 }; class LayoutByNW4R : public Base, public nw4rmanager::Layout { #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) friend class EventHandler; inline const nw4r::lyt::Pane* getLanguageTextPane() const; #endif public: #if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) LayoutByNW4R(textinput::Manager*, nw4r::lyt::MultiArcResourceAccessor*, const char*, EventObserver*, const char*); #endif ~LayoutByNW4R(); virtual void init(); virtual void onCommand(INPUT_COMMAND command, void* data); virtual void create(MEMAllocator* allocator, EditBuffer* editBuffer); virtual void setLanguage(Language language); virtual void draw(); virtual void calc(); virtual nw4r::math::VEC2 getScale() const; #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) void updateRepeatInput(u32 trig, u32 hold); #endif virtual void updateInputCommon(int chan, u32 trig, u32 hold, u32 release, void* data); virtual bool updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data); virtual bool updateInput(textinput::input::HKBManager& hkbManager); virtual bool isAbleToUp(); virtual bool isAbleToDown(); virtual void setRootPaneScaleFor16x9(); virtual void setRootPaneScaleFor4x3(); #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION) || defined(MYTIINPUTFORM_IMPLEMENTATION) virtual void onSE(sound::SE seId); #endif virtual void visibleSeparator(bool flag); #if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION) protected: const void* mpLayoutData; const void* mpLanguageData; const char* mpFontName; bool mbUpVisible; bool mbDownVisible; bool mbRepeat; nw4rmanager::TiEventHandler* mpInputEventHandler; nw4r::ut::ResFont mFont; int mUpRepeat; int mDownRepeat; int mLeftRepeat; int mRightRepeat; int mDeleteRepeat; int mConfirmRepeat; u32 mRepeatButtons; #else private: #ifdef MYTIMANAGER_IMPLEMENTATION u8 unk_0x2C0[0x48]; #else u8 unk_0x2C0[0x4C]; #endif #endif }; } typedef inputform::LayoutByNW4R InputForm; typedef inputform::Base InputFormBase; } #endif // TEXTINPUT_INPUT_FORM_H