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);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the WindowsFormsHost class.
        /// </summary>
        public WindowsFormsHost()
            : base()
        {
            this._hostContainerInternal = new WinFormsAdapter(this);

            _propertyMap = new WindowsFormsHostPropertyMap(this);
        }
        /// <summary>
        ///     Translator for individual property
        /// </summary>
        private void FlowDirectionPropertyTranslator(object host, string propertyName, object value)
        {
            SWF.Control     childControl = GetChildControl(host, FlowDirectionPropertyTranslator, value);
            WinFormsAdapter adapter      = GetAdapter(host);

            if (adapter != null && childControl != null)
            {
                if (value is SW.FlowDirection)
                {
                    const BindingFlags memberAccess = BindingFlags.Public | BindingFlags.Instance;

                    //use reflection to see if this control supports the RightToLeftLayout property
                    PropertyInfo propertyInfo = childControl.GetType().GetProperty("RightToLeftLayout", memberAccess);
                    switch ((SW.FlowDirection)value)
                    {
                    case SW.FlowDirection.RightToLeft:
                        adapter.RightToLeft = SWF.RightToLeft.Yes;
                        if (propertyInfo != null)
                        {
                            propertyInfo.SetValue(childControl, true, null);
                        }
                        break;

                    case SW.FlowDirection.LeftToRight:
                        adapter.RightToLeft = SWF.RightToLeft.No;
                        if (propertyInfo != null)
                        {
                            propertyInfo.SetValue(childControl, false, null);
                        }
                        break;
                    }
                }
            }
        }
Ejemplo n.º 4
0
 internal static void SetBackgroundImage(WinFormsAdapter adapter, Control child, SD.Bitmap image)
 {
     if (child != null &&
         (child.BackgroundImage == null || child.BackgroundImage == adapter.BackgroundImage))
     {
         child.BackgroundImage = image;
     }
     adapter.BackgroundImage = image;
 }
        /// <summary>
        ///     Translator for individual property
        /// </summary>
        private void IsEnabledPropertyTranslator(object host, string propertyName, object value)
        {
            WinFormsAdapter adapter = GetAdapter(host);

            if (adapter != null && value is bool)
            {
                adapter.Enabled = (bool)value;
            }
        }
        private void FontSizePropertyTranslator(object host, string propertyName, object value)
        {
            WinFormsAdapter adapter = GetAdapter(host);

            if (adapter != null && value is double)
            {
                double pointSize = Convert.FontSizeToSystemDrawing((double)value);
                adapter.Font = new SD.Font(CurrentFontFamily, (float)pointSize, CurrentFontStyle);
            }
        }
        /// <summary>
        ///     Translator for individual property
        /// </summary>
        private void PaddingPropertyTranslator(object host, string propertyName, object value)
        {
            SWF.Control     childControl = GetChildControl(host, PaddingPropertyTranslator, value);
            WinFormsAdapter adapter      = GetAdapter(host);

            if (adapter != null && childControl != null)
            {
                if (value is SW.Thickness)
                {
                    childControl.Padding = Convert.ToSystemWindowsFormsPadding((SW.Thickness)value);
                }
            }
        }
        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);
            }
        }
        private void FontFamilyPropertyTranslator(object host, string propertyName, object value)
        {
            WinFormsAdapter adapter = GetAdapter(host);

            if (adapter != null)
            {
                SWM.FontFamily family = value as SWM.FontFamily;
                if (family != null)
                {
                    string familySource = family.Source;
                    adapter.Font = new SD.Font(familySource, adapter.Font.Size, adapter.Font.Style);
                }
            }
        }
 /// <summary>
 ///     Translator for individual property
 /// </summary>
 private void ForegroundPropertyTranslator(object host, string propertyName, object value)
 {
     SWM.Brush brush = value as SWM.Brush;
     if (brush != null)
     {
         bool     defined;
         SD.Color wfColor = WindowsFormsHostPropertyMap.TranslateSolidOrGradientBrush(brush, out defined);
         if (defined)
         {
             WinFormsAdapter adapter = GetAdapter(host);
             if (adapter != null)
             {
                 adapter.ForeColor = wfColor;
             }
         }
     }
 }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        internal static SD.Bitmap GetBitmapForOpaqueWindowsFormsHost(WindowsFormsHost host, Brush brush)
        {
            WinFormsAdapter adapter = WindowsFormsHostPropertyMap.GetAdapter(host);

            if (adapter == null)
            {
                return(null);
            }

            DrawingVisual  drawingVisual  = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            drawingContext.DrawRectangle(brush, null, new Rect(0, 0, adapter.Width, adapter.Height));
            drawingContext.Close();

            RenderTargetBitmap bmp = GetRenderTargetBitmapForVisual(adapter.Width, adapter.Height, drawingVisual);

            return(GetBitmapFromRenderTargetBitmap(adapter, bmp, new Point(0, 0)));
        }
        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);
                    }
                }
            }
        }