Пример #1
0
		public int UxThemeDrawThemeBackground (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle bounds)
		{
			XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle (bounds);

			int result = UXTheme.DrawThemeBackground(hTheme, dc.GetHdc (), iPartId, iStateId, ref BoundsRect, IntPtr.Zero);
			dc.ReleaseHdc ();
			return result;
		}
Пример #2
0
		public int UxThemeDrawThemeEdge (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle bounds, Edges edges, EdgeStyle style, EdgeEffects effects, out Rectangle result)
		{
			XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle (bounds);
			XplatUIWin32.RECT retval;

			int hresult = UXTheme.DrawThemeEdge (hTheme, dc.GetHdc (), iPartId, iStateId, ref BoundsRect, (uint)style, (uint)edges + (uint)effects, out retval);
			dc.ReleaseHdc ();
			result = retval.ToRectangle();
			return hresult;
		}
Пример #3
0
        /// <summary>
        /// Draws composited text onto the glass area of a form.
        /// </summary>
        /// <param name="dc">The <see cref="IDeviceContext"/> onto which the composited text should be drawn.</param>
        /// <param name="text">The text to draw.</param>
        /// <param name="font">The <see cref="Font"/> to apply to the drawn text.</param>
        /// <param name="bounds">The <see cref="Rectangle" /> that represents the bounds of the text.</param>
        /// <param name="padding">The <see cref="Padding"/> around the text; necessary to allow space for the glow effect.</param>
        /// <param name="foreColor">The <see cref="Color" /> to apply to the drawn text.</param>
        /// <param name="textFormat">A bitwise combination of the <see cref="TextFormatFlags" /> values.</param>
        /// <param name="glowSize">Specifies the size of a glow that will be drawn on the background prior to any text being drawn.</param>
        /// <remarks>
        /// <para>
        ///   Do not use this method to draw text on non-glass areas of a form.
        /// </para>
        /// </remarks>
        /// <exception cref="NotSupportedException">The current operating system does not support glass, or the Desktop Window Manager is not enabled.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="dc"/>, <paramref name="text"/> or <paramref name="font"/> is <see langword="null"/>.</exception>
        public static void DrawCompositedText(IDeviceContext dc, string text, Font font, Rectangle bounds, Padding padding, Color foreColor, int glowSize, TextFormatFlags textFormat)
        {
            if (!IsDwmCompositionEnabled)
            {
                throw new NotSupportedException(Properties.Resources.GlassNotSupportedError);
            }

            if (dc == null)
            {
                throw new ArgumentNullException("dc");
            }
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            if (font == null)
            {
                throw new ArgumentNullException("font");
            }

            IntPtr primaryHdc = dc.GetHdc();

            try
            {
                using (SafeDeviceHandle memoryHdc = NativeMethods.CreateCompatibleDC(primaryHdc))
                    using (SafeGDIHandle fontHandle = new SafeGDIHandle(font.ToHfont(), true))
                        using (SafeGDIHandle dib = NativeMethods.CreateDib(bounds, primaryHdc, memoryHdc))
                        {
                            NativeMethods.SelectObject(memoryHdc, fontHandle);

                            // Draw glowing text
                            System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
                            NativeMethods.DTTOPTS dttOpts = new NativeMethods.DTTOPTS();
                            dttOpts.dwSize    = Marshal.SizeOf(typeof(NativeMethods.DTTOPTS));
                            dttOpts.dwFlags   = NativeMethods.DrawThemeTextFlags.Composited | NativeMethods.DrawThemeTextFlags.GlowSize | NativeMethods.DrawThemeTextFlags.TextColor;
                            dttOpts.crText    = ColorTranslator.ToWin32(foreColor);
                            dttOpts.iGlowSize = glowSize;
                            NativeMethods.RECT textBounds = new NativeMethods.RECT(padding.Left, padding.Top, bounds.Width - padding.Right, bounds.Height - padding.Bottom);
                            NativeMethods.DrawThemeTextEx(renderer.Handle, memoryHdc, 0, 0, text, text.Length, (int)textFormat, ref textBounds, ref dttOpts);

                            // Copy to foreground
                            const int SRCCOPY = 0x00CC0020;
                            NativeMethods.BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY);
                        }
            }
            finally
            {
                dc.ReleaseHdc();
            }
        }
Пример #4
0
 private Padding GetThemeMargins(IDeviceContext dc, NativeRenderer.MarginTypes marginType)
 {
     try {
         NativeRenderer.NativeMethods.MARGINS pMargins;
         if (NativeRenderer.NativeMethods.GetThemeMargins(this.renderer.Handle, dc.GetHdc(), this.renderer.Part, this.renderer.State, (int)marginType, IntPtr.Zero, out pMargins) == 0)
         {
             return(new Padding(pMargins.cxLeftWidth, pMargins.cyTopHeight, pMargins.cxRightWidth, pMargins.cyBottomHeight));
         }
         else
         {
             return(new Padding(0));
         }
     } finally {
         dc.ReleaseHdc();
     }
 }
Пример #5
0
 Padding GetThemeMargins(IDeviceContext dc, MarginTypes marginType)
 {
     try
     {
         IntPtr hDC = dc.GetHdc();
         if (0 == NativeMethods.GetThemeMargins(renderer.Handle, hDC, renderer.Part, renderer.State, (int)marginType, IntPtr.Zero, out NativeMethods.MARGINS margins))
         {
             return(new Padding(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight));
         }
         return(new Padding(0));
     }
     finally
     {
         dc.ReleaseHdc();
     }
 }
