2007-01-07 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.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                 internal 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                 [MonoTODO("Pull Microsofts InputLanguages and enter them here")]
42                 internal InputLanguage() {
43                         if (all == null) {
44                                 all = new InputLanguageCollection();
45
46                                 all.Add(new InputLanguage(IntPtr.Zero, new CultureInfo(""), "US"));
47                         }
48                         if (default_input == null) {
49                                 default_input=InputLanguage.FromCulture(CultureInfo.CurrentUICulture);
50                         }
51
52                         if (current_input == null) {
53                                 current_input=InputLanguage.FromCulture(CultureInfo.CurrentUICulture);
54                         }
55                 }
56
57                 internal InputLanguage(IntPtr handle, CultureInfo culture, string layout_name) : this() {
58                         this.handle=handle;
59                         this.culture=culture;
60                         this.layout_name=layout_name;
61                 }
62                 #endregion      // Private Constructor
63
64                 #region Public Static Properties
65                 public static InputLanguage CurrentInputLanguage {
66                         get {
67                                 return current_input;
68                         }
69
70                         set {
71                                 if (all.Contains(value)) {
72                                         current_input=value;
73                                 }
74                         }
75                 }
76
77                 public static InputLanguage DefaultInputLanguage {
78                         get {
79                                 return default_input;
80                         }
81                 }
82
83                 public static InputLanguageCollection InstalledInputLanguages {
84                         get {
85                                 return all;
86                         }
87                 }
88                 #endregion      // Public Static Properties
89
90                 #region Public Instance Properties
91                 public CultureInfo Culture {
92                         get {
93                                 return this.culture;
94                         }
95                 }
96
97                 public IntPtr Handle {
98                         get {
99                                 return this.handle;
100                         }
101                 }
102
103                 public string LayoutName {
104                         get {
105                                 return this.layout_name;
106                         }
107                 }
108                 #endregion      // Public Instance Properties
109
110                 #region Public Static Methods
111                 public static InputLanguage FromCulture(System.Globalization.CultureInfo culture) {
112                         foreach (InputLanguage c in all) {
113                                 if (culture.EnglishName==c.culture.EnglishName) {
114                                         return new InputLanguage(c.handle, c.culture, c.layout_name);
115                                 }
116                         }
117
118                         return new InputLanguage(all[0].handle, all[0].culture, all[0].layout_name);
119                 }
120                 #endregion      // Public Static Methods
121
122                 #region Public Instance Methods
123                 public override bool Equals(object value) {
124                         if (value is InputLanguage) {
125                                 if ((((InputLanguage)value).culture==this.culture) && (((InputLanguage)value).handle==this.handle) && (((InputLanguage)value).layout_name==this.layout_name)) {
126                                         return true;
127                                 }
128                         }
129                         return false;
130                 }
131
132                 public override int GetHashCode() {
133                         return base.GetHashCode();
134                 }
135                 #endregion      // Public Instance Methods
136         }
137 }