private void FontStylePropertyTranslator(object host, string propertyName, object value) { WinFormsAdapter adapter = GetAdapter(host); if (adapter != null) { if (value is SW.FontStyle) { SD.FontStyle style; if ((SW.FontStyle)value == SW.FontStyles.Normal) { style = SD.FontStyle.Regular; } else { style = SD.FontStyle.Italic; } if (HostUtils.FontWeightIsBold(Host.FontWeight)) { style |= SD.FontStyle.Bold; } adapter.Font = new SD.Font(CurrentFontFamily, CurrentFontSize, style); } } }
private static double ScaleFactor(double value, Orientation orientation, double dpiScale) { //This is a guard against possible unset scale value (which shouldn't happen) if (HostUtils.IsZero(value)) { value = 1.0; } return(value * dpiScale); }
private static double ScaleFactor(double value, Orientation orientation) { //This is a guard against possible unset scale value (which shouldn't happen) if (HostUtils.IsZero(value)) { value = 1.0; } return(value * HostUtils.PixelsPerInch(orientation) / systemWindowsPixelsPerInch); }
private void ScaleChild() { bool skewed; Vector newScale = HostUtils.GetScale(this, out skewed); if (skewed) { OnLayoutError(); } _currentScale = ScaleChild(newScale); }
internal static bool IsRotated(Visual visual) { // Determine whether WindowsFormsHost is rotated Point pOrigin = HostUtils.TransformToRootPoint(visual, new Point(0.0, 0.0)); Point pX = HostUtils.TransformToRootPoint(visual, new Point(1.0, 0.0)); Point pY = HostUtils.TransformToRootPoint(visual, new Point(0.0, 1.0)); Vector xComponent = pX - pOrigin; Vector yComponent = pY - pOrigin; return(xComponent.X < 0 || yComponent.Y < 0); }
internal static Vector GetScale(Visual visual, out bool skewed) { // Determine whether WindowsFormsHost scaling has changed Point pOrigin = HostUtils.TransformToRootPoint(visual, new Point(0.0, 0.0)); Point pX = HostUtils.TransformToRootPoint(visual, new Point(1.0, 0.0)); Point pY = HostUtils.TransformToRootPoint(visual, new Point(0.0, 1.0)); Vector xComponent = pX - pOrigin; Vector yComponent = pY - pOrigin; skewed = (!IsZero(xComponent.Y) || !IsZero(yComponent.X)); return(new Vector(xComponent.Length, yComponent.Length)); }
private void FontWeightPropertyTranslator(object host, string propertyName, object value) { WinFormsAdapter adapter = GetAdapter(host); if (adapter != null && value is SW.FontWeight) { SD.FontStyle style = CurrentFontStyle; if (HostUtils.FontWeightIsBold((SW.FontWeight)value)) { style |= SD.FontStyle.Bold; } adapter.Font = new SD.Font(CurrentFontFamily, CurrentFontSize, style); } }
internal static RenderTargetBitmap GetRenderTargetBitmapForVisual(int width, int height, Visual visualToRender) { if (width < 1 || height < 1) { return(null); } RenderTargetBitmap bmp = new RenderTargetBitmap( width, height, HostUtils.PixelsPerInch(Orientation.Horizontal), HostUtils.PixelsPerInch(Orientation.Vertical), PixelFormats.Pbgra32); bmp.Render(visualToRender); return(bmp); }
internal static SD.Bitmap GetBitmapForTransparentWindowsFormsHost(WindowsFormsHost host) { WinFormsAdapter adapter = WindowsFormsHostPropertyMap.GetAdapter(host); if (adapter == null) { return(null); } //We need to find our highest-level ancestor that's a FrameworkElement: //if it's not a FrameworkElement, we don't know how big it is, and can't //properly deal with it. FrameworkElement frameworkElementAncestor = GetFrameworkElementAncestor(host); if (frameworkElementAncestor != null) { RenderTargetBitmap bmp = GetBitmapForFrameworkElement(frameworkElementAncestor); Point hostPoint = new Point(0, 0); Point parentPoint = new Point(0, 0); if (HostUtils.IsRotated(host)) { //Image is upside down. Need the lower right corner of host and the //lower right corner of the parent. hostPoint = HostUtils.TransformToParentPoint(host, frameworkElementAncestor, new Point(host.ActualWidth, host.ActualHeight)); parentPoint = HostUtils.TransformToParentPoint(frameworkElementAncestor, frameworkElementAncestor, new Point(frameworkElementAncestor.ActualWidth, frameworkElementAncestor.ActualHeight)); } else { //Need upper left corner of host and the upper left corner of the parent. hostPoint = HostUtils.TransformToParentPoint(host, frameworkElementAncestor, new Point(0, 0)); parentPoint = HostUtils.TransformToParentPoint(frameworkElementAncestor, frameworkElementAncestor, new Point(0, 0)); } hostPoint.Offset(-parentPoint.X, -parentPoint.Y); return(GetBitmapFromRenderTargetBitmap(adapter, bmp, hostPoint)); } return(null); }
private void BackgroundPropertyTranslator(object host, string propertyName, object value) { SWM.Brush brush = value as SWM.Brush; if (value == null) { //If they passed null (not to be confused with "passed us a non-null non-Brush"), //we should look up our parent chain. DependencyObject parent = host as WindowsFormsHost; do { brush = (Brush)parent.GetValue(SWC.Control.BackgroundProperty); parent = VisualTreeHelper.GetParent(parent); } while (parent != null && brush == null); } WinFormsAdapter adapter = GetAdapter(host); if (adapter != null && brush != null) { WindowsFormsHost windowsFormsHost = host as WindowsFormsHost; if (windowsFormsHost != null) { SWF.Control child = windowsFormsHost.Child; if (HostUtils.BrushIsSolidOpaque(brush)) { bool ignore; SD.Color wfColor = WindowsFormsHostPropertyMap.TranslateSolidOrGradientBrush(brush, out ignore); adapter.BackColor = wfColor; } else { SD.Bitmap backgroundImage = HostUtils.GetBitmapForWindowsFormsHost(windowsFormsHost, brush); HostUtils.SetBackgroundImage(adapter, child, backgroundImage); } } } }
private static void UpdateBackgroundImage(ElementHost host) { if (host != null && host.HostContainerInternal != null) { if (host.BackColorTransparent) { Control parent = host.Parent; if (parent != null && parent.Visible) { using (SD.Bitmap parentBitmap = HostUtils.GetCoveredPortionOfBitmap(parent, host)) { host.HostContainerInternal.Background = new SWM.ImageBrush(Convert.ToSystemWindowsMediaImagingBitmapImage(parentBitmap)); } } } else { using (SD.Bitmap elementHostBitmap = HostUtils.GetBitmapOfControl(host, host)) { host.HostContainerInternal.Background = new SWM.ImageBrush(Convert.ToSystemWindowsMediaImagingBitmapImage(elementHostBitmap)); } } } }