Пример #6
0
        /// <summary>
        ///     Provides the size, in pixels, of the specified text.
        /// </summary>
        /// <param name="dc">The device context in which to measure the text.</param>
        /// <param name="text">The text to measure.</param>
        /// <param name="font">The <see cref="Font" /> to apply to the measured text.</param>
        /// <param name="textFormat">A bitwise combination of the <see cref="TextFormatFlags" /> values.</param>
        /// <returns>
        ///     The <see cref="Size" />, in pixels, of <paramref name="text" /> drawn with the specified
        ///     <paramref name="font" /> and format.
        /// </returns>
        /// <exception cref="NotSupportedException">
        ///     The current operating system does not support glass, or the Desktop Window
        ///     Manager is not enabled.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="dc" />, <paramref name="text" /> or <paramref name="font" /> is
        ///     <see langword="null" />.
        /// </exception>
        public static Size MeasureCompositedText(IDeviceContext dc, string text, Font font, TextFormatFlags textFormat)
        {
            if (!IsDwmCompositionEnabled)
            {
                throw new NotSupportedException(Resources.GlassNotSupportedError);
            }

            if (dc == null)
            {
                throw new ArgumentNullException("dc");
            }
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            if (font == null)
            {
                throw new ArgumentNullException("font");
            }

            var primaryHdc = dc.GetHdc();

            try
            {
                var bounds = new Rectangle(0, 0, int.MaxValue, int.MaxValue);

                using (var memoryHdc = NativeMethods.CreateCompatibleDC(primaryHdc))
                    using (var fontHandle = new SafeGDIHandle(font.ToHfont(), true))
                        using (var dib = NativeMethods.CreateDib(bounds, primaryHdc, memoryHdc))
                        {
                            NativeMethods.SelectObject(memoryHdc, fontHandle);

                            var renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);
                            var bounds2  = new NativeMethods.RECT(bounds);
                            NativeMethods.RECT rect;
                            NativeMethods.GetThemeTextExtent(renderer.Handle, memoryHdc, 0, 0, text, text.Length,
                                                             (int)textFormat, ref bounds2, out rect);
                            return(new Size(rect.Right - rect.Left, rect.Bottom - rect.Top));
                        }
            }
            finally
            {
                dc.ReleaseHdc();
            }
        }
Пример #7
0
        /// <summary>
        /// Provides the size, in pixels, of the specified text.
        /// </summary>
        /// <param name="dc">The device context in which to measure the text.</param>
        /// <param name="text">The text to measure.</param>
        /// <param name="font">The <see cref="Font"/> to apply to the measured text.</param>
        /// <param name="textFormat">A bitwise combination of the <see cref="TextFormatFlags" /> values.</param>
        /// <returns>The <see cref="Size"/>, in pixels, of <paramref name="text"/> drawn with the specified <paramref name="font"/> and format.</returns>
        /// <exception cref="NotSupportedException">The current operating system does not support glass, or the Desktop Window Manager is not enabled.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="dc"/>, <paramref name="text"/> or <paramref name="font"/> is <see langword="null"/>.</exception>
        public static Size MeasureCompositedText(IDeviceContext dc, string text, Font font, TextFormatFlags textFormat)
        {
            if (!IsDwmCompositionEnabled)
            {
                throw new NotSupportedException("The current operating system does not support glass, or the Desktop Window Manager is not enabled.");
            }

            if (dc == null)
            {
                throw new ArgumentNullException("dc");
            }
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            if (font == null)
            {
                throw new ArgumentNullException("font");
            }

            IntPtr primaryHdc = dc.GetHdc();

            try
            {
                Rectangle bounds = new Rectangle(0, 0, int.MaxValue, int.MaxValue);

                using (SafeDeviceHandle memoryHdc = Natives.CreateCompatibleDC(primaryHdc))
                    using (SafeGDIHandle fontHandle = new SafeGDIHandle(font.ToHfont(), true))
                        using (SafeGDIHandle dib = Natives.CreateDib(bounds, primaryHdc, memoryHdc))
                        {
                            Natives.SelectObject(memoryHdc, fontHandle);

                            System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
                            Natives.RECT bounds2 = new Natives.RECT(bounds);
                            Natives.RECT rect;
                            Natives.GetThemeTextExtent(renderer.Handle, memoryHdc, 0, 0, text, text.Length, (int)textFormat, ref bounds2, out rect);
                            return(new Size(rect.Right - rect.Left, rect.Bottom - rect.Top));
                        }
            }
            finally
            {
                dc.ReleaseHdc();
            }
        }
Пример #8
0
        public static void MaskOutCorners(ImageWithDeviceContext destImage, int destWidth,
                                          Size frameSize, IDeviceContext maskOutBitmap, Padding stretchExcludeMargins, int maskOutColor, int nYOriginSrc)
        {
            // Doesn't maskout all the image, just the right and left exclude margins
            if (maskOutBitmap != null)
            {
                IntPtr destDc = destImage.GetHdc();
                IntPtr srcDc  = maskOutBitmap.GetHdc();
                if (stretchExcludeMargins.Left > 0)
                {
                    NativeMethods.TransparentBlt(destDc, 0, 0, stretchExcludeMargins.Left, frameSize.Height, srcDc, 0,
                                                 nYOriginSrc, stretchExcludeMargins.Left, frameSize.Height,
                                                 maskOutColor);

                    //BitBlt(DestDC, 0, 0, StretchRect.Left, FrameHeight, _
                    //           MaskOutBitmap.DC, 0, Me.State(State), CopyPixelOperation.SourceAnd)
                }
                if (stretchExcludeMargins.Right > 0)
                {
                    NativeMethods.TransparentBlt(destDc, (destWidth - stretchExcludeMargins.Right) + 0, 0,
                                                 stretchExcludeMargins.Right, frameSize.Height, srcDc, frameSize.Width - (stretchExcludeMargins.Right),
                                                 nYOriginSrc, stretchExcludeMargins.Right, frameSize.Height,
                                                 maskOutColor);

                    //BitBlt(DestDC, (DestWidth - StretchRect.Right) + 0, _
                    //            0, StretchRect.Right, FrameHeight, _
                    //           MaskOutBitmap.DC, FrameWidth - (StretchRect.Right), _
                    //            Me.State(State), StretchRect.Right, FrameHeight, MaskOutColor)
                }

                //TransparentBlt(DestDC, _
                //           StretchRect.Left, StretchRect.Top, _
                //           DestWidth - (StretchRect.Left + StretchRect.Right), _
                //           FrameHeight, _
                //           Image.DC, _
                //           StretchRect.Left, Me.State(State) + +StretchRect.Top, _
                //           FrameWidth - (StretchRect.Left + StretchRect.Right), _
                //           FrameHeight, _
                //           MaskOutColor)
                destImage.ReleaseHdc();
                maskOutBitmap.ReleaseHdc();
            }
        }
