InputLanguage.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Peter Bartok [email protected]
  24. //
  25. // NOT COMPLETE
  26. using System.Globalization;
  27. namespace System.Windows.Forms {
  28. public sealed class InputLanguage {
  29. internal static InputLanguageCollection all;
  30. private IntPtr handle;
  31. private CultureInfo culture;
  32. private string layout_name;
  33. private static InputLanguage current_input;
  34. private static InputLanguage default_input;
  35. #region Private Constructor
  36. [MonoTODO("Pull Microsofts InputLanguages and enter them here")]
  37. internal InputLanguage() {
  38. if (all == null) {
  39. all = new InputLanguageCollection();
  40. all.Add(new InputLanguage(IntPtr.Zero, new CultureInfo(""), "US"));
  41. }
  42. if (default_input == null) {
  43. default_input=InputLanguage.FromCulture(CultureInfo.CurrentUICulture);
  44. }
  45. if (current_input == null) {
  46. current_input=InputLanguage.FromCulture(CultureInfo.CurrentUICulture);
  47. }
  48. }
  49. internal InputLanguage(IntPtr handle, CultureInfo culture, string layout_name) : this() {
  50. this.handle=handle;
  51. this.culture=culture;
  52. this.layout_name=layout_name;
  53. }
  54. #endregion // Private Constructor
  55. #region Public Static Properties
  56. public static InputLanguage CurrentInputLanguage {
  57. get {
  58. return current_input;
  59. }
  60. set {
  61. if (all.Contains(value)) {
  62. current_input=value;
  63. }
  64. }
  65. }
  66. public static InputLanguage DefaultInputLanguage {
  67. get {
  68. return default_input;
  69. }
  70. }
  71. public static InputLanguageCollection InstalledInputLanguages {
  72. get {
  73. return all;
  74. }
  75. }
  76. #endregion // Public Static Properties
  77. #region Public Instance Properties
  78. public CultureInfo Culture {
  79. get {
  80. return this.culture;
  81. }
  82. }
  83. public IntPtr Handle {
  84. get {
  85. return this.handle;
  86. }
  87. }
  88. public string LayoutName {
  89. get {
  90. return this.layout_name;
  91. }
  92. }
  93. #endregion // Public Instance Properties
  94. #region Public Static Methods
  95. public static InputLanguage FromCulture(System.Globalization.CultureInfo culture) {
  96. foreach (InputLanguage c in all) {
  97. if (culture.EnglishName==c.culture.EnglishName) {
  98. return new InputLanguage(c.handle, c.culture, c.layout_name);
  99. }
  100. }
  101. return new InputLanguage(all[0].handle, all[0].culture, all[0].layout_name);
  102. }
  103. #endregion // Public Static Methods
  104. #region Public Instance Methods
  105. public override bool Equals(object value) {
  106. if (value is InputLanguage) {
  107. if ((((InputLanguage)value).culture==this.culture) && (((InputLanguage)value).handle==this.handle) && (((InputLanguage)value).layout_name==this.layout_name)) {
  108. return true;
  109. }
  110. }
  111. return false;
  112. }
  113. public override int GetHashCode() {
  114. return base.GetHashCode();
  115. }
  116. #endregion // Public Instance Methods
  117. }
  118. }