/// <summary>
        /// Sets the property value of the control.
        /// This method is called for all the settable properties defined in UITestControl.PropertyNames
        /// to let the provider override the values. The provider should either support setting of those
        /// properties properly or throw System.NotSupportedException.
        /// </summary>
        /// <param name="uiTestControl">The control for which to set the value.</param>
        /// <param name="propertyName">The name of the property to set.</param>
        /// <param name="propertyValue">The value of the property.</param>
        /// <exception cref="System.NotSupportedException">Property with the given name is not supported.</exception>
        public override void SetPropertyValue(UITestControl uiTestControl, string propertyName, object propertyValue)
        {
            // Simply delegate the call to Word add-in (TBD - for the rest).
            WordSelectionInfo selectionInfo = GetSelectionInfo(uiTestControl);

            WordCommunicator.Instance.SetSelectionProperty(selectionInfo, propertyName, propertyValue);
        }
Beispiel #2
0
        /// <summary>
        /// Sets the property of a given selection.
        /// </summary>
        /// <param name="selectionInfo">The selection info.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="propertyValue">The value of the property.</param>
        public void SetSelectionProperty(WordSelectionInfo selectionInfo, string propertyName, object propertyValue)
        {
            Range selection = this.GetSelection(selectionInfo);

            if (selection == null)
            {
                throw new InvalidOperationException();
            }

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

            switch (propertyName)
            {
            case PropertyNames.Text:
                selection.Text = propertyValue.ToString();
                break;

            case PropertyNames.Start:
                selection.Start = (int)propertyValue;
                break;

            case PropertyNames.End:
                selection.End = (int)propertyValue;
                break;

            default:
                throw new NotSupportedException();
            }
        }
        // Needed to find out if two objects are same or not.
        public override bool Equals(object obj)
        {
            WordSelectionInfo other = obj as WordSelectionInfo;

            if (other != null)
            {
                return(this.StartIndex == other.StartIndex && this.EndIndex == other.EndIndex && object.Equals(this.Parent, other.Parent));
            }

            return(false);
        }
        /// <summary>
        /// Gets the property value of the control.
        /// This method is called for all the properties defined in UITestControl.PropertyNames
        /// to let the provider override the values. The provider should either support those
        /// properties properly or throw System.NotSupportedException.
        /// </summary>
        /// <param name="uiTestControl">The control for which to get the value.</param>
        /// <param name="propertyName">The name of the property to get.</param>
        /// <returns>The value of the property.</returns>
        /// <exception cref="System.NotSupportedException">Property with the given name is not supported.</exception>
        public override object GetPropertyValue(UITestControl uiTestControl, string propertyName)
        {
            // Simply delegate the call to Word add-in.
            WordSelectionInfo selectionInfo = GetSelectionInfo(uiTestControl);

            if (selectionInfo != null)
            {
                return(WordCommunicator.Instance.GetSelectionProperty(selectionInfo, propertyName));
            }

            throw new System.NotSupportedException();
        }
Beispiel #5
0
        /// <summary>
        /// Gets the Range (selection) from the selection info.
        /// </summary>
        /// <param name="selectionInfo">The selection info.</param>
        /// <returns>The Range.</returns>
        private Range GetSelection(WordSelectionInfo selectionInfo)
        {
            Range    sel = null;
            Document doc = this.GetDocument(selectionInfo.Parent);

            if (doc != null)
            {
                sel = doc.Application.Selection.Range;
            }

            return(sel);
        }
        /// <summary>
        /// Creates an appropriate Word UI element.
        /// </summary>
        /// <param name="windowHandle">The window handle.</param>
        /// <param name="rangeInfo">The info on the element.</param>
        /// <returns>The Word UI element.</returns>
        internal UITechnologyElement GetWordRange(IntPtr windowHandle, WordRangeInfo rangeInfo)
        {
            WordSelectionInfo wsi = rangeInfo as WordSelectionInfo;

            if (wsi != null)
            {
                return(new WordSelectionRange(windowHandle, wsi, this));
            }

            WordDocumentInfo wdi = rangeInfo as WordDocumentInfo;

            return(wdi != null ? new WordDocumentRange(windowHandle, wdi, this) : new WordRange(windowHandle, this));
        }