Пример #9
0
        Padding GetThemeMargins(IDeviceContext dc, MarginTypes marginType)
        {
            NativeMethods.Margins margins;
            try
            {
                IntPtr hDc = dc.GetHdc();

                if (NativeMethods.GetThemeMargins(Renderer.Handle, hDc, Renderer.Part, Renderer.State, (int)marginType, IntPtr.Zero, out margins) == 0)
                {
                    return(new Padding(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight));
                }

                return(new Padding(0));
            }
            finally
            {
                dc.ReleaseHdc();
            }
        }
Пример #10
0
        private Padding GetThemeMargins(IDeviceContext dc, MarginTypes marginType)
        {
            try
            {
                IntPtr hDC = dc.GetHdc();

                MARGINS margins;
                if (DllImports.GetThemeMargins(_renderer.Handle, hDC, _renderer.Part, _renderer.State, (int)marginType, IntPtr.Zero, out margins) == 0)
                {
                    return(new Padding(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight));
                }

                return(new Padding(0));
            }
            finally
            {
                dc.ReleaseHdc();
            }
        }
Пример #11
0
        Padding GetThemeMargins(IDeviceContext dc, MarginTypes marginType)
        {
            NativeMethods.Margins margins;
            try
            {
                IntPtr hDc = dc.GetHdc();

                if (NativeMethods.GetThemeMargins(Renderer.Handle, hDc, Renderer.Part, Renderer.State, (int)marginType, IntPtr.Zero, out margins) == 0)
                {
                    return new Padding(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
                }

                return new Padding(0);
            }
            finally
            {
                dc.ReleaseHdc();
            }
        }
Пример #12
0
        static Rectangle RangeBound(this IDeviceContext dc, Font font, string text,
                                    Rectangle container, int start, int end, out Rectangle textBound, out Rectangle uptoIndex, DrawTextFlags?flags = null)
        {
            textBound = Rectangle.Empty;
            uptoIndex = Rectangle.Empty;

            if (string.IsNullOrEmpty(text))
            {
                return(Rectangle.Empty);
            }

            IntPtr hdc   = dc.GetHdc();
            IntPtr _font = SelectObject(hdc, font.ToHfont());

            var rc = hdc.rangeBound(text, container, start, end, out textBound, out uptoIndex, flags: flags);

            DeleteObject(SelectObject(hdc, _font));
            dc.ReleaseHdc();
            return(rc);
        }
Пример #13
0
        private Padding GetThemeMargins(IDeviceContext dc, MarginTypes marginType)
        {
            Padding padding;

            try {
                NativeMethods.MARGINS margins;
                IntPtr hdc = dc.GetHdc();
                if (
                    NativeMethods.GetThemeMargins(renderer.Handle, hdc, renderer.Part, renderer.State, (int)marginType, IntPtr.Zero,
                                                  out margins) == 0)
                {
                    return(new Padding(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight));
                }
                padding = new Padding(0);
            }
            finally {
                dc.ReleaseHdc();
            }
            return(padding);
        }
Пример #14
0
        public static void HighlightText(this IDeviceContext dc, Font font, string text,
                                         Rectangle container, int start, int end, Color highlightForeColor, Color highlightBackColorStart,
                                         Color?highlightBackColorEnd, DrawTextFlags?flags = null)
        {
            IntPtr hdc   = dc.GetHdc();
            IntPtr _font = SelectObject(hdc, font.ToHfont());

            Dimension dm   = container;
            var       flag = flags.getMeasureFlag(false);

            SetBkMode(hdc, ColorTranslator.ToWin32(Color.Transparent));

            //first draw whole text
            DrawText(hdc, text, text.Length, ref dm, 0);

            //now get the highlight rectangle which will draw the highlighted text
            Rectangle textBound, uptoIndex;
            var       rect = hdc.rangeBound(text, container, start, end, out textBound, out uptoIndex, flags: flags);

            dm = rect;

            var _backColorEnd = highlightBackColorEnd ?? highlightBackColorStart;

            hdc.Fill(rect, highlightBackColorStart, _backColorEnd, Angle.A0);

            SetTextColor(hdc, ColorTranslator.ToWin32(highlightForeColor));

            if (start < 0 || start > text.Length - 1 || end < 0 || end > text.Length - 1)
            {
                throw new Exception("start and end value must be with in text length");
            }

            var _text = text.Substring(start, end - start + 1);

            DrawText(hdc, _text, _text.Length, ref dm, 0);

            DeleteObject(SelectObject(hdc, _font));
            dc.ReleaseHdc();
        }
Пример #15
0
        public void DrawTextRect(IDeviceContext dc, string text, Color foreColor, Color backColor, Rectangle bounds, TextFormatFlags flags)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            RECT rect = new RECT(bounds);

            IntPtr hDc = dc.GetHdc();

            try
            {
                int clr  = ColorTranslator.ToWin32(foreColor);
                int back = ColorTranslator.ToWin32(backColor);
                NativeMethods.DrawTextRect(hDc, text, hFont, clr, back, ref rect, (int)flags);
            }
            finally
            {
                dc.ReleaseHdc();
            }
        }
Пример #16
0
        public void DirectDraw(IDeviceContext dc, string text, Point pt)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            if (dc == null)
            {
                throw new ArgumentNullException("dc");
            }

            IntPtr hDc = dc.GetHdc();

            try
            {
                NativeMethods.DrawTextDirect(hDc, text, hFont, Win32Color, pt.X, pt.Y);
            }
            finally
            {
                dc.ReleaseHdc();
            }
        }
