예제 #1
0
        public void TransformPatternCachedTest()
        {
            using (AppHost host = new AppHost("notepad.exe", ""))
            {
                CacheRequest req = new CacheRequest();
                req.Add(TransformPattern.Pattern);
                req.Add(TransformPattern.CanMoveProperty);
                req.Add(TransformPattern.CanResizeProperty);
                req.Add(TransformPattern.CanRotateProperty);
                using (req.Activate())
                {
                    AutomationElement cachedEl = host.Element.GetUpdatedCache(req);

                    TransformPattern transformPattern = (TransformPattern)cachedEl.GetCachedPattern(TransformPattern.Pattern);
                    // Coded to expectations for an explorer window
                    Assert.IsTrue(transformPattern.Cached.CanMove);
                    Assert.IsTrue(transformPattern.Cached.CanResize);
                    Assert.IsFalse(transformPattern.Cached.CanRotate);

                    // Little move
                    transformPattern.Move(10, 10);

                    // Little resize
                    transformPattern.Resize(200, 200);
                }
            }
        }
예제 #2
0
        public void NoClickablePointTest()
        {
            // Launch a notepad and position it
            using (AppHost host1 = new AppHost("notepad.exe", ""))
            {
                TransformPattern transformPattern1 = (TransformPattern)host1.Element.GetCurrentPattern(TransformPattern.Pattern);
                transformPattern1.Move(0, 0);
                transformPattern1.Resize(400, 300);

                System.Windows.Point pt1 = host1.Element.GetClickablePoint();

                // Launch a second notepad and position it on top
                using (AppHost host2 = new AppHost("notepad.exe", ""))
                {
                    TransformPattern transformPattern2 = (TransformPattern)host2.Element.GetCurrentPattern(TransformPattern.Pattern);
                    transformPattern2.Move(0, 0);
                    transformPattern2.Resize(400, 300);

                    // Now try it again for host1
                    try
                    {
                        System.Windows.Point pt1again = host1.Element.GetClickablePoint();
                        Assert.Fail("expected exception");
                    }
                    catch (NoClickablePointException)
                    {
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Capture the window region of the specified size
        /// </summary>
        public Microsoft.Test.RenderingVerification.ImageAdapter CaptureWindow(double targetWidth, double targetHeight)
        {
            //Reposition Mouse to the origin
            Input.Input.MoveTo(new System.Windows.Point(0, 0));

            //Get window, move it to the origin
            AutomationElement windowElement = AutomationElement.FromHandle(hWndHost);
            WindowPattern     window        = windowElement.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;

            window.SetWindowVisualState(WindowVisualState.Normal);
            TransformPattern transform = windowElement.GetCurrentPattern(TransformPattern.Pattern) as TransformPattern;

            transform.Move(0, 0);

            //we need to size the window (IE) to get the client area the correct size
            //Get the size of the target window
            AutomationElement clientElement = windowElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "RootBrowserWindow"));
            Rect clientRect = (Rect)clientElement.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);

            //Determine what the new size of the window should be to get the client area the correct size
            System.Windows.Rect ierect = (System.Windows.Rect)windowElement.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);
            double w = (double)(ierect.Width + targetWidth - clientRect.Width);
            double h = (double)(ierect.Height + targetHeight - clientRect.Height);

            transform.Resize(w, h);

            // Wait for document to load and resize to occurs (assuming render would have occured)
            Thread.Sleep(3000);

            //Get bounds of content region, convert to Rectangle form, and capture to image adapter
            Rect ContentRect = (Rect)clientElement.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);

            System.Drawing.Rectangle captureRect = new Rectangle((int)ContentRect.X, (int)ContentRect.Y, (int)ContentRect.Width, (int)ContentRect.Height);
            return(new Microsoft.Test.RenderingVerification.ImageAdapter(captureRect));
        }
예제 #4
0
        public bool SetSize(double width, double height)
        {
            AutomationElement autoElement = GetCurrentAutoElement();

            if (autoElement == null)
            {
                return(false);
            }
            TransformPattern transformPattern = null;
            object           objPattern;

            if (true == autoElement.TryGetCurrentPattern(TransformPattern.Pattern, out objPattern))
            {
                transformPattern = objPattern as TransformPattern;
            }
            if (transformPattern != null)
            {
                Rect bound = autoElement.Current.BoundingRectangle;
                if (bound == null)
                {
                    return(false);
                }
                transformPattern.Resize(width, height);
                return(true);
            }
            // if not supported TransformPattern
            else
            {
            }
            return(false);
        }