Beispiel #7
0
        /// <summary>
        /// Scrolls a given selection into view.
        /// </summary>
        /// <param name="selectionInfo">The selection info.</param>
        public void ScrollIntoView(WordSelectionInfo selectionInfo)
        {
            if (selectionInfo == null)
            {
                throw new ArgumentNullException("selectionInfo");
            }

            // Use Word's Object Model to get the required.
            Document doc = this.GetDocument(selectionInfo.Parent);

            if (doc != null)
            {
                doc.Activate();
                this.GetBoundingRectangle(selectionInfo);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Gets the property of a given selection.
        /// </summary>
        /// <param name="selectionInfo">The selection info.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <returns>The value of the property.</returns>
        public object GetSelectionProperty(WordSelectionInfo selectionInfo, string propertyName)
        {
            // Use Word's Object Model to get the required.
            Range selection = this.GetSelection(selectionInfo);

            if (selection == null)
            {
                throw new InvalidOperationException();
            }

            switch (propertyName)
            {
            case PropertyNames.Enabled: return(true);    // TODO - Needed to add support for a "locked" selection.

            case PropertyNames.DocumentName: return(selection.Document.Name);

            case PropertyNames.End: return(selection.End);

            case PropertyNames.Start: return(selection.Start);

            case PropertyNames.Text: return(selection.Text);

            case PropertyNames.TextLength: return(selection.Text.Length);

            case PropertyNames.BoundingRectangle:
                double[]           selectionRect = this.GetBoundingRectangle(selectionInfo);
                NativeMethods.RECT windowRect;
                int top, width, height;
                int left = top = width = height = -1;

                if (NativeMethods.GetWindowRect(NativeMethods.FindWindowEx(0, 0, "OpusApp", 0), out windowRect))
                {
                    left   = (int)selectionRect[0];
                    top    = (int)selectionRect[1];
                    width  = (int)selectionRect[2];
                    height = (int)selectionRect[3];
                }

                return(new System.Drawing.Rectangle(left, top, width, height));

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #9
0
        /// <summary>
        /// Sets focus on a given selection. (in Word, the focus is where the cursor is)
        /// </summary>
        /// <param name="selectionInfo">The selection info.</param>
        public void SetFocus(WordSelectionInfo selectionInfo)
        {
            if (selectionInfo == null)
            {
                throw new ArgumentNullException("selectionInfo");
            }

            // Use Word's Object Model to get the required.
            Document doc = this.GetDocument(selectionInfo.Parent);

            if (doc != null)
            {
                doc.Activate();
                Range selection = this.GetSelection(selectionInfo);
                if (selection != null)
                {
                    selection.GoTo(doc.Application.Selection);
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Gets the bounding rectangle of the Word range. (Maps to Word)
        /// </summary>
        /// <param name="selectionInfo">The selection info.</param>
        /// <returns>The bounding rectangle as an array.
        /// The values from Word are in Pixels).</returns>
        public double[] GetBoundingRectangle(WordSelectionInfo selectionInfo)
        {
            // Use Words's Object Model to get the required.
            double[] rect = new double[4];
            rect[0] = rect[1] = rect[2] = rect[3] = -1;

            Range selection = this.GetSelection(selectionInfo);

            if (selection != null)
            {
                int left, top, width, height;
                selection.Document.Windows[selection.Document.Name].GetPoint(out left, out top, out width, out height, selection);

                rect[0] = left;
                rect[1] = top;
                rect[2] = width;
                rect[3] = height;
            }

            return(rect);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="WordSelectionRange"/> class.
 /// </summary>
 /// <param name="windowHandle">The window handle.</param>
 /// <param name="selectionInfo">The selection info.</param>
 /// <param name="manager">The technology manager.</param>
 internal WordSelectionRange(IntPtr windowHandle, WordSelectionInfo selectionInfo, WordTechnologyManager manager)
     : base(windowHandle, manager)
 {
     this.SelectionInfo = selectionInfo;
 }