Пример #17
0
        public void DrawTextGlow(IDeviceContext dc, string text, Point pt, Color foreColor)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            if (dc == null)
            {
                throw new ArgumentNullException("dc");
            }

            IntPtr hDc = dc.GetHdc();

            try
            {
                int clr1 = ColorTranslator.ToWin32(foreColor);
                NativeMethods.DrawTextGlow(hDc, text, hFont, clr1, pt.X, pt.Y);
            }
            finally
            {
                dc.ReleaseHdc();
            }
        }
Пример #18
0
        public void DrawText(IDeviceContext dc, string text, Rectangle bounds)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            if (dc == null)
            {
                throw new ArgumentNullException("dc");
            }

            IntPtr hDc = dc.GetHdc();

            try
            {
                RECT rect = new RECT(bounds);
                NativeMethods.DrawAlphaTextRect(hDc, text, hFont, Win32Color, ref rect, 0);
            }
            finally
            {
                dc.ReleaseHdc();
            }
        }
Пример #19
0
		public int UxThemeGetThemeTextMetrics (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, out TextMetrics result)
		{
			XplatUIWin32.TEXTMETRIC metrics;
			
			int hresult = UXTheme.GetThemeTextMetrics (hTheme, dc.GetHdc (), iPartId, iStateId, out metrics);
			dc.ReleaseHdc ();

			TextMetrics retval = new TextMetrics ();
			retval.Ascent = metrics.tmAscent;
			retval.AverageCharWidth = metrics.tmAveCharWidth;
			retval.BreakChar =(char)metrics.tmBreakChar;
			retval.CharSet = (TextMetricsCharacterSet)metrics.tmCharSet;
			retval.DefaultChar = (char)metrics.tmDefaultChar;
			retval.Descent = metrics.tmDescent;
			retval.DigitizedAspectX = metrics.tmDigitizedAspectX;
			retval.DigitizedAspectY = metrics.tmDigitizedAspectY;
			retval.ExternalLeading = metrics.tmExternalLeading;
			retval.FirstChar = (char)metrics.tmFirstChar;
			retval.Height = metrics.tmHeight;
			retval.InternalLeading = metrics.tmInternalLeading;
			retval.Italic = metrics.tmItalic == 0 ? false : true;
			retval.LastChar = (char)metrics.tmLastChar;
			retval.MaxCharWidth = metrics.tmMaxCharWidth;
			retval.Overhang = metrics.tmOverhang;
			retval.PitchAndFamily = (TextMetricsPitchAndFamilyValues)metrics.tmPitchAndFamily;
			retval.StruckOut = metrics.tmStruckOut == 0 ? false : true;
			retval.Underlined = metrics.tmUnderlined == 0 ? false : true;
			retval.Weight = metrics.tmWeight;

			result = retval;
			return hresult;
		}
Пример #20
0
		void Paint (WidgetType widgetType, Rectangle bounds, IDeviceContext dc, TransparencyType transparencyType, Color background, DeviceContextType deviceContextType, Rectangle clippingArea, Painter painter, Rectangle excludedArea)
		{
			Rectangle painted_area = Rectangle.Intersect (bounds, clippingArea);
			if (painted_area.Width == 0 || painted_area.Height == 0)
				return;
			painted_area.Offset (-bounds.X, -bounds.Y);
			excludedArea.Offset (-bounds.X, -bounds.Y);
			GdkDrawablePointer drawable = gdk_pixmap_new (IntPtr.Zero, bounds.Width, bounds.Height, 24);
			painter.AttachStyle (widgetType, drawable, this);
			GdkPixbufPointer pixbuf;
			IntPtr pixel_data;
			int rowstride;
			GdkGCPointer gc = gdk_gc_new (drawable);
			GdkColor color = new GdkColor (background);
			gdk_gc_set_rgb_fg_color (gc, ref color);
			Paint (drawable, gc, bounds, widgetType, out pixbuf, out pixel_data, out rowstride, painted_area, painter, excludedArea);
			GdkPixbufPointer white_pixbuf = IntPtr.Zero;
			IntPtr white_pixel_data = IntPtr.Zero;
			int white_rowstride = 0;
			GdkColor white_color = new GdkColor();
			if (transparencyType == TransparencyType.Alpha) {
				white_color.red = guint16.MaxValue;
				white_color.green = guint16.MaxValue;
				white_color.blue = guint16.MaxValue;
				gdk_gc_set_rgb_fg_color (gc, ref white_color);
				Paint (drawable, gc, bounds, widgetType, out white_pixbuf, out white_pixel_data, out white_rowstride, painted_area, painter, excludedArea);
			}
			g_object_unref (gc);
			unsafe {
				byte* row = (byte*)pixel_data;
				byte* pixel;
				byte* white_row = (byte*)white_pixel_data;
				byte* white_pixel;

				for (int row_index = 0; row_index < painted_area.Height; row_index++) {
					pixel = row;
					white_pixel = white_row;
					for (int pixel_index = 0; pixel_index < painted_area.Width; pixel_index++) {
						const int GdkRedOffset = 0;
						const int GdkGreenOffset = 1;
						const int GdkBlueOffset = 2;
						const int BitmapAlphaOffset = 3;
						const int BitmapRedOffset = 2;
						const int BitmapBlueOffset = 0;
						switch (transparencyType) {
						case TransparencyType.Alpha:
							pixel [BitmapAlphaOffset] = (byte)(pixel [GdkRedOffset] - white_pixel [GdkRedOffset] + byte.MaxValue);
							break;
						case TransparencyType.Color:
							if (
								pixel [GdkRedOffset] == background.R &&
								pixel [GdkGreenOffset] == background.G &&
								pixel [GdkBlueOffset] == background.B) {
								const int AlphaFullyTransparent = 0;
								pixel [BitmapAlphaOffset] = AlphaFullyTransparent;
							}
							break;
						}

						byte temporary = pixel [GdkRedOffset];
						pixel [BitmapBlueOffset] = pixel [GdkBlueOffset];
						pixel [BitmapRedOffset] = temporary;

						const int PixelSize = 4;
						pixel += PixelSize;
						white_pixel += PixelSize;
					}
					row += rowstride;
					white_row += white_rowstride;
				}
			}
			if (transparencyType == TransparencyType.Alpha)
				g_object_unref (white_pixbuf);
			g_object_unref (drawable);
			Bitmap bitmap = new Bitmap (painted_area.Width, painted_area.Height, rowstride, PixelFormat.Format32bppPArgb, pixel_data);
			Graphics g;
			bool graphics_is_from_hdc = false;
			switch (deviceContextType) {
			case DeviceContextType.Graphics:
				g = (Graphics)dc;
				break;
			case DeviceContextType.Native:
				g = Graphics.FromHdc (dc.GetHdc ());
				break;
			default:
				g = dc as Graphics;
				if (g == null) {
					graphics_is_from_hdc = true;
					g = Graphics.FromHdc (dc.GetHdc ());
				} else
					graphics_is_from_hdc = false;
				break;
			}
			painted_area.Offset (bounds.X, bounds.Y);
			g.DrawImage (bitmap, painted_area.Location);
			switch (deviceContextType) {
			case DeviceContextType.Graphics:
				break;
			case DeviceContextType.Native:
				g.Dispose ();
				dc.ReleaseHdc ();
				break;
			default:
				if (graphics_is_from_hdc) {
					g.Dispose ();
					dc.ReleaseHdc ();
				}
				break;
			}
			bitmap.Dispose ();
			g_object_unref (pixbuf);
		}