예제 #5
0
        /// <summary>
        /// Resizes the control.
        /// </summary>
        /// <param name="control">The control to resize</param>
        /// <param name="width">desired width in pixels</param>
        /// <param name="height">the desired height in pixels</param>
        /// <returns>
        /// 0 if no problems encountered, -1 if InvalidOperationException is raised
        /// </returns>
        internal static int Resize(AutomationElement control, double width, double height)
        {
            TransformPattern pat = (TransformPattern)CommonUIAPatternHelpers.CheckPatternSupport(TransformPattern.Pattern, control);

            if (pat.Current.CanResize)
            {
                pat.Resize(width, height);
                return(0);
            }
            return(-1);
        }
예제 #6
0
파일: Window.cs 프로젝트: ABEMBARKA/monoUI
        public void Resize(double width, double height, bool log)
        {
            if (log)
            {
                procedureLogger.Action(string.Format("Resize window to {0} width, {1} height.", width, height));
            }

            TransformPattern tp = (TransformPattern)element.GetCurrentPattern(TransformPattern.Pattern);

            tp.Resize(width, height);
        }
예제 #7
0
        private AutomationElement StartApp(string app)
        {
            if (File.Exists(app))
            {
                AutomationElement targetElement;

                // Start application.
                Process p = Process.Start(app);

                //// Give application a second to startup.
                Thread.Sleep(2000);

                targetElement = AutomationElement.FromHandle(p.MainWindowHandle);
                if (targetElement == null)
                {
                    return(null);
                }
                else
                {
                    AutomationEventHandler targetClosedHandler =
                        new AutomationEventHandler(onTargetClose);
                    Automation.AddAutomationEventHandler(
                        WindowPattern.WindowClosedEvent,
                        targetElement, TreeScope.Element, targetClosedHandler);

                    // Set size and position of target.
                    TransformPattern targetTransformPattern =
                        targetElement.GetCurrentPattern(TransformPattern.Pattern)
                        as TransformPattern;
                    if (targetTransformPattern == null)
                    {
                        return(null);
                    }
                    targetTransformPattern.Resize(550, 400);
                    targetTransformPattern.Move(
                        clientWindow.Left + clientWindow.Width + 25, clientWindow.Top);

                    Output("Target started.");

                    // Return the AutomationElement
                    return(targetElement);
                }
            }
            else
            {
                Output(app + " not found.");
                return(null);
            }
        }
        // </Snippet103>

        // <Snippet104>
        ///--------------------------------------------------------------------
        /// <summary>
        /// Calls the TransformPattern.Resize() method for an associated
        /// automation element.
        /// </summary>
        /// <param name="transformPattern">
        /// The TransformPattern control pattern obtained from
        /// an automation element.
        /// </param>
        /// <param name="width">
        /// The requested width of the automation element.
        /// </param>
        /// <param name="height">
        /// The requested height of the automation element.
        /// </param>
        ///--------------------------------------------------------------------
        private void ResizeElement(
            TransformPattern transformPattern, double width, double height)
        {
            try
            {
                if (transformPattern.Current.CanResize)
                {
                    transformPattern.Resize(width, height);
                }
            }
            catch (InvalidOperationException)
            {
                // object is not able to perform the requested action
                return;
            }
        }
예제 #9
0
        public void TransformPatternTest()
        {
            // Launch a notepad and position it
            using (AppHost host = new AppHost("notepad.exe", ""))
            {
                TransformPattern transformPattern = (TransformPattern)host.Element.GetCurrentPattern(TransformPattern.Pattern);
                // Coded to expectations for an explorer window
                Assert.IsTrue(transformPattern.Current.CanMove);
                Assert.IsTrue(transformPattern.Current.CanResize);
                Assert.IsFalse(transformPattern.Current.CanRotate);

                // Little move
                transformPattern.Move(10, 10);

                // Little resize
                transformPattern.Resize(200, 200);
            }
        }
