/// <summary>
        ///  Creates a new clipping region from the intersection of the current clipping region and
        ///  the specified rectangle.
        /// </summary>
        public void IntersectClip(WindowsRegion wr)
        {
            //if the incoming windowsregion is infinite, there is no need to do any intersecting.
            if (wr.HRegion == IntPtr.Zero)
            {
                return;
            }

            WindowsRegion clip = new WindowsRegion(0, 0, 0, 0);

            try
            {
                int result = Gdi32.GetClipRgn(new HandleRef(this, Hdc), new HandleRef(clip, clip.HRegion));

                // If the function succeeds and there is a clipping region for the given device context, the return value is 1.
                if (result == 1)
                {
                    Debug.Assert(clip.HRegion != IntPtr.Zero);
                    wr.CombineRegion(clip, wr, Gdi32.CombineMode.RGN_AND);
                }

                SetClip(wr);
            }
            finally
            {
                clip.Dispose();
            }
        }
Exemple #2
0
 public void IntersectClip(WindowsRegion wr)
 {
     if (wr.HRegion != IntPtr.Zero)
     {
         using (WindowsRegion region = new WindowsRegion(0, 0, 0, 0))
         {
             if (IntUnsafeNativeMethods.GetClipRgn(new HandleRef(this, this.Hdc), new HandleRef(region, region.HRegion)) == 1)
             {
                 wr.CombineRegion(region, wr, RegionCombineMode.AND);
             }
             this.SetClip(wr);
         }
     }
 }
