private NativeMethods.RECT[] CreateScrollableRegion(Rectangle scroll) 
        {
            if (this.cachedScrollableRegion != null) 
            {
                return this.cachedScrollableRegion;
            }

            using (Region region = new Region(scroll))
            {
                IntPtr handle = IntPtr.Zero;
                using (Graphics graphics = CreateGraphicsInternal())
                {
                    handle = region.GetHrgn(graphics);
                }
                if (handle != IntPtr.Zero)
                {
                    this.cachedScrollableRegion = UnsafeNativeMethods.GetRectsFromRegion(handle);

                    // SECREVIEW : This assert is safe since we created the native region.
                    //
                    IntSecurity.ObjectFromWin32Handle.Assert();
                    try
                    {
                        region.ReleaseHrgn(handle);
                    }
                    finally
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }
            return this.cachedScrollableRegion;
        }
Exemplo n.º 2
0
		public void ReleaseHrng_Zero ()
		{
			Region r = new Region (new GraphicsPath ());
			r.ReleaseHrgn (IntPtr.Zero);
		}
Exemplo n.º 3
0
		public void ReleaseHrng ()
		{
			Region r = new Region (new GraphicsPath ());
			IntPtr ptr = r.GetHrgn (graphic);
			Assert.IsFalse (IntPtr.Zero == ptr, "ptr");
			r.ReleaseHrgn (ptr);
		}
Exemplo n.º 4
0
		public void GetHrgn_TwiceFromSameRegionInstance ()
		{
			Region r = new Region (new GraphicsPath ());
			IntPtr h1 = r.GetHrgn (graphic);
			IntPtr h2 = r.GetHrgn (graphic);
			Assert.IsFalse (h1 == h2, "Handle_1!=Handle_2");
			r.ReleaseHrgn (h1);
			r.ReleaseHrgn (h2);
		}
Exemplo n.º 5
0
		public void GetHrgn_FromHrgn ()
		{
			Region r1 = new Region (new GraphicsPath ());
			IntPtr h1 = r1.GetHrgn (graphic);
			Assert.IsFalse (h1 == IntPtr.Zero, "Handle_1!=0");

			Region r2 = Region.FromHrgn (h1);
			IntPtr h2 = r2.GetHrgn (graphic);
			Assert.IsFalse (h2 == IntPtr.Zero, "Handle_2!=0");
			Assert.IsFalse (h1 == h2, "Handle_1!=Handle_2");
			r1.ReleaseHrgn (h1);
			r2.ReleaseHrgn (h2);
		}
Exemplo n.º 6
0
		public void GetHrgn_Empty_MakeInfinite ()
		{
			Region r = new Region (new GraphicsPath ());
			Assert.IsTrue (r.IsEmpty (graphic), "Empty");
			Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
			IntPtr h = r.GetHrgn (graphic);
			Assert.IsFalse (h == IntPtr.Zero, "Handle!=0");

			r.MakeInfinite ();
			Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
			Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
			Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");
			r.ReleaseHrgn (h);
		}
Exemplo n.º 7
0
        /// <summary>
        /// Redraws the non client area.
        /// </summary>
        /// <param name="invalidateBuffer">if set to <c>true</c> the buffer is invalidated.</param>
        /// <returns>true if the original painting should be suppressed otherwise false.</returns>
        private bool NcPaint(bool invalidateBuffer)
        {
            if (!IsProcessNcArea)
                return false;
            bool result = false;

            IntPtr hdc = (IntPtr)0;
            Graphics g = null;
            Region region = null;
            IntPtr hrgn = (IntPtr)0;

            try
            {
                // no drawing needed
                if (_parentForm.MdiParent != null && _parentForm.WindowState == FormWindowState.Maximized)
                {
                    _currentCacheSize = Size.Empty;
                    return false;
                }

                // prepare image bounds
                Size borderSize = FormExtenders.GetBorderSize(_parentForm);
                int captionHeight = FormExtenders.GetCaptionHeight(_parentForm);

                RECT rectScreen = new RECT();
                Win32Api.GetWindowRect(_parentForm.Handle, ref rectScreen);

                Rectangle rectBounds = rectScreen.ToRectangle();
                rectBounds.Offset(-rectBounds.X, -rectBounds.Y);

                // prepare clipping
                Rectangle rectClip = rectBounds;
                region = new Region(rectClip);
                rectClip.Inflate(-borderSize.Width, -borderSize.Height);
                rectClip.Y += captionHeight;
                rectClip.Height -= captionHeight;

                // create graphics handle
                hdc = Win32Api.GetDCEx(_parentForm.Handle, (IntPtr)0,
                    (DCXFlags.DCX_CACHE | DCXFlags.DCX_CLIPSIBLINGS | DCXFlags.DCX_WINDOW));
                g = Graphics.FromHdc(hdc);

                // Apply clipping
                region.Exclude(rectClip);
                hrgn = region.GetHrgn(g);
                Win32Api.SelectClipRgn(hdc, hrgn);

                // create new buffered graphics if needed
                if (_bufferGraphics == null || _currentCacheSize != rectBounds.Size)
                {
                    if (_bufferGraphics != null)
                        _bufferGraphics.Dispose();

                    _bufferGraphics = _bufferContext.Allocate(g, new Rectangle(0, 0,
                                rectBounds.Width, rectBounds.Height));
                    _currentCacheSize = rectBounds.Size;
                    invalidateBuffer = true;
                }

                if (invalidateBuffer)
                {
                    // Create painting meta data for form
                    SkinningFormPaintData paintData = new SkinningFormPaintData(_bufferGraphics.Graphics, rectBounds)
                    {
                        Borders = borderSize,
                        CaptionHeight = captionHeight,
                        Active = _formIsActive,
                        HasMenu = FormExtenders.HasMenu(_parentForm),
                        IconSize = SystemInformation.SmallIconSize,
                        IsSmallCaption =
                            captionHeight ==
                            SystemInformation.ToolWindowCaptionHeight,
                        Text = _parentForm.Text
                    };

                    // create painting meta data for caption buttons
                    if (_captionButtons.Count > 0)
                    {
                        paintData.CaptionButtons = new CaptionButtonPaintData[_captionButtons.Count];
                        for (int i = 0; i < _captionButtons.Count; i++)
                        {
                            CaptionButton button = _captionButtons[i];
                            CaptionButtonPaintData buttonData = new CaptionButtonPaintData(_bufferGraphics.Graphics, button.Bounds)
                            {
                                Pressed = button.Pressed,
                                Hovered = button.Hovered,
                                Enabled = button.Enabled,
                                HitTest = button.HitTest
                            };
                            paintData.CaptionButtons[i] = buttonData;
                        }
                    }

                    // paint
                    result = _manager.CurrentSkin.OnNcPaint(_parentForm, paintData);
                }

                // render buffered graphics 
                if (_bufferGraphics != null)
                    _bufferGraphics.Render(g);
            }
            catch (Exception)
            {// error drawing
                result = false;
            }

            // cleanup data
            if (hdc != (IntPtr)0)
            {
                Win32Api.SelectClipRgn(hdc, (IntPtr)0);
                Win32Api.ReleaseDC(_parentForm.Handle, hdc);
            }
            if (region != null && hrgn != (IntPtr)0)
                region.ReleaseHrgn(hrgn);

            if (region != null)
                region.Dispose();

            if (g != null)
                g.Dispose();

            return result;
        }
Exemplo n.º 8
0
		public void GetHrgn_Infinite_MakeEmpty ()
		{
			Region r = new Region ();
			Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
			Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
			Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");

			r.MakeEmpty ();
			Assert.IsTrue (r.IsEmpty (graphic), "Empty");
			Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
			IntPtr h = r.GetHrgn (graphic);
			Assert.IsFalse (h == IntPtr.Zero, "Handle!=0");
#if NET_2_0
			r.ReleaseHrgn (h);
#endif
		}
 private System.Windows.Forms.NativeMethods.RECT[] CreateScrollableRegion(Rectangle scroll)
 {
     if (this.cachedScrollableRegion == null)
     {
         bool rightToLeft = this.isRightToLeft();
         using (Region region = new Region(scroll))
         {
             int numVisibleRows = this.numVisibleRows;
             int y = this.layout.Data.Y;
             int x = this.layout.Data.X;
             DataGridRow[] dataGridRows = this.DataGridRows;
             for (int i = this.firstVisibleRow; i < numVisibleRows; i++)
             {
                 int height = dataGridRows[i].Height;
                 Rectangle nonScrollableArea = dataGridRows[i].GetNonScrollableArea();
                 nonScrollableArea.X += x;
                 nonScrollableArea.X = this.MirrorRectangle(nonScrollableArea, this.layout.Data, rightToLeft);
                 if (!nonScrollableArea.IsEmpty)
                 {
                     region.Exclude(new Rectangle(nonScrollableArea.X, nonScrollableArea.Y + y, nonScrollableArea.Width, nonScrollableArea.Height));
                 }
                 y += height;
             }
             using (Graphics graphics = base.CreateGraphicsInternal())
             {
                 IntPtr hrgn = region.GetHrgn(graphics);
                 if (hrgn != IntPtr.Zero)
                 {
                     this.cachedScrollableRegion = System.Windows.Forms.UnsafeNativeMethods.GetRectsFromRegion(hrgn);
                     System.Windows.Forms.IntSecurity.ObjectFromWin32Handle.Assert();
                     try
                     {
                         region.ReleaseHrgn(hrgn);
                     }
                     finally
                     {
                         CodeAccessPermission.RevertAssert();
                     }
                 }
             }
         }
     }
     return this.cachedScrollableRegion;
 }
 private System.Windows.Forms.NativeMethods.RECT[] CreateScrollableRegion(Rectangle scroll)
 {
     if (this.cachedScrollableRegion == null)
     {
         using (Region region = new Region(scroll))
         {
             IntPtr zero = IntPtr.Zero;
             using (Graphics graphics = base.CreateGraphicsInternal())
             {
                 zero = region.GetHrgn(graphics);
             }
             if (zero != IntPtr.Zero)
             {
                 this.cachedScrollableRegion = System.Windows.Forms.UnsafeNativeMethods.GetRectsFromRegion(zero);
                 System.Windows.Forms.IntSecurity.ObjectFromWin32Handle.Assert();
                 try
                 {
                     region.ReleaseHrgn(zero);
                 }
                 finally
                 {
                     CodeAccessPermission.RevertAssert();
                 }
             }
         }
     }
     return this.cachedScrollableRegion;
 }