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