Exemple #3
0
        protected override void WndProc(ref Message m) {
            switch (m.Msg) {
                // We don't want to fire the focus events twice -
                // once in the combobox and once in the ChildWndProc.
                case NativeMethods.WM_SETFOCUS:
                    try {
                        fireSetFocus = false;
                        base.WndProc(ref m);
                    }
                        
                    finally {
                        fireSetFocus = true;
                    }
                    break;
                case NativeMethods.WM_KILLFOCUS:
                    try {
                        fireLostFocus = false;
                        base.WndProc(ref m);
                        // Nothing to see here... Just keep on walking... VSWhidbey 504477.
                        // Turns out that with Theming off, we don't get quite the same messages as with theming on.
                        
                        // With theming on we get a WM_MOUSELEAVE after a WM_KILLFOCUS even if you use the Tab key
                        // to move focus. Our response to WM_MOUSELEAVE causes us to repaint everything correctly.

                        // With theming off, we do not get a WM_MOUSELEAVE after a WM_KILLFOCUS, and since we don't have a childwndproc
                        // when we are a Flat DropDownList, we need to force a repaint. The easiest way to do this is to send a 
                        // WM_MOUSELEAVE to ourselves, since that also sets up the right state. Or... at least the state is the same
                        // as with Theming on.

                        // This is such a @#$(*&#@$ hack.
                        
                        if (!Application.RenderWithVisualStyles && GetStyle(ControlStyles.UserPaint) == false && this.DropDownStyle == ComboBoxStyle.DropDownList && (FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup)) {
                            UnsafeNativeMethods.PostMessage(new HandleRef(this, Handle), NativeMethods.WM_MOUSELEAVE, 0, 0);                            
                        }
                    }

                    finally {
                        fireLostFocus = true;
                    }
                    break;
                case NativeMethods.WM_CTLCOLOREDIT:
                case NativeMethods.WM_CTLCOLORLISTBOX:
                    m.Result = InitializeDCForWmCtlColor(m.WParam, m.Msg);
                    break;
                case NativeMethods.WM_ERASEBKGND:
                    WmEraseBkgnd(ref m);
                    break;
                case NativeMethods.WM_PARENTNOTIFY:
                    WmParentNotify(ref m);
                    break;
                case NativeMethods.WM_REFLECT + NativeMethods.WM_COMMAND:
                    WmReflectCommand(ref m);
                    break;
                case NativeMethods.WM_REFLECT + NativeMethods.WM_DRAWITEM:
                    WmReflectDrawItem(ref m);
                    break;
                case NativeMethods.WM_REFLECT + NativeMethods.WM_MEASUREITEM:
                    WmReflectMeasureItem(ref m);
                    break;
                case NativeMethods.WM_LBUTTONDOWN:
                    mouseEvents = true;
                    base.WndProc(ref m);
                    break;
                case NativeMethods.WM_LBUTTONUP:
                    // Get the mouse location
                    //
                    NativeMethods.RECT r = new NativeMethods.RECT();
                    UnsafeNativeMethods.GetWindowRect(new HandleRef(this, Handle), ref r);
                    Rectangle ClientRect = new Rectangle(r.left, r.top, r.right - r.left, r.bottom - r.top);

                    int x = NativeMethods.Util.SignedLOWORD(m.LParam);
                    int y = NativeMethods.Util.SignedHIWORD(m.LParam);
                    Point pt = new Point(x, y);
                    pt = PointToScreen(pt);
                    //mouseEvents is used to keep the check that we get the WM_LBUTTONUP after
                    //WM_LBUTTONDOWN or WM_LBUTTONDBLBCLK
                    // combo box gets a WM_LBUTTONUP for focus change ...
                    //
                    if (mouseEvents && !ValidationCancelled) {
                        mouseEvents = false;
                        bool captured = Capture;
                        if (captured && ClientRect.Contains(pt)) {
                            OnClick(new MouseEventArgs(MouseButtons.Left, 1, NativeMethods.Util.SignedLOWORD(m.LParam), NativeMethods.Util.SignedHIWORD(m.LParam), 0));
                            OnMouseClick(new MouseEventArgs(MouseButtons.Left, 1, NativeMethods.Util.SignedLOWORD(m.LParam), NativeMethods.Util.SignedHIWORD(m.LParam), 0));

                        }
                        base.WndProc(ref m);
                    }
                    else {
                        CaptureInternal = false;
                        DefWndProc(ref m);
                    }
                    break;

                case NativeMethods.WM_MOUSELEAVE:
                    DefWndProc(ref m);
                    OnMouseLeaveInternal(EventArgs.Empty);
                    break;

                case NativeMethods.WM_PAINT:
                    if (GetStyle(ControlStyles.UserPaint) == false && (FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup)) {

                        using (WindowsRegion dr = new WindowsRegion(FlatComboBoxAdapter.dropDownRect)) {
                            using (WindowsRegion wr = new WindowsRegion(this.Bounds)) {

                                // Stash off the region we have to update (the base is going to clear this off in BeginPaint)
                                NativeMethods.RegionFlags updateRegionFlags = (NativeMethods.RegionFlags)SafeNativeMethods.GetUpdateRgn(new HandleRef(this, this.Handle), new HandleRef(this, wr.HRegion), true);

                                dr.CombineRegion(wr, dr, RegionCombineMode.DIFF);

                                Rectangle updateRegionBoundingRect = wr.ToRectangle();
                                FlatComboBoxAdapter.ValidateOwnerDrawRegions(this, updateRegionBoundingRect);
                                // Call the base class to do its painting (with a clipped DC).

                                NativeMethods.PAINTSTRUCT ps = new NativeMethods.PAINTSTRUCT();
                                IntPtr dc;
                                bool disposeDc = false;
                                if (m.WParam == IntPtr.Zero) {
                                    dc = UnsafeNativeMethods.BeginPaint(new HandleRef(this, Handle), ref ps);
                                    disposeDc = true;
                                }
                                else {
                                    dc = m.WParam;
                                }

                                using (DeviceContext mDC = DeviceContext.FromHdc(dc)) {
                                    using (WindowsGraphics wg = new WindowsGraphics(mDC)) {
                                        if (updateRegionFlags != NativeMethods.RegionFlags.ERROR) {
                                            wg.DeviceContext.SetClip(dr);
                                        }
                                        m.WParam = dc;
                                        DefWndProc(ref m);
                                        if (updateRegionFlags != NativeMethods.RegionFlags.ERROR) {
                                            wg.DeviceContext.SetClip(wr);
                                        }
                                        using (Graphics g = Graphics.FromHdcInternal(dc)) {
                                            FlatComboBoxAdapter.DrawFlatCombo(this, g);
                                        }
                                    }
                                }

                                if (disposeDc) {
                                    UnsafeNativeMethods.EndPaint(new HandleRef(this, Handle), ref ps);
                                }

                            }
                            return;
                        }
                    }
                    
                    base.WndProc(ref m);
                    break;
                case NativeMethods.WM_PRINTCLIENT: 
                    // all the fancy stuff we do in OnPaint has to happen again in OnPrint.
                    if (GetStyle(ControlStyles.UserPaint) == false && FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup) {
                        DefWndProc(ref m);
                        
                        if ((unchecked( (int) (long)m.LParam) & NativeMethods.PRF_CLIENT) == NativeMethods.PRF_CLIENT) { 
                            if (GetStyle(ControlStyles.UserPaint) == false && FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup) {
                                using (Graphics g = Graphics.FromHdcInternal(m.WParam)) {
                                    FlatComboBoxAdapter.DrawFlatCombo(this,g);
                                }
                            }
                            return;
                        }
                    }
                    base.WndProc(ref m);
                    return;                    
                case NativeMethods.WM_SETCURSOR:
                    base.WndProc(ref m);
                    break;

                case NativeMethods.WM_SETFONT:
                    //(bug 119265)
                    if (Width == 0) {
                        suppressNextWindosPos = true;
                    }
                    base.WndProc(ref m);
                    break;


                case NativeMethods.WM_WINDOWPOSCHANGED:
                    if (!suppressNextWindosPos) {
                        base.WndProc(ref m);
                    }
                    suppressNextWindosPos = false;
                    break;

                case NativeMethods.WM_NCDESTROY:
                    base.WndProc(ref m);
                    ReleaseChildWindow();
                    break;
                    
                default:
                    if (m.Msg == NativeMethods.WM_MOUSEENTER) {
                        DefWndProc(ref m);
                        OnMouseEnterInternal(EventArgs.Empty);
                        break;
                    }
                    base.WndProc(ref m);
                    break;
            }
        }
 public void IntersectClip(WindowsRegion wr)
 {
     if (wr.HRegion != IntPtr.Zero)
     {
         using (WindowsRegion region = new WindowsRegion(0, 0, 0, 0))
         {
             if (IntUnsafeNativeMethods.GetClipRgn(new HandleRef(this, this.Hdc), new HandleRef(region, region.HRegion)) == 1)
             {
                 wr.CombineRegion(region, wr, RegionCombineMode.AND);
             }
             this.SetClip(wr);
         }
     }
 }
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 7:
                    try
                    {
                        this.fireSetFocus = false;
                        base.WndProc(ref m);
                        return;
                    }
                    finally
                    {
                        this.fireSetFocus = true;
                    }
                    break;

                case 8:
                    break;

                case 15:
                    if (!base.GetStyle(ControlStyles.UserPaint) && ((this.FlatStyle == System.Windows.Forms.FlatStyle.Flat) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Popup)))
                    {
                        using (WindowsRegion region = new WindowsRegion(this.FlatComboBoxAdapter.dropDownRect))
                        {
                            using (WindowsRegion region2 = new WindowsRegion(base.Bounds))
                            {
                                IntPtr wParam;
                                System.Windows.Forms.NativeMethods.RegionFlags flags = (System.Windows.Forms.NativeMethods.RegionFlags) System.Windows.Forms.SafeNativeMethods.GetUpdateRgn(new HandleRef(this, base.Handle), new HandleRef(this, region2.HRegion), true);
                                region.CombineRegion(region2, region, RegionCombineMode.DIFF);
                                Rectangle updateRegionBox = region2.ToRectangle();
                                this.FlatComboBoxAdapter.ValidateOwnerDrawRegions(this, updateRegionBox);
                                System.Windows.Forms.NativeMethods.PAINTSTRUCT lpPaint = new System.Windows.Forms.NativeMethods.PAINTSTRUCT();
                                bool flag2 = false;
                                if (m.WParam == IntPtr.Zero)
                                {
                                    wParam = System.Windows.Forms.UnsafeNativeMethods.BeginPaint(new HandleRef(this, base.Handle), ref lpPaint);
                                    flag2 = true;
                                }
                                else
                                {
                                    wParam = m.WParam;
                                }
                                using (DeviceContext context = DeviceContext.FromHdc(wParam))
                                {
                                    using (WindowsGraphics graphics = new WindowsGraphics(context))
                                    {
                                        if (flags != System.Windows.Forms.NativeMethods.RegionFlags.ERROR)
                                        {
                                            graphics.DeviceContext.SetClip(region);
                                        }
                                        m.WParam = wParam;
                                        this.DefWndProc(ref m);
                                        if (flags != System.Windows.Forms.NativeMethods.RegionFlags.ERROR)
                                        {
                                            graphics.DeviceContext.SetClip(region2);
                                        }
                                        using (Graphics graphics2 = Graphics.FromHdcInternal(wParam))
                                        {
                                            this.FlatComboBoxAdapter.DrawFlatCombo(this, graphics2);
                                        }
                                    }
                                }
                                if (flag2)
                                {
                                    System.Windows.Forms.UnsafeNativeMethods.EndPaint(new HandleRef(this, base.Handle), ref lpPaint);
                                }
                            }
                            return;
                        }
                    }
                    base.WndProc(ref m);
                    return;

                case 20:
                    this.WmEraseBkgnd(ref m);
                    return;

                case 0x47:
                    if (!this.suppressNextWindosPos)
                    {
                        base.WndProc(ref m);
                    }
                    this.suppressNextWindosPos = false;
                    return;

                case 130:
                    base.WndProc(ref m);
                    this.ReleaseChildWindow();
                    return;

                case 0x20:
                    base.WndProc(ref m);
                    return;

                case 0x30:
                    if (base.Width == 0)
                    {
                        this.suppressNextWindosPos = true;
                    }
                    base.WndProc(ref m);
                    return;

                case 0x133:
                case 0x134:
                    goto Label_017F;

                case 0x201:
                    this.mouseEvents = true;
                    base.WndProc(ref m);
                    return;

                case 0x202:
                {
                    System.Windows.Forms.NativeMethods.RECT rect = new System.Windows.Forms.NativeMethods.RECT();
                    System.Windows.Forms.UnsafeNativeMethods.GetWindowRect(new HandleRef(this, base.Handle), ref rect);
                    Rectangle rectangle = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
                    int x = System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam);
                    int y = System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam);
                    Point p = new Point(x, y);
                    p = base.PointToScreen(p);
                    if (this.mouseEvents && !base.ValidationCancelled)
                    {
                        this.mouseEvents = false;
                        if (base.Capture && rectangle.Contains(p))
                        {
                            this.OnClick(new MouseEventArgs(MouseButtons.Left, 1, System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam), 0));
                            this.OnMouseClick(new MouseEventArgs(MouseButtons.Left, 1, System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam), 0));
                        }
                        base.WndProc(ref m);
                        return;
                    }
                    base.CaptureInternal = false;
                    this.DefWndProc(ref m);
                    return;
                }
                case 0x210:
                    this.WmParentNotify(ref m);
                    return;

                case 0x202b:
                    this.WmReflectDrawItem(ref m);
                    return;

                case 0x202c:
                    this.WmReflectMeasureItem(ref m);
                    return;

                case 0x2111:
                    this.WmReflectCommand(ref m);
                    return;

                case 0x2a3:
                    this.DefWndProc(ref m);
                    this.OnMouseLeaveInternal(EventArgs.Empty);
                    return;

                case 0x318:
                    if ((base.GetStyle(ControlStyles.UserPaint) || (this.FlatStyle != System.Windows.Forms.FlatStyle.Flat)) && (this.FlatStyle != System.Windows.Forms.FlatStyle.Popup))
                    {
                        goto Label_04EF;
                    }
                    this.DefWndProc(ref m);
                    if ((((int) ((long) m.LParam)) & 4) != 4)
                    {
                        goto Label_04EF;
                    }
                    if ((!base.GetStyle(ControlStyles.UserPaint) && (this.FlatStyle == System.Windows.Forms.FlatStyle.Flat)) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Popup))
                    {
                        using (Graphics graphics3 = Graphics.FromHdcInternal(m.WParam))
                        {
                            this.FlatComboBoxAdapter.DrawFlatCombo(this, graphics3);
                        }
                    }
                    return;

                default:
                    if (m.Msg == System.Windows.Forms.NativeMethods.WM_MOUSEENTER)
                    {
                        this.DefWndProc(ref m);
                        this.OnMouseEnterInternal(EventArgs.Empty);
                        return;
                    }
                    base.WndProc(ref m);
                    return;
            }
            try
            {
                this.fireLostFocus = false;
                base.WndProc(ref m);
                if (((!Application.RenderWithVisualStyles && !base.GetStyle(ControlStyles.UserPaint)) && (this.DropDownStyle == ComboBoxStyle.DropDownList)) && ((this.FlatStyle == System.Windows.Forms.FlatStyle.Flat) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Popup)))
                {
                    System.Windows.Forms.UnsafeNativeMethods.PostMessage(new HandleRef(this, base.Handle), 0x2a3, 0, 0);
                }
                return;
            }
            finally
            {
                this.fireLostFocus = true;
            }
        Label_017F:
            m.Result = this.InitializeDCForWmCtlColor(m.WParam, m.Msg);
            return;
        Label_04EF:
            base.WndProc(ref m);
        }