//Pascal &or the FreePascal use of nintendo 2ds, 3ds regime // // Copyright (c) 2013, 2015, 2017 Kenneth Dwayne Lee Bsc. // all rights reserved // {$ifdef 3dsintf} {* * @file swkbd.h * @brief Software keyboard applet. } {/ Keyboard types. } {/< Normal keyboard with several pages (QWERTY/accents/symbol/mobile) } {/< QWERTY keyboard only. } {/< Number pad. } {/< On JPN systems, a text keyboard without Japanese input capabilities, otherwise same as SWKBD_TYPE_NORMAL. } type SwkbdType = (SWKBD_TYPE_NORMAL := 0,SWKBD_TYPE_QWERTY, SWKBD_TYPE_NUMPAD,SWKBD_TYPE_WESTERN ); {/ Accepted input types. } {/< All inputs are accepted. } {/< Empty inputs are not accepted. } {/< Empty or blank inputs (consisting solely of whitespace) are not accepted. } {/< Blank inputs (consisting solely of whitespace) are not accepted, but empty inputs are. } {/< The input must have a fixed length (specified by maxTextLength in swkbdInit). } SwkbdValidInput = (SWKBD_ANYTHING := 0,SWKBD_NOTEMPTY, SWKBD_NOTEMPTY_NOTBLANK,SWKBD_NOTBLANK_NOTEMPTY := SWKBD_NOTEMPTY_NOTBLANK, SWKBD_NOTBLANK,SWKBD_FIXEDLEN); {/ Keyboard dialog buttons. } {/< Left button (usually Cancel) } {/< Middle button (usually I Forgot) } {/< Right button (usually OK) } {/< No button (returned by swkbdInputText in special cases) } SwkbdButton = (SWKBD_BUTTON_LEFT := 0,SWKBD_BUTTON_MIDDLE, SWKBD_BUTTON_RIGHT,SWKBD_BUTTON_CONFIRM := SWKBD_BUTTON_RIGHT, SWKBD_BUTTON_NONE); {/ Keyboard password modes. } {/< Characters are not concealed. } {/< Characters are concealed immediately. } {/< Characters are concealed a second after they've been typed. } SwkbdPasswordMode = (SWKBD_PASSWORD_NONE := 0,SWKBD_PASSWORD_HIDE, SWKBD_PASSWORD_HIDE_DELAY); {/ Keyboard input filtering flags. } {/< Disallow the use of more than a certain number of digits (0 or more) } {/< Disallow the use of the @ sign. } {/< Disallow the use of the % sign. } {/< Disallow the use of the \ sign. } {/< Disallow profanity using Nintendo's profanity filter. } {/< Use a callback in order to check the input. } Swkbdfilterflags = (SWKBD_FILTER_DIGITS := (1 shl 0) ,SWKBD_FILTER_AT := (1 shl 1), SWKBD_FILTER_PERCENT := (1 shl 2),SWKBD_FILTER_BACKSLASH := (1 shl 3), SWKBD_FILTER_PROFANITY := (1 shl 4),SWKBD_FILTER_CALLBACK := (1 shl 5) ); {/ Keyboard features. } {/< Parental PIN mode. } {/< Darken the top screen when the keyboard is shown. } {/< Enable predictive input (necessary for Kanji input in JPN systems). } {/< Enable multiline input. } {/< Enable fixed-width mode. } {/< Allow the usage of the HOME button. } {/< Allow the usage of a software-reset combination. } {/< Allow the usage of the POWER button. } {/< Default to the QWERTY page when the keyboard is shown. } Swkbdeyboardfeatures = (SWKBD_PARENTAL := (1 shl 0),SWKBD_DARKEN_TOP_SCREEN := (1 shl 1), SWKBD_PREDICTIVE_INPUT := (1 shl 2),SWKBD_MULTILINE := (1 shl 3), SWKBD_FIXED_WIDTH := (1 shl 4),SWKBD_ALLOW_HOME := (1 shl 5), SWKBD_ALLOW_RESET := (1 shl 6),SWKBD_ALLOW_POWER := (1 shl 7), SWKBD_DEFAULT_QWERTY := (1 shl 9)); {/ Keyboard filter callback return values. } {/< Specifies that the input is valid. } {/< Displays an error message, then closes the keyboard. } {/< Displays an error message and continues displaying the keyboard. } SwkbdCallbackResult = (SWKBD_CALLBACK_OK := 0,SWKBD_CALLBACK_CLOSE, SWKBD_CALLBACK_CONTINUE); {/ Keyboard return values. } {/< Dummy/unused. } {/< Invalid parameters to swkbd. } {/< Out of memory. } {/< The button was clicked in 1-button dialogs. } {/< The left button was clicked in 2-button dialogs. } {/< The right button was clicked in 2-button dialogs. } {/< The left button was clicked in 3-button dialogs. } {/< The middle button was clicked in 3-button dialogs. } {/< The right button was clicked in 3-button dialogs. } {/< The HOME button was pressed. } {/< The soft-reset key combination was pressed. } {/< The POWER button was pressed. } {/< The parental PIN was verified successfully. } {/< The parental PIN was incorrect. } {/< The filter callback returned SWKBD_CALLBACK_CLOSE. } SwkbdResult = (SWKBD_NONE := -(1),SWKBD_INVALID_INPUT := -(2), SWKBD_OUTOFMEM := -(3),SWKBD_D0_CLICK := 0, SWKBD_D1_CLICK0,SWKBD_D1_CLICK1,SWKBD_D2_CLICK0, SWKBD_D2_CLICK1,SWKBD_D2_CLICK2,SWKBD_HOMEPRESSED := 10, SWKBD_RESETPRESSED,SWKBD_POWERPRESSED, SWKBD_PARENTAL_OK := 20,SWKBD_PARENTAL_FAIL, SWKBD_BANNED_INPUT := 30); {/ Maximum dictionary word length, in UTF-16 code units. } const SWKBD_MAX_WORD_LEN = 40; {/ Maximum button text length, in UTF-16 code units. } SWKBD_MAX_BUTTON_TEXT_LEN = 16; {/ Maximum hint text length, in UTF-16 code units. } SWKBD_MAX_HINT_TEXT_LEN = 64; {/ Maximum filter callback error message length, in UTF-16 code units. } SWKBD_MAX_CALLBACK_MSG_LEN = 256; {/ Keyboard dictionary word for predictive input. } {/< Reading of the word (that is, the string that needs to be typed). } {/< Spelling of the word. } {/< Language the word applies to. } {/< Specifies if the word applies to all languages. } type SwkbdDictWord = record reading : array[0..(SWKBD_MAX_WORD_LEN+1)-1] of u16; word : array[0..(SWKBD_MAX_WORD_LEN+1)-1] of u16; language : u8; all_languages : bool; end; PSwkbdDictWord = ^SwkbdDictWord; {/ Keyboard filter callback function. } SwkbdCallbackFn = function (user:pointer; ppMessage: ppchar; text:pcchar; textlen:s32):SwkbdCallbackResult;cdecl; {/ Keyboard status data. } SwkbdStatusData = record data : array[0..16] of u32; end; PSwkbdStatusData = ^SwkbdStatusData; {/ Keyboard predictive input learning data. } SwkbdLearningData = record data : array[0..10522] of u32; end; PSwkbdLearningData = ^SwkbdLearningData; {/ Internal libctru book-keeping structure for software keyboards. } SwkbdExtra = record initial_text : ^cchar; dict : ^SwkbdDictWord; status_data : ^SwkbdStatusData; learning_data : ^SwkbdLearningData; callback : SwkbdCallbackFn; callback_user : pointer; end; SwkbdExt = record case longint of 0 : ( reserved : array[0..170] of u8 ); 1 : ( extra : SwkbdExtra ); end; {/ Software keyboard parameter structure, it shouldn't be modified directly. } { XX: what is this supposed to do? "communicateWithOtherRegions" } { XX: not working? supposedly 0 = use system language, CFG_Language+1 = pick language } SwkbdState = record _type : cint; num_buttons_m1 : cint; valid_input : cint; password_mode : cint; is_parental_screen : cint; darken_top_screen : cint; filter_flags : u32; save_state_flags : u32; max_text_len : u16; dict_word_count : u16; max_digits : u16; button_text : array[0..2] of array[0..(SWKBD_MAX_BUTTON_TEXT_LEN+1)-1] of u16; numpad_keys : array[0..1] of u16; hint_text : array[0..(SWKBD_MAX_HINT_TEXT_LEN+1)-1] of u16; predictive_input : bool; multiline : bool; fixed_width : bool; allow_home : bool; allow_reset : bool; allow_power : bool; unknown : bool; default_qwerty : bool; button_submits_text : array[0..3] of bool; language : u16; initial_text_offset : cint; dict_offset : cint; initial_status_offset : cint; initial_learning_offset : cint; shared_memory_size : s32; version : u32; kbdResult : SwkbdResult; status_offset : cint; learning_offset : cint; text_offset : cint; text_length : u16; callback_result : cint; callback_msg : array[0..(SWKBD_MAX_CALLBACK_MSG_LEN+1)-1] of u16; skip_at_check : bool; bdExt: SwkbdExt; end; PSwkbdState = ^SwkbdState; {* * @brief Initializes software keyboard status. * @param swkbd Pointer to swkbd state. * @param type Keyboard type. * @param numButtons Number of dialog buttons to display (1, 2 or 3). * @param maxTextLength Maximum number of UTF-16 code units that input text can have (or -1 to let libctru use a big default). } procedure swkbdInit(swkbd:PSwkbdState; _type:SwkbdType; numButtons:cint; maxTextLength:cint);cdecl;external; {* * @brief Configures password mode in a software keyboard. * @param swkbd Pointer to swkbd state. * @param mode Password mode. } procedure swkbdSetPasswordMode(swkbd:PSwkbdState; mode:SwkbdPasswordMode);cdecl; {* * @brief Configures input validation in a software keyboard. * @param swkbd Pointer to swkbd state. * @param validInput Specifies which inputs are valid. * @param filterFlags Bitmask specifying which characters are disallowed (filtered). * @param maxDigits In case digits are disallowed, specifies how many digits are allowed at maximum in input strings (0 completely restricts digit input). } procedure swkbdSetValidation(swkbd:PSwkbdState; validInput: SwkbdValidInput; filterFlags:u32; maxDigits:s32);cdecl; {* * @brief Configures what characters will the two bottom keys in a numpad produce. * @param swkbd Pointer to swkbd state. * @param left Unicode codepoint produced by the leftmost key in the bottom row (0 hides the key). * @param left Unicode codepoint produced by the rightmost key in the bottom row (0 hides the key). } procedure swkbdSetNumpadKeys(swkbd:PSwkbdState; left, right:s16);cdecl; {* * @brief Specifies which special features are enabled in a software keyboard. * @param swkbd Pointer to swkbd state. * @param features Feature bitmask. } procedure swkbdSetFeatures(swkbd:PSwkbdState; features:u32);cdecl;external; {* * @brief Sets the hint text of a software keyboard (that is, the help text that is displayed when the textbox is empty). * @param swkbd Pointer to swkbd state. * @param text Hint text. } procedure swkbdSetHintText(swkbd:PSwkbdState; text:pchar);cdecl;external; {* * @brief Configures a dialog button in a software keyboard. * @param swkbd Pointer to swkbd state. * @param button Specifies which button to configure. * @param text Button text. * @param submit Specifies whether pushing the button will submit the text or discard it. } procedure swkbdSetButton(swkbd:PSwkbdState; button:SwkbdButton; text:pchar; submit:bool);cdecl;external; {* * @brief Sets the initial text that a software keyboard will display on launch. * @param swkbd Pointer to swkbd state. * @param text Initial text. } procedure swkbdSetInitialText(swkbd:PSwkbdState; text:pchar);cdecl;external; {* * @brief Configures a word in a predictive dictionary for use with a software keyboard. * @param word Pointer to dictionary word structure. * @param reading Reading of the word, that is, the sequence of characters that need to be typed to trigger the word in the predictive input system. * @param text Spelling of the word, that is, the actual characters that will be produced when the user decides to select the word. } procedure swkbdSetDictWord(word:PSwkbdDictWord; reading:pchar; text:pchar);cdecl;external; {* * @brief Sets the custom word dictionary to be used with the predictive input system of a software keyboard. * @param swkbd Pointer to swkbd state. * @param dict Pointer to dictionary words. * @param wordCount Number of words in the dictionary. } procedure swkbdSetDictionary(swkbd:PSwkbdState; dict:PSwkbdDictWord; wordCount:cint);cdecl;external; {* * @brief Configures software keyboard internal status management. * @param swkbd Pointer to swkbd state. * @param data Pointer to internal status structure (can be in, out or both depending on the other parameters). * @param in Specifies whether the data should be read from the structure when the keyboard is launched. * @param out Specifies whether the data should be written to the structure when the keyboard is closed. } procedure swkbdSetStatusData(swkbd:PSwkbdState; data:PSwkbdStatusData; isin:bool; isout:bool);cdecl;external; {* * @brief Configures software keyboard predictive input learning data management. * @param swkbd Pointer to swkbd state. * @param data Pointer to learning data structure (can be in, out or both depending on the other parameters). * @param in Specifies whether the data should be read from the structure when the keyboard is launched. * @param out Specifies whether the data should be written to the structure when the keyboard is closed. } procedure swkbdSetLearningData(swkbd:PSwkbdState; data:PSwkbdLearningData; isin:bool; isout:bool);cdecl;external; {* * @brief Configures a custom function to be used to check the validity of input when it is submitted in a software keyboard. * @param swkbd Pointer to swkbd state. * @param callback Filter callback function. * @param user Custom data to be passed to the callback function. } procedure swkbdSetFilterCallback(swkbd:PSwkbdState; callback:SwkbdCallbackFn; user:pointer);cdecl;external; {* * @brief Launches a software keyboard in order to input text. * @param swkbd Pointer to swkbd state. * @param buf Pointer to output buffer which will hold the inputted text. * @param bufsize Maximum number of UTF-8 code units that the buffer can hold (including null terminator). * @return The identifier of the dialog button that was pressed, or SWKBD_BUTTON_NONE if a different condition was triggered - in that case use swkbdGetResult to check the condition. } function swkbdInputText(swkbd:PSwkbdState; buf:pchar; bufsize:s32):SwkbdButton;cdecl;external; {* * @brief Retrieves the result condition of a software keyboard after it has been used. * @param swkbd Pointer to swkbd state. * @return The result value. } function swkbdGetResult(swkbd:PSwkbdState):SwkbdResult;cdecl; {$endif 3dsintf} {$ifdef 3dsimpl} procedure swkbdSetValidation(swkbd:PSwkbdState; validInput: SwkbdValidInput; filterFlags:u32; maxDigits:s32);cdecl; begin swkbd^.valid_input := u32(validInput); swkbd^.filter_flags := u32(filterFlags); with swkbd^ do if ((filterFlags and u32(SWKBD_FILTER_DIGITS)) > 0) then max_digits := u32(maxDigits) else max_digits := 0; // swkbd^.max_digits = (filterFlags & SWKBD_FILTER_DIGITS) ? maxDigits : 0; end; procedure swkbdSetNumpadKeys(swkbd:PSwkbdState; left, right:s16);cdecl; begin swkbd^.numpad_keys[0] := left; swkbd^.numpad_keys[1] := right; end; procedure swkbdSetPasswordMode(swkbd:PSwkbdState; mode:SwkbdPasswordMode);cdecl; begin swkbd^.password_mode := u32(mode); end; function swkbdGetResult(swkbd:PSwkbdState):SwkbdResult;cdecl; begin swkbdGetResult:= swkbd^.kbdResult; end; {$endif 3dsimpl}