示例#1
0
        internal static Rect GetToolBarButtonImageBounds(FragmentControlProvider provider,
                                                         SWF.ToolBarButton buttonBase)
        {
            //Implementation highly based in ThemeWin32Classic.ButtonBase_DrawImage method

            Image image;
            int   imageX;
            int   imageY;
            int   imageWidth;
            int   imageHeight;

            Rect buttonRect
                = (Rect)provider.GetPropertyValue(AutomationElementIdentifiers.BoundingRectangleProperty.Id);

            int width = (int)buttonRect.Width;

            image = buttonBase.Image;

            if (image == null)
            {
                return(Rect.Empty);
            }

            imageWidth  = image.Width;
            imageHeight = image.Height;

            GetXYFromWidthInTopCenterAlignment(width, imageWidth, out imageX, out imageY);

            imageX += (int)buttonRect.X;
            imageY += (int)buttonRect.Y;

            Rect imageRect = new Rect(imageX, imageY, imageWidth, imageHeight);

            buttonRect.Intersect(imageRect);

            return(buttonRect);
        }
示例#2
0
        internal static Rect GetButtonBaseImageBounds(FragmentControlProvider provider,
                                                      SWF.ButtonBase buttonBase)
        {
            //Implementation highly based in ThemeWin32Classic.ButtonBase_DrawImage method

            Image image;
            int   imageX;
            int   imageY;
            int   imageWidth;
            int   imageHeight;
            int   width  = buttonBase.Width;
            int   height = buttonBase.Height;

            if (buttonBase.ImageIndex != -1)
            {
                image = buttonBase.ImageList.Images [buttonBase.ImageIndex];
            }
            else
            {
                image = buttonBase.Image;
            }

            if (image == null)
            {
                return(Rect.Empty);
            }

            imageWidth  = image.Width;
            imageHeight = image.Height;

            switch (buttonBase.ImageAlign)
            {
            case ContentAlignment.TopLeft: {
                imageX = 5;
                imageY = 5;
                break;
            }

            case ContentAlignment.TopCenter: {
                GetXYFromWidthInTopCenterAlignment(width, imageWidth, out imageX, out imageY);
                break;
            }

            case ContentAlignment.TopRight: {
                imageX = width - imageWidth - 5;
                imageY = 5;
                break;
            }

            case ContentAlignment.MiddleLeft: {
                imageX = 5;
                imageY = (height - imageHeight) / 2;
                break;
            }

            case ContentAlignment.MiddleCenter: {
                imageX = (width - imageWidth) / 2;
                imageY = (height - imageHeight) / 2;
                break;
            }

            case ContentAlignment.MiddleRight: {
                imageX = width - imageWidth - 4;
                imageY = (height - imageHeight) / 2;
                break;
            }

            case ContentAlignment.BottomLeft: {
                imageX = 5;
                imageY = height - imageHeight - 4;
                break;
            }

            case ContentAlignment.BottomCenter: {
                imageX = (width - imageWidth) / 2;
                imageY = height - imageHeight - 4;
                break;
            }

            case ContentAlignment.BottomRight: {
                imageX = width - imageWidth - 4;
                imageY = height - imageHeight - 4;
                break;
            }

            default: {
                imageX = 5;
                imageY = 5;
                break;
            }
            }

            Rect buttonRect
                = (Rect)provider.GetPropertyValue(AutomationElementIdentifiers.BoundingRectangleProperty.Id);

            imageX += (int)buttonRect.X;
            imageY += (int)buttonRect.Y;

            Rect imageRect = new Rect(imageX, imageY, imageWidth, imageHeight);

            buttonRect.Intersect(imageRect);

            return(buttonRect);
        }