Rename Managed.Windows.Forms to System.Windows.Forms for consistency.
[mono.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / InputLanguage.cs
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    pbartok@novell.com
24 //
25
26
27 // NOT COMPLETE
28
29 using System.Globalization;
30
31 namespace System.Windows.Forms {
32         public sealed class InputLanguage {
33                 private static InputLanguageCollection  all;
34                 private IntPtr                  handle;
35                 private CultureInfo             culture;
36                 private string                  layout_name;
37                 private static InputLanguage    current_input;
38                 private static InputLanguage    default_input;
39
40                 #region Private Constructor
41                 [MonoInternalNote ("Pull Microsofts InputLanguages and enter them here")]
42                 internal InputLanguage()
43                 {
44                 }
45
46                 internal InputLanguage(IntPtr handle, CultureInfo culture, string layout_name) : this() {
47                         this.handle=handle;
48                         this.culture=culture;
49                         this.layout_name=layout_name;
50                 }
51                 #endregion      // Private Constructor
52
53                 #region Public Static Properties
54                 public static InputLanguage CurrentInputLanguage {
55                         get {
56                                 if (current_input == null)
57                                         current_input = InputLanguage.FromCulture (CultureInfo.CurrentUICulture);
58                                 return current_input;
59                         }
60
61                         set {
62                                 if (InstalledInputLanguages.Contains (value))
63                                         current_input = value;
64                         }
65                 }
66
67                 public static InputLanguage DefaultInputLanguage {
68                         get {
69                                 if (default_input == null)
70                                         default_input = InputLanguage.FromCulture (CultureInfo.CurrentUICulture);
71
72                                 return default_input;
73                         }
74                 }
75
76                 public static InputLanguageCollection InstalledInputLanguages {
77                         get {
78                                 if (all == null)
79                                         all = new InputLanguageCollection (new InputLanguage[] { new InputLanguage (IntPtr.Zero, new CultureInfo(string.Empty), "US") });
80
81                                 return all;
82                         }
83                 }
84                 #endregion      // Public Static Properties
85
86                 #region Public Instance Properties
87                 public CultureInfo Culture {
88                         get {
89                                 return this.culture;
90                         }
91                 }
92
93                 public IntPtr Handle {
94                         get {
95                                 return this.handle;
96                         }
97                 }
98
99                 public string LayoutName {
100                         get {
101                                 return this.layout_name;
102                         }
103                 }
104                 #endregion      // Public Instance Properties
105
106                 #region Public Static Methods
107                 public static InputLanguage FromCulture(System.Globalization.CultureInfo culture) {
108                         foreach (InputLanguage c in InstalledInputLanguages) {
109                                 if (culture.EnglishName==c.culture.EnglishName) {
110                                         return new InputLanguage(c.handle, c.culture, c.layout_name);
111                                 }
112                         }
113
114                         return new InputLanguage (InstalledInputLanguages[0].handle, InstalledInputLanguages[0].culture, InstalledInputLanguages[0].layout_name);
115                 }
116                 #endregion      // Public Static Methods
117
118                 #region Public Instance Methods
119                 public override bool Equals(object value) {
120                         if (value is InputLanguage) {
121                                 if ((((InputLanguage)value).culture==this.culture) && (((InputLanguage)value).handle==this.handle) && (((InputLanguage)value).layout_name==this.layout_name)) {
122                                         return true;
123                                 }
124                         }
125                         return false;
126                 }
127
128                 public override int GetHashCode() {
129                         return base.GetHashCode();
130                 }
131                 #endregion      // Public Instance Methods
132         }
133 }