WMRussianIME.Mod 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. MODULE WMRussianIME; (** AUTHOR "tf"; PURPOSE "Write cyrillic characters"; *)
  2. IMPORT
  3. Strings, WMInputMethods, Texts, KernelLog;
  4. CONST
  5. imeName* = "Russian";
  6. TYPE
  7. IME* = OBJECT(WMInputMethods.IME)
  8. PROCEDURE GetName*() : Strings.String;
  9. BEGIN
  10. RETURN Strings.NewString(imeName);
  11. END GetName;
  12. (* Map characters from US-Keyboard to cyrillic keyboard *)
  13. PROCEDURE KeyEvent*(ucs : LONGINT; flags : SET; keysym : LONGINT);
  14. BEGIN
  15. CASE ucs OF
  16. (* unshifted *)
  17. | 60H : InsertChar(00000451H) (*`*)
  18. (* first row: qwertyuiop[] *)
  19. | 71H : InsertChar(00000439H) (*q*)
  20. | 77H : InsertChar(00000446H) (*w*)
  21. | 65H : InsertChar(00000443H) (*e*)
  22. | 72H : InsertChar(0000043AH) (*r*)
  23. | 74H : InsertChar(00000435H) (*t*)
  24. | 79H : InsertChar(0000043DH) (*y*)
  25. | 75H : InsertChar(00000433H) (*u*)
  26. | 69H : InsertChar(00000448H) (*i*)
  27. | 6FH : InsertChar(00000449H) (*o*)
  28. | 70H : InsertChar(00000437H) (*p*)
  29. | 5BH : InsertChar(00000445H) (*[*)
  30. | 5DH : InsertChar(0000044AH) (*]*)
  31. (* second row : asdfghjkl;' *)
  32. | 61H : InsertChar(00000444H) (*a*)
  33. | 73H : InsertChar(0000044BH) (*s*)
  34. | 64H : InsertChar(00000432H) (*d*)
  35. | 66H : InsertChar(00000430H) (*f*)
  36. | 67H : InsertChar(0000043FH) (*g*)
  37. | 68H : InsertChar(00000440H) (*h*)
  38. | 6AH : InsertChar(0000043EH) (*j*)
  39. | 6BH : InsertChar(0000043BH) (*k*)
  40. | 6CH : InsertChar(00000434H) (*l*)
  41. | 3BH : InsertChar(00000436H) (*;*)
  42. | 27H : InsertChar(0000044DH) (*'*)
  43. (* third row : zxcvbnm,./;' *)
  44. | 7AH : InsertChar(0000044FH) (*z*)
  45. | 78H : InsertChar(00000447H) (*x*)
  46. | 63H : InsertChar(00000441H) (*c*)
  47. | 76H : InsertChar(0000043CH) (*v*)
  48. | 62H : InsertChar(00000438H) (*b*)
  49. | 6EH : InsertChar(00000442H) (*n*)
  50. | 6DH : InsertChar(0000044CH) (*m*)
  51. | 2CH : InsertChar(00000431H) (*,*)
  52. | 2EH : InsertChar(0000044EH) (*.*)
  53. | 2FH : InsertChar(0000002EH) (*/*)
  54. (* shifted *)
  55. | 7EH : InsertChar(00000401H) (*~*)
  56. | 40H : InsertChar(00000022H) (**@*)
  57. | 23H : InsertChar(00002116H) (**#*)
  58. | 24H : InsertChar(0000003BH) (*$*)
  59. | 5EH : InsertChar(0000003AH) (*^*)
  60. | 26H : InsertChar(0000003FH) (*&*)
  61. (* first row: QWERTYUIOP{} *)
  62. | 51H : InsertChar(00000419H) (*Q*)
  63. | 57H : InsertChar(00000426H) (*W*)
  64. | 45H : InsertChar(00000423H) (*E*)
  65. | 52H : InsertChar(0000041AH) (*R*)
  66. | 54H : InsertChar(00000415H) (*T*)
  67. | 59H : InsertChar(0000041DH) (*Y*)
  68. | 55H : InsertChar(00000413H) (*U*)
  69. | 49H : InsertChar(00000428H) (*I*)
  70. | 4FH : InsertChar(00000429H) (*O*)
  71. | 50H : InsertChar(00000417H) (*P*)
  72. | 7BH : InsertChar(00000425H) (*{*)
  73. | 7DH : InsertChar(0000042AH) (*}*)
  74. (* second row : ASDFGHJKL:"| *)
  75. | 41H : InsertChar(00000424H) (*A*)
  76. | 53H : InsertChar(0000042BH) (*S*)
  77. | 44H : InsertChar(00000412H) (*D*)
  78. | 46H : InsertChar(00000410H) (*F*)
  79. | 47H : InsertChar(0000041FH) (*G*)
  80. | 48H : InsertChar(00000420H) (*H*)
  81. | 4AH : InsertChar(0000041EH) (*J*)
  82. | 4BH : InsertChar(0000041BH) (*K*)
  83. | 4CH : InsertChar(00000414H) (*L*)
  84. | 3AH : InsertChar(00000416H) (*:*)
  85. | 22H : InsertChar(0000042DH) (*"*)
  86. | 7CH : InsertChar(0000002FH) (*|*)
  87. (* third row : ZXCVBNM<>? *)
  88. | 5AH : InsertChar(0000042FH) (*Z*)
  89. | 58H : InsertChar(00000427H) (*X*)
  90. | 43H : InsertChar(00000421H) (*C*)
  91. | 56H : InsertChar(0000041CH) (*V*)
  92. | 42H : InsertChar(00000418H) (*B*)
  93. | 4EH : InsertChar(00000422H) (*N*)
  94. | 4DH : InsertChar(0000042CH) (*M*)
  95. | 3CH : InsertChar(00000411H) (*<*)
  96. | 3EH : InsertChar(0000042EH) (*>*)
  97. | 3FH : InsertChar(0000002CH) (*?*)
  98. ELSE
  99. InsertChar(ucs)
  100. END
  101. END KeyEvent;
  102. END IME;
  103. (* installs the Russian IME *)
  104. PROCEDURE Install*;
  105. VAR ime : IME;
  106. BEGIN
  107. NEW(ime);
  108. WMInputMethods.InstallIME(ime);
  109. END Install;
  110. (* helper procedure for development : return the UCS code of a selected character in a text *)
  111. PROCEDURE SelectedCharToUCS*;
  112. VAR r : Texts.TextReader;
  113. selectionText: Texts.Text;
  114. ucs : LONGINT;
  115. from, to : Texts.TextPosition;
  116. BEGIN
  117. IF Texts.GetLastSelection(selectionText, from, to) THEN
  118. selectionText.AcquireRead;
  119. NEW(r, selectionText);
  120. r.SetPosition(MIN(from.GetPosition(), to.GetPosition()));
  121. r.ReadCh(ucs);
  122. selectionText.ReleaseRead;
  123. KernelLog.String("InsertChar("); KernelLog.Hex(ucs, 0); KernelLog.String("H) (**)"); KernelLog.Ln;
  124. END;
  125. END SelectedCharToUCS;
  126. END WMRussianIME.Install~
  127. System.Free WMRussianIME~
  128. WMRussianIME.SelectedCharToUCS ~
  129. WMKeyCode.Open ~