Пример #21
0
        /// <summary>
        /// without render, only calc lines layout
        /// </summary>
        /// <param name="dev"></param>
        public void CalcLines(IDeviceContext dev, int max_lines_to_calc)
        {
            //освобождаем имеющиеся строки
            free_lines();
            if (TextRegion != null)
            {
                TextRegion.Dispose();
            }
            TextRegion = new Region();

            IntPtr hdc                 = dev.GetHdc();
            IntPtr font_ptr            = Font.ToHfont();
            IntPtr old_font            = NativeGdi.SelectObject(hdc, font_ptr);
            uint   old_align           = NativeGdi.SetTextAlign(hdc, 0);
            int    line_height         = (int)Math.Ceiling(Font.GetHeight());
            IntPtr char_buffer         = IntPtr.Zero;
            bool   EOF                 = false;
            int    chars_filled        = 0;
            int    current_char_offset = 0;
            int    current_Y           = 0;
            int    current_line_index  = 0;

            while (current_line_index < max_lines_to_calc)
            {
                OnFetchCharsToScreen
                    (current_char_offset,
                    true,
                    out char_buffer,
                    out chars_filled,
                    out EOF);
                LineInfoSS new_line = new LineInfoSS();
                new_line.ReferensePoint = new Point(Bounds.X, Bounds.Y + current_Y);
                new_line.CharFirst      = current_char_offset;

                //обсчитываем
                if (chars_filled != 0)
                {
                    new_line.PrepareLayout
                        (hdc,
                        char_buffer,
                        chars_filled,
                        Bounds.Width);
                }

                //прибавляем счетчики
                current_char_offset = current_char_offset + new_line.CharLength;
                current_Y           = current_Y + line_height;
                current_line_index++;

                lines_info.Add(new_line);
                TextRegion.Union(new Rectangle(new_line.ReferensePoint, new_line.Extent));

                //если стоит признак конца файла, выходим
                if (EOF)
                {
                    break;
                }
            }

            font_ptr = NativeGdi.SelectObject(hdc, old_font);
            NativeGdi.DeleteObject(font_ptr);
            NativeGdi.SetTextAlign(hdc, old_align);

            dev.ReleaseHdc();
        }
Пример #22
0
    public static Rectangle GetHighlightRectangle(IDeviceContext dc, string text, int highlightStart, int highlightLength, Font font, Rectangle bounds, TextFormatFlags flags = TextFormatFlags.SingleLine)
    {
        if ((flags & TextFormatFlags.SingleLine) == 0)
        {
            throw new InvalidOperationException("This method only handles single line highlights. Multiline text highlights may be composed of multiple rectangles.");
        }
        if (string.IsNullOrEmpty(text))
        {
            throw new ArgumentException("Text must not be null or empty.", "text");
        }
        if (highlightStart < 0)
        {
            throw new ArgumentOutOfRangeException("highlightStart", highlightLength, "Highlight length must be greater than or equal to zero.");
        }
        if (highlightLength <= 0)
        {
            throw new ArgumentOutOfRangeException("highlightLength", highlightLength, "Highlight length must be greater than zero.");
        }
        if (highlightLength > text.Length - highlightStart)
        {
            throw new ArgumentOutOfRangeException("highlightLength", highlightLength, "Highlight length must be less than or equal to the length of the text minus the highlight start.");
        }
        var  drawTextParams = GetTextMargins(font, flags);
        Size totalSize;

        // Determine total size and adjust for cut-off highlight.
        // We need access to the modified string in case it was trimmed.
        // Unfortunately, TextFormatFlags.ModifyString can't be used with TextRenderer.MeasureText
        // so we'll have to roll our own.
        var hdc = dc.GetHdc();

        try
        {
            var modifiedText = new StringBuilder(text);
            var rectBounds   = new RECT(0, 0, bounds.Width, bounds.Height);
            var hFont        = font.ToHfont();
            try
            {
                var oldFont = Gdi32.SelectObject(hdc, hFont);
                try
                {
                    User32.DrawTextEx(hdc, modifiedText, modifiedText.Length, ref rectBounds, (flags & ~AlignFlags) | CalcRectFlag | TextFormatFlags.ModifyString, ref drawTextParams);
                }
                finally
                {
                    Gdi32.SelectObject(hdc, oldFont);
                }
            }
            finally
            {
                Gdi32.DeleteObject(hFont);
            }
            totalSize = new Size(rectBounds.Right - rectBounds.Left, rectBounds.Bottom - rectBounds.Top);

            // drawTextParams.uiLengthDrawn may be equal to text.Length even if an ellipsis was applied
            for (var i = 0; i < drawTextParams.uiLengthDrawn; i++)
            {
                if (modifiedText[i] != text[i])
                {
                    var unchangedLength = i;
                    if (highlightStart > unchangedLength)
                    {
                        highlightStart = unchangedLength;
                    }
                    if (highlightStart + highlightLength > unchangedLength)
                    {
                        highlightLength = modifiedText.Length - highlightStart;
                    }
                    text = modifiedText.ToString();
                    break;
                }
            }
        }
        finally
        {
            dc.ReleaseHdc();
        }

        // Find the end of the highlight first rather than the beginning. This avoids having to explicitly deal with kerning.
        // Kerning may move the first highlighted character closer to the previous character. As long as the two characters
        // are measured together, kerning is taken into consideration.
        // The rectangle extends to the full beginning of the highlighted text, even when kerning moves it.
        var highlightXEnd = drawTextParams.iLeftMargin + TextRenderer.MeasureText(dc, text.Substring(0, highlightStart + highlightLength), font, bounds.Size, (flags & ~(PaddingFlags | AlignFlags | EllipsisFlags)) | TextFormatFlags.NoPadding).Width;
        // We don't care about the kerning of the first character *following* the highlight. This way the highlight is inclusive on both ends.
        // The rectangle extends to the full end of the highlighted text, regardless of how close the following character comes.
        var highlightSize = TextRenderer.MeasureText(dc, text.Substring(highlightStart, highlightLength), font, bounds.Size, (flags & ~(PaddingFlags | AlignFlags | EllipsisFlags)) | TextFormatFlags.NoPadding);

        var unalignedHighlightBounds = new Rectangle(bounds.X + highlightXEnd - highlightSize.Width, bounds.Y, highlightSize.Width, highlightSize.Height);

        return(ApplyAlignment(unalignedHighlightBounds, bounds.Width - totalSize.Width, bounds.Height - totalSize.Height, flags));
    }
