[winforms] Small optimizations, use properties that do not compute values
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms.CarbonInternal / ControlHandler.cs
index 04ea3e963f5024c63397fca0f0019999eac6187e..9064c27291aa6eb374a2363e3d191241539d2824 100644 (file)
@@ -86,14 +86,18 @@ namespace System.Windows.Forms.CarbonInternal {
                internal const uint kEventParamCGContextRef = 1668183160;
                internal const uint kEventParamDirectObject = 757935405;
                internal const uint kEventParamControlPart = 1668313716;
+               internal const uint kEventParamControlLikesDrag = 1668047975;
+               internal const uint kEventParamRgnHandle = 1919381096;
                internal const uint typeControlRef = 1668575852;
                internal const uint typeCGContextRef = 1668183160;
                internal const uint typeQDPoint = 1363439732;
+               internal const uint typeQDRgnHandle = 1919381096;
                internal const uint typeControlPartCode = 1668313716;
+               internal const uint typeBoolean = 1651470188;
 
                internal ControlHandler (XplatUICarbon driver) : base (driver) {}
 
-               public bool ProcessEvent (IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
+               public bool ProcessEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
                        Hwnd hwnd;
                        bool client;
 
@@ -108,11 +112,22 @@ namespace System.Windows.Forms.CarbonInternal {
 
                        switch (kind) {
                                case kEventControlDraw: {
-                                       //FIXME: This is a hack which masks our over-redraw-expose problem
-                                       if (client) {
-                                               HIRect bounds = new HIRect ();
+                                       IntPtr rgn = IntPtr.Zero;
+                                       HIRect bounds = new HIRect ();
+                               
+                                       GetEventParameter (eventref, kEventParamRgnHandle, typeQDRgnHandle, IntPtr.Zero, (uint) Marshal.SizeOf (typeof (IntPtr)), IntPtr.Zero, ref rgn);
+
+                                       if (rgn != IntPtr.Zero) {
+                                               Rect rbounds = new Rect ();
+                                               
+                                               GetRegionBounds (rgn, ref rbounds);
+                                               
+                                               bounds.origin.x = rbounds.left;
+                                               bounds.origin.y = rbounds.top;
+                                               bounds.size.width = rbounds.right - rbounds.left;
+                                               bounds.size.height = rbounds.bottom - rbounds.top;
+                                       } else {
                                                HIViewGetBounds (handle, ref bounds);
-                                               Driver.AddExpose (hwnd, client, bounds);
                                        }
 
                                        if (!hwnd.visible) {
@@ -124,31 +139,15 @@ namespace System.Windows.Forms.CarbonInternal {
                                                 return false;
                                        }
 
-                                       if (client) {
-                                               if (!hwnd.expose_pending) {
-                                                       return false;
-                                               }
-                                                msg.message = Msg.WM_PAINT;
-                                       } else {
-                                               if (!hwnd.nc_expose_pending) {
-                                                       return false;
-                                               }
-                                               //DrawBackground here
+                                       if (!client) {
                                                DrawBorders (hwnd);
-                                               Region region = new Region (hwnd.Invalid);
-                                               IntPtr hrgn = region.GetHrgn (null); // Graphics object isn't needed
-                                               msg.message = Msg.WM_NCPAINT;
-                                               msg.wParam = hrgn == IntPtr.Zero ? (IntPtr)1 : hrgn;
-                                               msg.refobject = region;
-                                               
                                        }
+
+                                       Driver.AddExpose (hwnd, client, bounds);
+
                                        return true;
                                }
                                case kEventControlVisibilityChanged: {
-                                       HIRect bounds = new HIRect ();
-
-                                       HIViewGetBounds (handle, ref bounds);
-                                       Driver.AddExpose (hwnd, client, bounds);
                                        if (client) {
                                                msg.message = Msg.WM_SHOWWINDOW;
                                                msg.lParam = (IntPtr) 0;
@@ -168,29 +167,26 @@ namespace System.Windows.Forms.CarbonInternal {
                                                hwnd.Height = (int) view_frame.size.height;
                                                Driver.PerformNCCalc (hwnd);
                                        }
-                                       return false;
+
+                                       msg.message = Msg.WM_WINDOWPOSCHANGED;
+                                       msg.hwnd = hwnd.Handle;
+
+                                       return true;
                                }
                                case kEventControlGetFocusPart: {
                                        short pcode = 0;
                                        SetEventParameter (eventref, kEventParamControlPart, typeControlPartCode, (uint)Marshal.SizeOf (typeof (short)), ref pcode);
                                        return false;
                                }
+                               case kEventControlDragEnter: 
+                               case kEventControlDragWithin: 
+                               case kEventControlDragLeave: 
+                               case kEventControlDragReceive: 
+                                       return Dnd.HandleEvent (callref, eventref, handle, kind, ref msg);
                        }
                        return false;
                }
 
-               private void DrawBackground (Hwnd hwnd, IntPtr eventref, HIRect bounds) {
-                       if (XplatUICarbon.WindowBackgrounds [hwnd] != null) {
-                               IntPtr context = IntPtr.Zero;
-                               Color color = (Color) XplatUICarbon.WindowBackgrounds [hwnd];
-
-                               GetEventParameter (eventref, kEventParamCGContextRef, typeCGContextRef, IntPtr.Zero, (uint) Marshal.SizeOf (typeof (IntPtr)), IntPtr.Zero, ref context); 
-                               
-                               CGContextSetRGBFillColor (context, (float) color.R / 255, (float) color.G / 255, (float) color.B / 255, (float) color.A / 255);
-                               CGContextFillRect (context, bounds);
-                       }
-               }
-
                private void DrawBorders (Hwnd hwnd) {
                        switch (hwnd.border_style) {
                                case FormBorderStyle.Fixed3D: {
@@ -216,6 +212,8 @@ namespace System.Windows.Forms.CarbonInternal {
                        }
                }
                        
+               [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+               static extern int GetRegionBounds (IntPtr rgnhandle, ref Rect region);
                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
                static extern int GetEventParameter (IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, IntPtr outsize, ref IntPtr data);
                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
@@ -227,11 +225,5 @@ namespace System.Windows.Forms.CarbonInternal {
                static extern int HIViewGetFrame (IntPtr handle, ref HIRect rect);
                [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
                extern static bool HIViewIsVisible (IntPtr vHnd);
-
-               [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
-               static extern int CGContextSetRGBFillColor (IntPtr cgContext, float r, float g, float b, float alpha);
-               [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
-               static extern int CGContextFillRect (IntPtr context, HIRect rect);
-
        }
 }