keymap.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2007 by Karoly Balogh
  4. keymap.library interface unit for MorphOS/PowerPC
  5. Based on the Commodore Amiga/68k port by Nils Sjoholm
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$PACKRECORDS 2}
  13. {$IFNDEF FPC_DOTTEDUNITS}
  14. unit keymap;
  15. {$ENDIF FPC_DOTTEDUNITS}
  16. interface
  17. {$IFDEF FPC_DOTTEDUNITS}
  18. uses
  19. Amiga.Core.Exec, Amiga.Core.Inputevent;
  20. {$ELSE FPC_DOTTEDUNITS}
  21. uses
  22. exec, inputevent;
  23. {$ENDIF FPC_DOTTEDUNITS}
  24. type
  25. PKeyMap = ^TKeyMap;
  26. TKeyMap = record
  27. km_LoKeyMapTypes: PByte;
  28. km_LoKeyMap: PLongWord;
  29. km_LoCapsable: PByte;
  30. km_LoRepeatable: PByte;
  31. km_HiKeyMapTypes: PByte;
  32. km_HiKeyMap: PLongWord;
  33. km_HiCapsable: PByte;
  34. km_HiRepeatable: PByte;
  35. end;
  36. PKeymapNode = ^TKeyMapNode;
  37. TKeyMapNode = record
  38. kn_Node: TNode; // including name of keymap
  39. kn_KeyMap: TKeyMap;
  40. end;
  41. PExtendedKeyMapNode = ^TExtendedKeyMapNode;
  42. TExtendedKeyMapNode = record
  43. ekn_Node: TNode;
  44. ekn_KeyMap: TKeyMap;
  45. pad1: Word;
  46. ekn_Seglist: BPTR;
  47. ekn_Resident: PResident;
  48. ekn_Future0: APTR; // keep 0 for now
  49. end;
  50. // the structure of keymap.resource
  51. PKeyMapResource = ^TKeyMapResource;
  52. TKeyMapResource = record
  53. kr_Node: TNode;
  54. kr_List: TList; // a list of KeyMapNodes
  55. end;
  56. const
  57. // Key Map Types
  58. KC_NOQUAL = 0;
  59. KC_VANILLA = 7; // note that SHIFT+ALT+CTRL is VANILLA
  60. KCB_SHIFT = 0;
  61. KCF_SHIFT = 1 shl KCB_SHIFT;
  62. KCB_ALT = 1;
  63. KCF_ALT = 1 shl KCB_ALT;
  64. KCB_CONTROL = 2;
  65. KCF_CONTROL = 1 shl KCB_CONTROL;
  66. KCB_DOWNUP = 3;
  67. KCF_DOWNUP = 1 shl KCB_DOWNUP;
  68. KCB_DEAD = 5; // may be dead or modified by dead key:
  69. KCF_DEAD = 1 shl KCB_DEAD; // use dead prefix bytes
  70. KCB_STRING = 6;
  71. KCF_STRING = 1 shl KCB_STRING;
  72. KCB_NOP = 7;
  73. KCF_NOP = 1 shl KCB_NOP;
  74. // Dead Prefix Bytes
  75. DPB_MOD = 0;
  76. DPF_MOD = 1 shl DPB_MOD;
  77. DPB_DEAD = 3;
  78. DPF_DEAD = 1 shl DPB_DEAD;
  79. DP_2DINDEXMASK = $0f; // mask for index for 1st of two dead keys
  80. DP_2DFACSHIFT = 4; // shift for factor for 1st of two dead keys
  81. type
  82. PUCS4_ConvTable = ^TUCS4_ConvTable;
  83. TUCS4_ConvTable = record
  84. FirstChar: Word;
  85. LastChar: Word;
  86. ConvTable: APTR; // Either pointer to Byte or LongWord
  87. end;
  88. PUCS4_CharsetCode = ^TUCS4_CharsetCode;
  89. TUCS4_CharsetCode = record
  90. UCS4: LongWord;
  91. CharsetCode: LongWord;
  92. end;
  93. PUCS4_CharsetConvTable = ^TUCS4_CharsetConvTable;
  94. TUCS4_CharsetConvTable = record
  95. Mapping: PUCS4_CharsetCode; // An optional array, terminated with (0, 0) entry
  96. ConvTables: array[0..0] of TUCS4_ConvTable; // 0 sized array
  97. end;
  98. var
  99. KeyMapBase: PLibrary = nil;
  100. const
  101. KEYMAPNAME: PAnsiChar = 'keymap.library';
  102. procedure SetKeyMapDefault(const KeyMap: PKeyMap location 'a0'); SysCall KeyMapBase 030;
  103. function AskKeyMapDefault: PKeyMap; SysCall KeyMapBase 036;
  104. function MapRawKey(const Event: PInputEvent location 'a0'; Buffer: STRPTR location 'a1'; Length: LongInt location 'd1'; const KeyMap: PKeyMap location 'a2'): LongInt; SysCall KeyMapBase 042;
  105. function MapANSI(const Strg: STRPTR location 'a0'; Count: LongInt location 'd0'; Buffer: STRPTR location 'a1'; Length: LongInt location 'd1'; const KeyMap: PKeyMap location 'a2'): LongInt; SysCall KeyMapBase 048;
  106. function MapRawKeyUCS4(const Event: PInputEvent location 'a0'; Buffer: WSTRPTR location 'a1'; Length: LongInt location 'd1'; const KeyMap: PKeyMap location 'a2'): LongInt; SysCall KeyMapBase 54;
  107. function MapUCS4(const Strg: WSTRPTR location 'a0'; Count: LongInt location 'd0'; Buffer: STRPTR location 'a1'; Length: LongInt location 'd1'; const KeyMap: PKeyMap location 'a2'): LongInt; SysCall KeyMapBase 60;
  108. function ToANSI(UCS4Char: WideChar location 'a0'; const KeyMap: PKeyMap location 'a1'): AnsiChar; SysCall KeyMapBase 66;
  109. function ToUCS4(ASCIIChar: AnsiChar location 'a0'; const KeyMap: PKeyMap location 'a1'): WideChar; SysCall KeyMapBase 72;
  110. function GetKeyMapCodePage(const KeyMap: PKeyMap location 'a0'): STRPTR; SysCall KeyMapBase 78;
  111. // Helper calls
  112. function InitKeymapLibrary : boolean;
  113. implementation
  114. const
  115. LIBVERSION: LongWord = 50;
  116. function InitKeymapLibrary: boolean;
  117. begin
  118. InitKeyMapLibrary := Assigned(KeyMapBase);
  119. end;
  120. initialization
  121. KeyMapBase := OpenLibrary(KEYMAPNAME, LIBVERSION);
  122. finalization
  123. if Assigned(KeyMapBase) then
  124. CloseLibrary(PLibrary(KeyMapBase));
  125. end.