Пример #23
0
        public int FindPreviousLineStart(IDeviceContext dev)
        {
            //для обсчета строки будет нужен контекст
            IntPtr hdc          = dev.GetHdc();
            IntPtr font_ptr     = Font.ToHfont();
            IntPtr old_font     = NativeGdi.SelectObject(hdc, font_ptr);
            uint   old_align    = NativeGdi.SetTextAlign(hdc, 0);
            int    line_height  = (int)Math.Ceiling(Font.GetHeight());
            IntPtr char_buffer  = IntPtr.Zero;
            bool   EOF          = false;
            int    chars_filled = 0;
            int    ret          = 0;

            //получаем буфер символов начиная от -max_chars_in_line
            OnFetchCharsToScreen
                (-max_chars_in_line,
                false,
                out char_buffer,
                out chars_filled,
                out EOF);

            if (chars_filled <= 0)
            {
                //то есть и так находимся в начале
                ret = 0;
            }
            else
            {
                //получаем ssa_sctruct
                IntPtr ssa_scruct = NativeScript.ScriptStringAnalyseCall
                                        (hdc,
                                        char_buffer,
                                        chars_filled,
                                        SCRIPT_TABDEF.GetDefault());

                //берем logical wodths
                int[] widths = NativeScript.GetLogicalWidths(ssa_scruct);
                //освобождаем ssa_scruct
                NativeScript.ScriptStringFree(ref ssa_scruct);

                //суммируем полученные ширины символов с конца, пока не превысим
                //максимальную ширину или не встретим второй hard break
                char current_char  = '\0';
                int  current_width = 0;
                int  finding_ind   = -1;
                for (int i = chars_filled - 1; i >= 0; i--)
                {
                    current_char  = get_char_from_buffer(char_buffer, i);
                    current_width = current_width + widths[i];
                    //проверяем ширину
                    if (current_width > Bounds.Width)
                    {
                        finding_ind = i;
                        break;
                    }

                    //проверяем hard break (\n   \r     \r\n) начиная со второго шага
                    if (i != chars_filled - 1)
                    {
                        if (current_char == '\n')
                        {
                            if (((i - 1) >= 0) && (get_char_from_buffer(char_buffer, i - 1) == '\r'))
                            {
                                finding_ind = i;
                                break;
                            }
                            finding_ind = i;
                            break;
                        }
                        else if ((current_char == '\r') && (i < chars_filled - 2))
                        {
                            finding_ind = i;
                            break;
                        }
                    }
                }

                //finding_ind теперь соответствует концу предыщей строки
                ret = -(chars_filled - finding_ind - 1);
            }

            font_ptr = NativeGdi.SelectObject(hdc, old_font);
            NativeGdi.DeleteObject(font_ptr);
            NativeGdi.SetTextAlign(hdc, old_align);
            dev.ReleaseHdc();

            return(ret);
        }
Пример #24
0
		public int UxThemeGetThemeBackgroundContentRect (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle bounds, out Rectangle result)
		{
			XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle (bounds);
			XplatUIWin32.RECT retval;

			int hresult = UXTheme.GetThemeBackgroundContentRect (hTheme, dc.GetHdc (), iPartId, iStateId, ref BoundsRect, out retval);
			dc.ReleaseHdc ();

			result = retval.ToRectangle ();
			return hresult;
		}
Пример #25
0
		public int UxThemeDrawThemeText (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, string text, TextFormatFlags textFlags, Rectangle bounds)
		{
			XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle (bounds);

			int result = UXTheme.DrawThemeText (hTheme, dc.GetHdc (), iPartId, iStateId, text, text.Length, (uint)textFlags, 0, ref BoundsRect);
			dc.ReleaseHdc ();
			return result;
		}
