BindingFlags.Public needed here as Exception.HResult is now public in .NET 4.5. This...
[mono.git] / mcs / class / System / Microsoft.Win32 / SystemEvents.cs
1 //
2 // Microsoft.Win32.SystemEvents.cs
3 //
4 // Authors:
5 //   Johannes Roith (johannes@jroith.de)
6 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) 2002 Johannes Roith
9 // (C) 2003 Andreas Nahr
10 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System;
33 using System.Collections;
34 using System.ComponentModel;
35 using System.Security.Permissions;
36 using System.Timers;
37
38 namespace Microsoft.Win32 {
39
40         [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
41         public sealed class SystemEvents 
42         {
43                 private static Hashtable TimerStore = new Hashtable ();
44
45                 private SystemEvents ()
46                 {
47                 }
48
49                 // You can use timers using the CreateTimer, KillTimer methods and the Timerelapsed event
50                 // This is only a partial solution, as it only works in managed code.
51                 // TODO implement this on OS level
52                 // Till done this solution should work if you are only using the mentioned members
53
54                 public static IntPtr CreateTimer (int interval)
55                 {
56                         Guid Ident = Guid.NewGuid ();
57                         int IdentValue = Ident.GetHashCode ();
58                         Timer t = new System.Timers.Timer (interval);
59                         t.Elapsed += new ElapsedEventHandler (InternalTimerElapsed);
60                         TimerStore.Add (IdentValue, t);
61                         return new IntPtr (IdentValue);
62                 }
63
64                 public static void KillTimer (IntPtr timerId)
65                 {
66                         Timer t = (Timer) TimerStore[timerId.GetHashCode()];
67                         t.Stop ();
68                         t.Elapsed -= new ElapsedEventHandler (InternalTimerElapsed);
69                         t.Dispose ();
70                         TimerStore.Remove (timerId.GetHashCode());
71                 }
72
73                 private static void InternalTimerElapsed (object e, ElapsedEventArgs args)
74                 {
75                         if (TimerElapsed != null)
76                                 TimerElapsed (null, new TimerElapsedEventArgs (IntPtr.Zero));
77                 }
78
79                 [MonoTODO]
80                 public static void InvokeOnEventsThread(Delegate method)
81                 {
82                         throw new System.NotImplementedException ();
83                 }
84
85                 [MonoTODO]
86                 public static event System.EventHandler DisplaySettingsChanged 
87                 {
88                         add     { }
89                         remove  { }
90                 }
91                 [MonoTODO("Currently does nothing on Mono")]
92                 public static event EventHandler DisplaySettingsChanging {
93                         add {  }
94                         remove { }
95                 }
96                 [MonoTODO("Currently does nothing on Mono")]
97                 public static event System.EventHandler EventsThreadShutdown 
98                 {
99                         add     { }
100                         remove  { }
101                 }
102
103                 [MonoTODO("Currently does nothing on Mono")]
104                 public static event System.EventHandler InstalledFontsChanged 
105                 {
106                         add     { }
107                         remove  { }
108                 }
109
110                 [MonoTODO("Currently does nothing on Mono")]
111 #if NET_2_0
112                 [Browsable (false)]
113                 [EditorBrowsable (EditorBrowsableState.Never)]
114                 [Obsolete ("")]
115 #endif
116                 public static event System.EventHandler LowMemory 
117                 {
118                         add     { }
119                         remove  { }
120                 }
121
122                 [MonoTODO("Currently does nothing on Mono")]
123                 public static event System.EventHandler PaletteChanged 
124                 {
125                         add     { }
126                         remove  { }
127                 }
128
129                 [MonoTODO("Currently does nothing on Mono")]
130                 public static event PowerModeChangedEventHandler PowerModeChanged 
131                 {
132                         add     { }
133                         remove  { }
134                 }
135
136                 [MonoTODO("Currently does nothing on Mono")]
137                 public static event SessionEndedEventHandler SessionEnded 
138                 {
139                         add     { }
140                         remove  { }
141                 }
142
143                 [MonoTODO("Currently does nothing on Mono")]
144                 public static event SessionEndingEventHandler SessionEnding 
145                 {
146                         add     { }
147                         remove  { }
148                 }
149 #if NET_2_0
150                 [MonoTODO("Currently does nothing on Mono")]
151                 public static event SessionSwitchEventHandler SessionSwitch {
152                         add    { }
153                         remove { }
154                 }
155 #endif
156                 [MonoTODO("Currently does nothing on Mono")]
157                 public static event System.EventHandler TimeChanged 
158                 {
159                         add     { }
160                         remove  { }
161                 }
162
163                 public static event TimerElapsedEventHandler TimerElapsed;
164
165                 [MonoTODO("Currently does nothing on Mono")]
166                 public static event UserPreferenceChangedEventHandler UserPreferenceChanged 
167                 {
168                         add     { }
169                         remove  { }
170                 }
171
172                 [MonoTODO("Currently does nothing on Mono")]
173                 public static event UserPreferenceChangingEventHandler UserPreferenceChanging 
174                 {
175                         add     { }
176                         remove  { }
177                 }
178         }
179 }