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