Пример #26
0
        /// <summary>
        /// calc layout and render
        /// </summary>
        /// <param name="dev"></param>
        public void UpdateArea(IDeviceContext dev)
        //public void UpdateArea(Graphics g)
        {
            free_lines();
            if (TextRegion != null)
            {
                TextRegion.Dispose();
            }
            TextRegion = new Region();

            IntPtr hdc = dev.GetHdc();
            //IntPtr hdc = g.GetHdc();



            IntPtr font_ptr = Font.ToHfont();
            //IntPtr font_ptr = font_ptr_cached;
            IntPtr old_font = NativeGdi.SelectObject(hdc, font_ptr);

            //Font hdc_font = Font.FromHfont(old_font);

            uint   old_align   = NativeGdi.SetTextAlign(hdc, 0);
            int    line_height = (int)Math.Ceiling(Font.GetHeight());
            IntPtr char_buffer = IntPtr.Zero;

            int select_first      = 0;
            int select_last       = 0;
            int select_line_first = 0;
            int select_line_last  = 0;

            OnFetchSelectionRange(out select_first, out select_last);

            bool EOF                 = false;
            int  chars_filled        = 0;
            int  current_char_offset = 0;
            int  current_Y           = 0;

            while (current_Y + line_height < Bounds.Height)
            {
                select_line_first = 0;
                select_line_last  = 0;

                OnFetchCharsToScreen
                    (current_char_offset,
                    true,
                    out char_buffer,
                    out chars_filled,
                    out EOF);
                LineInfoSS new_line = new LineInfoSS();
                new_line.ReferensePoint = new Point(Bounds.X, Bounds.Y + current_Y);
                new_line.CharFirst      = current_char_offset;

                //если буфер не пуст рисуем строку
                if (chars_filled != 0)
                {
                    new_line.PrepareLayout
                        (hdc,
                        char_buffer,
                        chars_filled,
                        Bounds.Width);

                    //пересчитываем selection
                    if ((select_first >= current_char_offset) && (select_first <= current_char_offset + new_line.CharLength - 1))
                    {
                        //начало selection попадает в строку
                        select_line_first = select_first - current_char_offset;
                        select_line_last  = new_line.CharLength - 1;
                    }
                    if ((select_last >= current_char_offset) && (select_last <= current_char_offset + new_line.CharLength - 1))
                    {
                        //конец selection попадает в строку
                        select_line_last = select_last - current_char_offset;
                    }
                    if ((select_first <= current_char_offset) && (select_last >= current_char_offset + new_line.CharLength - 1))
                    {
                        //весь selection попадает в строку
                        select_line_first = select_first - current_char_offset;
                        select_line_last  = new_line.CharLength - 1;
                    }

                    //и рисуем
                    new_line.Render(select_line_first, select_line_last);
                }

                //прибавляем счетчики
                current_char_offset = current_char_offset + new_line.CharLength;
                current_Y           = current_Y + line_height;

                lines_info.Add(new_line);
                TextRegion.Union(new Rectangle(new_line.ReferensePoint, new_line.Extent));

                //если стоит признак конца файла, выходим
                if (EOF)
                {
                    break;
                }
            }



            font_ptr = NativeGdi.SelectObject(hdc, old_font);
            NativeGdi.DeleteObject(font_ptr);
            //NativeGdi.DeleteObject(old_font);
            NativeGdi.SetTextAlign(hdc, old_align);

            NativeGdi.GdiFlush(); //возможно не обязательно

            dev.ReleaseHdc();
            //g.ReleaseHdc(hdc);
        }
Пример #27
0
		public void VisualStyleRendererDrawBackgroundExcludingArea (IntPtr theme, IDeviceContext dc, int part, int state, Rectangle bounds, Rectangle excludedArea)
		{
			XplatUIWin32.RECT bounds_rect = XplatUIWin32.RECT.FromRectangle (bounds);
			IntPtr hdc = dc.GetHdc ();
			XplatUIWin32.Win32ExcludeClipRect (hdc, excludedArea.Left, excludedArea.Top, excludedArea.Right, excludedArea.Bottom);
			UXTheme.DrawThemeBackground (theme, hdc, part, state, ref bounds_rect, IntPtr.Zero);
			IntPtr hrgn = XplatUIWin32.Win32CreateRectRgn (excludedArea.Left, excludedArea.Top, excludedArea.Right, excludedArea.Bottom);
			XplatUIWin32.Win32ExtSelectClipRgn (hdc, hrgn, (int)ClipCombineMode.RGN_OR);
			XplatUIWin32.Win32DeleteObject (hrgn);
			dc.ReleaseHdc ();
		}
