Implement AxHost.InvalidActiveXStateException
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms.X11Internal / X11RootHwnd.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) 2006 Novell, Inc. (http://www.novell.com)
21 //
22 //
23
24 using System;
25 using System.Runtime.InteropServices;
26 using System.Windows.Forms;
27
28 namespace System.Windows.Forms.X11Internal {
29
30         internal class X11RootHwnd : X11Hwnd
31         {
32                 public X11RootHwnd (X11Display display, IntPtr window_handle) : base (display)
33                 {
34                         WholeWindow = ClientWindow = window_handle;
35
36                         Xlib.XSelectInput(display.Handle, WholeWindow, new IntPtr ((int)EventMask.PropertyChangeMask));
37                 }
38
39                 public override void CreateWindow (CreateParams cp)
40                 {
41                         // we don't do anything here
42                 }
43
44                 public override void PropertyChanged (XEvent xevent)
45                 {
46                         if (xevent.PropertyEvent.atom == Display.Atoms._NET_ACTIVE_WINDOW) {
47                                 IntPtr actual_atom;
48                                 int actual_format;
49                                 IntPtr nitems;
50                                 IntPtr bytes_after;
51                                 IntPtr prop = IntPtr.Zero;
52
53                                 Xlib.XGetWindowProperty (Display.Handle, WholeWindow,
54                                                          Display.Atoms._NET_ACTIVE_WINDOW, IntPtr.Zero, new IntPtr (1), false,
55                                                          Display.Atoms.XA_WINDOW, out actual_atom, out actual_format, out nitems, out bytes_after, ref prop);
56
57                                 if (((long)nitems > 0) && (prop != IntPtr.Zero)) {
58                                         // FIXME - is this 64 bit clean?
59                                         Display.SetActiveWindow ((X11Hwnd)Hwnd.ObjectFromHandle((IntPtr)Marshal.ReadInt32(prop)));
60                                         Xlib.XFree(prop);
61                                 }
62                         }
63                         else if (xevent.PropertyEvent.atom == Display.Atoms._NET_SUPPORTED) {
64                                 // we'll need to refetch the supported protocols list
65                                 refetch_net_supported = true;
66                                 _net_supported = null;
67                         }
68                         else
69                                 base.PropertyChanged (xevent);
70                 }
71
72                 bool refetch_net_supported = true;
73                 IntPtr[] _net_supported;
74                 public IntPtr[] _NET_SUPPORTED {
75                         get {
76                                 if (refetch_net_supported) {
77                                         _net_supported = GetAtomListProperty (Display.Atoms._NET_SUPPORTED);
78                                         refetch_net_supported = false;
79                                 }
80
81                                 return _net_supported;
82                         }
83                 }
84         }
85
86 }
87