Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms.X11Internal / X11Display.cs
index 192a9a8313b5351c8ccd9d8bb210574188d26e58..43b39dcd4fc9a9d78ccc3fd62494fcc426ea1d42 100644 (file)
@@ -853,7 +853,64 @@ namespace System.Windows.Forms.X11Internal {
 
                        return cursor;
                }
+               
+               public Bitmap DefineStdCursorBitmap (StdCursor id)
+               {
+                       CursorFontShape shape;
+                       string name;
+                       IntPtr theme;
+                       int size;
+                       Bitmap bmp = null;
+
+                       try {
+                               shape = XplatUIX11.StdCursorToFontShape (id);
+                               name = shape.ToString ().Replace ("XC_", string.Empty);
+                               size = XplatUIX11.XcursorGetDefaultSize (Handle);
+                               theme = XplatUIX11.XcursorGetTheme (Handle);
+                               IntPtr images_ptr = XplatUIX11.XcursorLibraryLoadImages (name, theme, size);
+#if debug
+                               Console.WriteLine ("DefineStdCursorBitmap, id={0}, #id={1}, name{2}, size={3}, theme: {4}, images_ptr={5}", id, (int) id, name, size, Marshal.PtrToStringAnsi (theme), images_ptr);
+#endif
+
+                               if (images_ptr == IntPtr.Zero) {
+                                       return null;
+                               }
+
+                               XcursorImages images = (XcursorImages)Marshal.PtrToStructure (images_ptr, typeof (XcursorImages));
+#if debug
+                               Console.WriteLine ("DefineStdCursorBitmap, cursor has {0} images", images.nimage);
+#endif
+
+                               if (images.nimage > 0) {
+                                       // We only care about the first image.
+                                       XcursorImage image = (XcursorImage)Marshal.PtrToStructure (Marshal.ReadIntPtr (images.images), typeof (XcursorImage));
+
+#if debug
+                                       Console.WriteLine ("DefineStdCursorBitmap, loaded image <size={0}, height={1}, width={2}, xhot={3}, yhot={4}, pixels={5}", image.size, image.height, image.width, image.xhot, image.yhot, image.pixels);
+#endif
+                                       // A sanity check
+                                       if (image.width <= short.MaxValue && image.height <= short.MaxValue) {
+                                               int [] pixels = new int [image.width * image.height];
+                                               Marshal.Copy (image.pixels, pixels, 0, pixels.Length);
+                                               bmp = new Bitmap (image.width, image.height);
+                                               for (int w = 0; w < image.width; w++) {
+                                                       for (int h = 0; h < image.height; h++) {
+                                                               bmp.SetPixel (w, h, Color.FromArgb (pixels [h * image.width + w]));
+                                                       }
+                                               }
+                                       }
+                               }
+
+                               XplatUIX11.XcursorImagesDestroy (images_ptr);
 
+                       } catch (DllNotFoundException ex) {
+                               Console.WriteLine ("Could not load libXcursor: " + ex.Message + " (" + ex.GetType ().Name + ")");
+                               return null;
+                       }
+
+                       return bmp;
+               }
+               
                public IntPtr DefineStdCursor (StdCursor id)
                {
                        CursorFontShape shape;
@@ -1152,7 +1209,7 @@ namespace System.Windows.Forms.X11Internal {
                                // of ours but not the modal one, switch back to the modal window
 
                                if (ActiveWindow != null &&
-                                   NativeWindow.FindWindow (ActiveWindow.Handle) != null) {
+                                   NativeWindow.FromHandle (ActiveWindow.Handle) != null) {
                                        if (ActiveWindow != (X11Hwnd)ModalWindows.Peek())
                                                ((X11Hwnd)ModalWindows.Peek()).Activate ();
                                }
@@ -1440,7 +1497,7 @@ namespace System.Windows.Forms.X11Internal {
                }
 
 
-               public PaintEventArgs PaintEventStart (IntPtr handle, bool client)
+               public PaintEventArgs PaintEventStart (ref Message m, IntPtr handle, bool client)
                {
                        X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
 
@@ -1449,14 +1506,14 @@ namespace System.Windows.Forms.X11Internal {
                                HideCaret();
                        }
 
-                       return hwnd.PaintEventStart (client);
+                       return hwnd.PaintEventStart (ref m, client);
                }
 
-               public void PaintEventEnd (IntPtr handle, bool client)
+               public void PaintEventEnd (ref Message m, IntPtr handle, bool client)
                {
                        X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
 
-                       hwnd.PaintEventEnd (client);
+                       hwnd.PaintEventEnd (ref m, client);
 
                        if (Caret.Visible == true) {
                                ShowCaret();
@@ -1906,8 +1963,6 @@ namespace System.Windows.Forms.X11Internal {
 
                                switch (xevent.type) {
                                case XEventName.KeyPress:
-                                       if (Dnd.InDrag ())
-                                               Dnd.HandleKeyPress (ref xevent);
                                        Keyboard.KeyEvent (FocusWindow.Handle, xevent, ref msg);
                                        return true;
 
@@ -2027,12 +2082,6 @@ namespace System.Windows.Forms.X11Internal {
                                }
 
                                case XEventName.ButtonRelease:
-                                       if (Dnd.InDrag()) {
-                                               if (Dnd.HandleButtonRelease (ref xevent))
-                                                       return true;
-                                               // Don't return here, so that the BUTTONUP message can get through
-                                       }
-
                                        switch(xevent.ButtonEvent.button) {
                                        case 1:
                                                if (client) {
@@ -2110,9 +2159,6 @@ namespace System.Windows.Forms.X11Internal {
                                                                  xevent.MotionEvent.x, xevent.MotionEvent.y);
 #endif
 
-                                               if (Dnd.HandleMotionNotify (ref xevent))
-                                                       goto ProcessNextMessage;
-
                                                if (Grab.Hwnd != IntPtr.Zero)
                                                        msg.hwnd = Grab.Hwnd;
                                                else
@@ -2593,6 +2639,9 @@ namespace System.Windows.Forms.X11Internal {
 
                public void DrawReversibleLine (Point start, Point end, Color backColor)
                {
+                       if (backColor.GetBrightness() < 0.5)
+                               backColor = Color.FromArgb(255 - backColor.R, 255 - backColor.G, 255 - backColor.B);
+
                        IntPtr gc = GetReversibleScreenGC (backColor);
 
                        Xlib.XDrawLine (display, RootWindow.Handle, gc, start.X, start.Y, end.X, end.Y);
@@ -2602,6 +2651,9 @@ namespace System.Windows.Forms.X11Internal {
 
                public void FillReversibleRectangle (Rectangle rectangle, Color backColor)
                {
+                       if (backColor.GetBrightness() < 0.5)
+                               backColor = Color.FromArgb(255 - backColor.R, 255 - backColor.G, 255 - backColor.B);
+
                        IntPtr gc = GetReversibleScreenGC (backColor);
 
                        if (rectangle.Width < 0) {
@@ -2620,6 +2672,9 @@ namespace System.Windows.Forms.X11Internal {
 
                public void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style)
                {
+                       if (backColor.GetBrightness() < 0.5)
+                               backColor = Color.FromArgb(255 - backColor.R, 255 - backColor.G, 255 - backColor.B);
+
                        IntPtr gc = GetReversibleScreenGC (backColor);
 
                        if (rectangle.Width < 0) {