Пример #28
0
        internal static void StretchImageWithOutMargin(IDeviceContext destImage, int destX, int destY, int destWidth, int destHeight, ImageWithDeviceContext srcImage, int srcY, int srcWidth, int srcHeight, Padding stretchExcludeMargin, byte opacity)
        {
            BlendFunction blend = BlendFunction.Default;

            blend.SourceConstantAlpha = opacity;
            IntPtr destDc = destImage.GetHdc();

            if (stretchExcludeMargin.Left > 0)
            {
                NativeMethods.AlphaBlend(destDc, destX, destY + stretchExcludeMargin.Top, stretchExcludeMargin.Left, destHeight - (stretchExcludeMargin.Top + stretchExcludeMargin.Bottom), srcImage.Dc, 0, srcY + stretchExcludeMargin.Top, stretchExcludeMargin.Left, srcHeight - (stretchExcludeMargin.Top + stretchExcludeMargin.Bottom),
                                         blend);
            }

            if (stretchExcludeMargin.Right > 0)
            {
                NativeMethods.AlphaBlend(destDc, destX + (destWidth - stretchExcludeMargin.Right), destY + stretchExcludeMargin.Top, stretchExcludeMargin.Right, destHeight - (stretchExcludeMargin.Bottom + stretchExcludeMargin.Top), srcImage.Dc, srcWidth - stretchExcludeMargin.Right, srcY + stretchExcludeMargin.Top, stretchExcludeMargin.Right, srcHeight - (stretchExcludeMargin.Bottom + stretchExcludeMargin.Top),
                                         blend);
            }

            if (stretchExcludeMargin.Top > 0)
            {
                NativeMethods.AlphaBlend(destDc, destX + stretchExcludeMargin.Left, destY, destWidth - (stretchExcludeMargin.Left + stretchExcludeMargin.Right), stretchExcludeMargin.Top, srcImage.Dc, stretchExcludeMargin.Left, srcY, srcWidth - (stretchExcludeMargin.Left + stretchExcludeMargin.Right), stretchExcludeMargin.Top,
                                         blend);
                if (stretchExcludeMargin.Left > 0)
                {
                    NativeMethods.AlphaBlend(destDc, destX, destY, stretchExcludeMargin.Left, stretchExcludeMargin.Top, srcImage.Dc, 0, srcY, stretchExcludeMargin.Left, stretchExcludeMargin.Top,
                                             blend);
                }

                if (stretchExcludeMargin.Right > 0)
                {
                    NativeMethods.AlphaBlend(destDc, (destWidth - stretchExcludeMargin.Right) + destX, destY, stretchExcludeMargin.Right, stretchExcludeMargin.Top, srcImage.Dc, srcWidth - stretchExcludeMargin.Right, srcY, stretchExcludeMargin.Right, stretchExcludeMargin.Top,
                                             blend);
                }
            }

            if (stretchExcludeMargin.Bottom > 0)
            {
//                WinAPI.AlphaBlend(DestDC, DestX, DestY + (DestHeight - stretchExcludeMargin.Bottom), DestWidth, stretchExcludeMargin.Bottom, srcImage.DC, 0, SrcY + (srcHeight - stretchExcludeMargin.Bottom), srcWidth, stretchExcludeMargin.Bottom,
//                    Blend);

                NativeMethods.AlphaBlend(destDc, destX + stretchExcludeMargin.Left, destY + (destHeight - stretchExcludeMargin.Bottom),
                                         destWidth - (stretchExcludeMargin.Left + stretchExcludeMargin.Right),
                                         stretchExcludeMargin.Top,
                                         srcImage.Dc,
                                         stretchExcludeMargin.Left,
                                         srcY + (srcHeight - stretchExcludeMargin.Bottom),
                                         srcWidth - (stretchExcludeMargin.Left + stretchExcludeMargin.Right),
                                         stretchExcludeMargin.Bottom,
                                         blend);

                if (stretchExcludeMargin.Left > 0)
                {
                    NativeMethods.AlphaBlend(destDc, destX, destY + (destHeight - stretchExcludeMargin.Bottom), stretchExcludeMargin.Left, stretchExcludeMargin.Bottom, srcImage.Dc, 0, srcY + (srcHeight - stretchExcludeMargin.Bottom), stretchExcludeMargin.Left, stretchExcludeMargin.Bottom,
                                             blend);
                }

                if (stretchExcludeMargin.Right > 0)
                {
                    NativeMethods.AlphaBlend(destDc, (destWidth - stretchExcludeMargin.Right) + destX, destY + (destHeight - stretchExcludeMargin.Bottom), stretchExcludeMargin.Right, stretchExcludeMargin.Bottom, srcImage.Dc, srcWidth - stretchExcludeMargin.Right, srcY + (srcHeight - stretchExcludeMargin.Bottom), stretchExcludeMargin.Right, stretchExcludeMargin.Bottom,
                                             blend);
                }
            }

            NativeMethods.AlphaBlend(destDc, destX + stretchExcludeMargin.Left, destY + stretchExcludeMargin.Top, destWidth - (stretchExcludeMargin.Left + stretchExcludeMargin.Right), destHeight - (stretchExcludeMargin.Top + stretchExcludeMargin.Bottom), srcImage.Dc, stretchExcludeMargin.Left, srcY + stretchExcludeMargin.Top, srcWidth - (stretchExcludeMargin.Left + stretchExcludeMargin.Right), srcHeight - (stretchExcludeMargin.Top + stretchExcludeMargin.Bottom),
                                     blend);
            destImage.ReleaseHdc();
        }
Пример #29
0
		public int UxThemeHitTestThemeBackground (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, HitTestOptions options, Rectangle backgroundRectangle, IntPtr hrgn, Point pt, out HitTestCode result)
		{
			XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle (backgroundRectangle);
			int retval;

			int hresult = UXTheme.HitTestThemeBackground (hTheme, dc.GetHdc (), iPartId, iStateId, (uint)options, ref BoundsRect, hrgn, new POINT(pt.X, pt.Y), out retval);
			dc.ReleaseHdc ();

			result = (HitTestCode)retval;
			return hresult;
		}
Пример #30
0
		public int UxThemeGetThemeTextExtent (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, string textToDraw, TextFormatFlags flags, out Rectangle result)
		{
			XplatUIWin32.RECT retval;
			
			int hresult = UXTheme.GetThemeTextExtent (hTheme, dc.GetHdc (), iPartId, iStateId, textToDraw, textToDraw.Length, (int)flags, 0, out retval);
			dc.ReleaseHdc ();

			result = retval.ToRectangle ();
			return hresult;
		}
Пример #31
0
		public int UxThemeGetThemePartSize (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, ThemeSizeType type, out Size result)
		{
			UXTheme.SIZE retval;

			int hresult = UXTheme.GetThemePartSize (hTheme, dc.GetHdc (), iPartId, iStateId, IntPtr.Zero, (int)type, out retval);
			dc.ReleaseHdc ();

			result = retval.ToSize ();
			return hresult;
		}
Пример #32
0
		public int UxThemeGetThemePartSize (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle bounds, ThemeSizeType type, out Size result)
		{
			XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle (bounds);
			UXTheme.SIZE retval;

			int hresult = UXTheme.GetThemePartSize (hTheme, dc.GetHdc (), iPartId, iStateId, ref BoundsRect, (int)type, out retval);
			dc.ReleaseHdc ();

			result = retval.ToSize();
			return hresult;
		}
Пример #33
0
		public int UxThemeGetThemeMargins (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, MarginProperty prop, out Padding result)
		{
			UXTheme.MARGINS retval = new UXTheme.MARGINS ();
			XplatUIWin32.RECT BoundsRect;

			int hresult = UXTheme.GetThemeMargins (hTheme, dc.GetHdc (), iPartId, iStateId, (int)prop, out BoundsRect, out retval);
			dc.ReleaseHdc ();

			result = retval.ToPadding();
			return hresult;
		}