예제 #10
0
        public static void WindowResize(AutomationElement window, System.Windows.Point pos)
        {
            TransformPattern pattern = window.GetCurrentPattern(TransformPattern.Pattern) as TransformPattern;

            pattern.Resize(pos.X, pos.Y);
        }
        private void setWindowsTileBottom()
        {
            Process[] processes = Process.GetProcessesByName("Revit");

            if (0 < processes.Length)
            {
                IntPtr mainWinHandle = processes[0].MainWindowHandle;
                if (mainWinHandle != null)
                {
                    AutomationElement MainWndAutElem = AutomationElement.FromHandle(mainWinHandle);
                    if (MainWndAutElem != null)
                    {
                        Condition MainWndConditions = new AndCondition(
                            new PropertyCondition(AutomationElement.ClassNameProperty, "MDIClient"),
                            new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane)
                            );

                        AutomationElementCollection MainWndElementCollection = MainWndAutElem.FindAll(TreeScope.Children, MainWndConditions);
                        if (MainWndElementCollection.Count > 0)
                        {
                            AutomationElement MDIClientAutElem = MainWndElementCollection[0];
                            if (MDIClientAutElem != null)
                            {
                                Condition MDIClientConditions = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window);

                                AutomationElementCollection MDIClientElementCollection = MDIClientAutElem.FindAll(TreeScope.Children, MDIClientConditions);
                                if (MDIClientElementCollection.Count > 0)
                                {
                                    int mdiWidth  = this.drawAreaRectangle.Right - this.drawAreaRectangle.Left;
                                    int mdiHeight = this.drawAreaRectangle.Bottom - this.drawAreaRectangle.Top;

                                    int activeViewX      = this.drawAreaRectangle.Left;
                                    int activeViewY      = this.drawAreaRectangle.Top;
                                    int activeViewWidth  = mdiWidth;
                                    int activeViewHeight = mdiHeight;

                                    int otherViewsY      = 0;
                                    int otherViewsWidth  = 0;
                                    int otherViewsHeight = 0;

                                    if (MDIClientElementCollection.Count > 1)
                                    {
                                        activeViewWidth  = mdiWidth;
                                        activeViewHeight = (int)Math.Floor((double)(0.01 * tyleStep * mdiHeight));

                                        otherViewsWidth  = (int)Math.Floor((double)(mdiWidth / (MDIClientElementCollection.Count - 1)));
                                        otherViewsHeight = mdiHeight - activeViewHeight;

                                        otherViewsY = this.drawAreaRectangle.Top;
                                        activeViewX = this.drawAreaRectangle.Left;
                                        activeViewY = otherViewsY + otherViewsHeight + 1;
                                    }

                                    int activeViewIndex = getActiveViewIndex(MDIClientElementCollection);

                                    int otherViewNum = 0;
                                    for (int v = 0; v < MDIClientElementCollection.Count; v++)
                                    {
                                        AutomationElement ViewWndAutElem = MDIClientElementCollection[v];
                                        if (ViewWndAutElem != null)
                                        {
                                            try
                                            {
                                                WindowPattern ViewWindowPattern = ViewWndAutElem.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
                                                if (ViewWindowPattern != null)
                                                {///test why pattern is not matched?
                                                    ViewWindowPattern.SetWindowVisualState(WindowVisualState.Normal);

                                                    TransformPattern ViewTransformPattern = ViewWndAutElem.GetCurrentPattern(TransformPattern.Pattern) as TransformPattern;
                                                    if (ViewTransformPattern != null)
                                                    {
                                                        if (v == activeViewIndex)
                                                        {
                                                            ViewTransformPattern.Move(activeViewX, activeViewY);
                                                            ViewTransformPattern.Resize(activeViewWidth, activeViewHeight);
                                                        }
                                                        else
                                                        {
                                                            ViewTransformPattern.Move((activeViewX + otherViewNum * otherViewsWidth), otherViewsY);
                                                            ViewTransformPattern.Resize(otherViewsWidth, otherViewsHeight);
                                                            otherViewNum++;
                                                        }
                                                    }
                                                }
                                            }
                                            catch (Exception exc)
                                            {
                                            }
                                        }
                                    }

                                    foreach (UIView curUIView in this.uidoc.GetOpenUIViews())
                                    {
                                        curUIView.ZoomToFit();
                                    }

                                    this.tyleType = TileType.Bottom;
                                }
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// setWindowsTileLeft
        /// debug this method only!!!
        /// </summary>
        private void setWindowsTileLeft()
        {
            //
            //UIApplication uiapp = commandData.Application;
            //UIDocument uidoc = uiapp.ActiveUIDocument;
            //Document doc = uidoc.Document;
            //View view = doc.ActiveView;
            //UIView uiview = null;
            //IList<UIView> uiviews = uidoc.GetOpenUIViews();

            //foreach (UIView uv in uiviews)
            //{
            //    if (uv.ViewId.Equals(view.Id))
            //    {
            //        uiview = uv;
            //        break;
            //    }
            //}
            //


            Process[] processes = Process.GetProcessesByName("Revit");

            if (0 < processes.Length)
            {
                //главное окно процесса
                IntPtr mainWinHandle = processes[0].MainWindowHandle;
                if (mainWinHandle != null)
                {
                    //его приведение к типу
                    AutomationElement MainWndAutElem = AutomationElement.FromHandle(mainWinHandle);
                    if (MainWndAutElem != null)
                    {
                        Condition MainWndConditions = new AndCondition(
                            new PropertyCondition(AutomationElement.ClassNameProperty, "MDIClient"),
                            new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane)
                            );
                        //
                        //AutomationElementCollection subwindows =
                        //MainWndAutElem.FindAll(TreeScope.Children,
                        //  new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane));
                        //
                        //var allMDIClients =  FindByMultipleConditions(MainWndAutElem);

                        List <IntPtr>               allChildWindows = new WindowHandleInfo(processes[0].MainWindowHandle).GetAllChildHandles();
                        AutomationElement           ael             = AutomationElement.FromHandle(allChildWindows[0]);
                        Condition                   cond            = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane);//.Window);
                        AutomationElementCollection collection      = ael.FindAll(TreeScope.Children, cond);

                        AutomationElementCollection MainWndElementCollection = collection;// MainWndAutElem.FindAll(TreeScope.Children, MainWndConditions);

                        //MainWndElementCollection = allMDIClients;
                        if (MainWndElementCollection.Count > 0)
                        {
                            AutomationElement MDIClientAutElem = MainWndElementCollection[0];
                            if (MDIClientAutElem != null)
                            {
                                Condition MDIClientConditions = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window);
                                //Возвращает все объекты AutomationElement, которые удовлетворяют заданному условию.
                                // Если совпадений нет, возвращается пустая коллекция.
                                AutomationElementCollection MDIClientElementCollection = MDIClientAutElem.FindAll(TreeScope.Children, MDIClientConditions);
                                if (MDIClientElementCollection.Count > 0)
                                {
                                    int mdiWidth  = this.drawAreaRectangle.Right - this.drawAreaRectangle.Left;
                                    int mdiHeight = this.drawAreaRectangle.Bottom - this.drawAreaRectangle.Top;

                                    int activeViewX      = this.drawAreaRectangle.Left;
                                    int activeViewY      = this.drawAreaRectangle.Top;
                                    int activeViewWidth  = mdiWidth;
                                    int activeViewHeight = mdiHeight;

                                    int otherViewsX      = 0;
                                    int otherViewsWidth  = 0;
                                    int otherViewsHeight = 0;

                                    if (MDIClientElementCollection.Count > 1)
                                    {
                                        activeViewX      = this.drawAreaRectangle.Left;
                                        activeViewY      = this.drawAreaRectangle.Top;
                                        activeViewWidth  = (int)Math.Floor((double)(0.01 * tyleStep * mdiWidth));
                                        activeViewHeight = mdiHeight;

                                        otherViewsX      = activeViewX + activeViewWidth + 1;
                                        otherViewsWidth  = mdiWidth - activeViewWidth;
                                        otherViewsHeight = (int)Math.Floor((double)(mdiHeight / (MDIClientElementCollection.Count - 1)));
                                    }

                                    int activeViewIndex = getActiveViewIndex(MDIClientElementCollection);

                                    int otherViewNum = 0;
                                    for (int v = 0; v < MDIClientElementCollection.Count; v++)
                                    {
                                        AutomationElement ViewWndAutElem = MDIClientElementCollection[v];
                                        if (ViewWndAutElem != null)
                                        {
                                            try
                                            {
                                                WindowPattern ViewWindowPattern = ViewWndAutElem.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
                                                if (ViewWindowPattern != null)
                                                {
                                                    ViewWindowPattern.SetWindowVisualState(WindowVisualState.Normal);

                                                    TransformPattern ViewTransformPattern = ViewWndAutElem.GetCurrentPattern(TransformPattern.Pattern) as TransformPattern;
                                                    if (ViewTransformPattern != null)
                                                    {
                                                        if (v == activeViewIndex)
                                                        {
                                                            ViewTransformPattern.Move(activeViewX, activeViewY);
                                                            ViewTransformPattern.Resize(activeViewWidth, activeViewHeight);
                                                        }
                                                        else
                                                        {
                                                            ViewTransformPattern.Move(otherViewsX, (activeViewY + otherViewNum * otherViewsHeight));
                                                            ViewTransformPattern.Resize(otherViewsWidth, otherViewsHeight);
                                                            otherViewNum++;
                                                        }
                                                    }
                                                }
                                            }
                                            catch (Exception exc)
                                            {
                                            }
                                        }
                                    }


                                    foreach (UIView curUIView in this.uidoc.GetOpenUIViews())
                                    {
                                        curUIView.ZoomToFit();
                                    }

                                    this.tyleType = TileType.Left;
                                }
                            }
                        }
                    }
                }
            }
        }