/// <summary>
        ///
        /// </summary>
        /// <param name="bookFolderPath"></param>
        /// <param name="imgOrDivWithBackgroundImage">Can be an XmlElement (during testing)</param>
        /// <param name="imageInfo"></param>
        /// <param name="progress"></param>
        public void ChangePicture(string bookFolderPath, ElementProxy imgOrDivWithBackgroundImage, PalasoImage imageInfo,
			IProgress progress)
        {
            var isSameFile = IsSameFilePath(bookFolderPath, HtmlDom.GetImageElementUrl(imgOrDivWithBackgroundImage), imageInfo);
            var imageFileName = ImageUtils.ProcessAndSaveImageIntoFolder(imageInfo, bookFolderPath, isSameFile);
            HtmlDom.SetImageElementUrl(imgOrDivWithBackgroundImage,
                UrlPathString.CreateFromUnencodedString(imageFileName));
            UpdateMetadataAttributesOnImage(imgOrDivWithBackgroundImage, imageInfo);
        }
        public static void UpdateMetadataAttributesOnImage(ElementProxy imgOrDivWithBackgroundImage, PalasoImage imageInfo)
        {
            //see also Book.UpdateMetadataAttributesOnImage(), which does the same thing but on the document itself, not the browser dom
            imgOrDivWithBackgroundImage.SetAttribute("data-copyright",
                             String.IsNullOrEmpty(imageInfo.Metadata.CopyrightNotice) ? "" : imageInfo.Metadata.CopyrightNotice);

            imgOrDivWithBackgroundImage.SetAttribute("data-creator", String.IsNullOrEmpty(imageInfo.Metadata.Creator) ? "" : imageInfo.Metadata.Creator);

            imgOrDivWithBackgroundImage.SetAttribute("data-license", imageInfo.Metadata.License == null ? "" : imageInfo.Metadata.License.ToString());
        }
Esempio n. 3
0
        public void Execute_OffsetElement_PerformDragCoordinateToElement()
        {
            // Arrange
            var webDriver  = Substitute.For <IWebDriver, IHasInputDevices>();
            var webElement = Substitute.For <IWebElement, ILocatable>();
            var element    = new ElementProxy(webElement);
            var command    = Substitute.ForPartsOf <DragCommand>(0, 0, element);

            // Act
            IgnoreExceptions.Run(() => command.Execute(webDriver));

            // Assert
            command.Received().PerformDragCoordinateToElement(webDriver, 0, 0, webElement);
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bookFolderPath"></param>
        /// <param name="imgOrDivWithBackgroundImage">Can be an XmlElement (during testing)</param>
        /// <param name="imageInfo"></param>
        /// <param name="progress"></param>
        public void ChangePicture(string bookFolderPath, ElementProxy imgOrDivWithBackgroundImage, PalasoImage imageInfo,
                                  IProgress progress)
        {
            var isSameFile    = IsSameFilePath(bookFolderPath, HtmlDom.GetImageElementUrl(imgOrDivWithBackgroundImage), imageInfo);
            var imageFileName = ImageUtils.ProcessAndSaveImageIntoFolder(imageInfo, bookFolderPath, isSameFile);

            HtmlDom.SetImageElementUrl(imgOrDivWithBackgroundImage,
                                       UrlPathString.CreateFromUnencodedString(imageFileName, true));
            UpdateMetadataAttributesOnImage(imgOrDivWithBackgroundImage, imageInfo);
            // It would seem more natural to use a metadata-saving method on imageInfo,
            // but the imageInfo has the source file's path locked into it, and the API
            // gives us no way to change it, so such a save would go to the wrong file.
            imageInfo.Metadata.Write(Path.Combine(bookFolderPath, imageFileName));
        }
Esempio n. 5
0
        public void Execute_ExistingElement_PerformMoveMouseToElement()
        {
            // Arrange
            var webDriver  = Substitute.For <IWebDriver>();
            var webElement = Substitute.For <IWebElement>();
            var element    = new ElementProxy(webElement);
            var command    = Substitute.ForPartsOf <HoverCommand>(element);

            // Act
            IgnoreExceptions.Run(() => command.Execute(webDriver));

            // Assert
            command.Received().PerformMoveMouseToElement(webDriver, webElement);
        }
Esempio n. 6
0
        public void ProxyCacheCanBeCleared()
        {
            // Creating a proxy of the same element twice via Element.Proxy should return you the exact same proxy, not a new proxy for each call.
            var mass           = new Mass(new Profile(Polygon.Rectangle(1, 1)));
            var dependencyName = "Fake Dependency Name";
            var proxy1         = mass.Proxy(dependencyName);
            var proxy2         = mass.Proxy(dependencyName);

            Assert.Equal(proxy1.Id, proxy2.Id);
            ElementProxy.ClearCache();
            var proxy3 = mass.Proxy(dependencyName);

            Assert.NotEqual(proxy1.Id, proxy3.Id);
        }
Esempio n. 7
0
        public void SelfOrAncestorHasClass_MatchesAncestor()
        {
            var dom = new XmlDocument();

            dom.LoadXml("<div class='blueberry pie'><div id='foo' class='foolish'/></div>");
            var fooDiv       = (XmlElement)dom.SelectSingleNode("//div[@id='foo']");
            var elementProxy = new ElementProxy(fooDiv);

            Assert.That(elementProxy.SelfOrAncestorHasClass("foolish"), Is.True);
            Assert.That(elementProxy.SelfOrAncestorHasClass("blueberry"), Is.True);
            Assert.That(elementProxy.SelfOrAncestorHasClass("berry"), Is.False);
            Assert.That(elementProxy.SelfOrAncestorHasClass("pie"), Is.True);
            Assert.That(elementProxy.SelfOrAncestorHasClass("pieplate"), Is.False);
        }
Esempio n. 8
0
        /// <summary>Returns the UI Automation provider for the specified cell.</summary>
        /// <param name="row">The ordinal number of the row of interest.</param>
        /// <param name="column">The ordinal number of the column of interest.</param>
        /// <returns>The UI Automation provider for the specified cell.</returns>
        // Token: 0x060026B4 RID: 9908 RVA: 0x000B7CA0 File Offset: 0x000B5EA0
        IRawElementProviderSimple IGridProvider.GetItem(int row, int column)
        {
            if (row < 0 || row >= ((IGridProvider)this).RowCount)
            {
                throw new ArgumentOutOfRangeException("row");
            }
            if (column < 0 || column >= ((IGridProvider)this).ColumnCount)
            {
                throw new ArgumentOutOfRangeException("column");
            }
            ListViewItem listViewItem = this._listview.ItemContainerGenerator.ContainerFromIndex(row) as ListViewItem;

            if (listViewItem == null)
            {
                VirtualizingPanel virtualizingPanel = this._listview.ItemsHost as VirtualizingPanel;
                if (virtualizingPanel != null)
                {
                    virtualizingPanel.BringIndexIntoView(row);
                }
                listViewItem = (this._listview.ItemContainerGenerator.ContainerFromIndex(row) as ListViewItem);
                if (listViewItem != null)
                {
                    this._listview.Dispatcher.Invoke(DispatcherPriority.Loaded, new DispatcherOperationCallback((object arg) => null), null);
                }
            }
            if (listViewItem != null)
            {
                AutomationPeer automationPeer = UIElementAutomationPeer.FromElement(this._listview);
                if (automationPeer != null)
                {
                    AutomationPeer automationPeer2 = UIElementAutomationPeer.FromElement(listViewItem);
                    if (automationPeer2 != null)
                    {
                        AutomationPeer eventsSource = automationPeer2.EventsSource;
                        if (eventsSource != null)
                        {
                            automationPeer2 = eventsSource;
                        }
                        List <AutomationPeer> children = automationPeer2.GetChildren();
                        if (children.Count > column)
                        {
                            return(ElementProxy.StaticWrap(children[column], automationPeer));
                        }
                    }
                }
            }
            return(null);
        }
        public void ChangeVideo(string bookFolderPath, ElementProxy videoContainer, string videoPath,
                                IProgress progress)
        {
            var videoFileName = Path.GetFileName(videoPath);
            var destPath      = Path.Combine(bookFolderPath, videoFileName);

            if (destPath != videoPath && !File.Exists(destPath))
            {
                RobustFile.Copy(videoPath, destPath);
            }
            // Enhance: if destination exists and content does not match pick a new name and copy to that.

            HtmlDom.SetVideoElementUrl(videoContainer, UrlPathString.CreateFromUnencodedString(videoFileName));
            // Enhance: do we need to do something here about metadata, when we figure out how to handle that
            // for videos?
        }
Esempio n. 10
0
        public void Execute_TwoElements_PerformDragElementToElement()
        {
            // Arrange
            var webDriver   = Substitute.For <IWebDriver, IHasInputDevices>();
            var webElementA = Substitute.For <IWebElement, ILocatable>();
            var webElementB = Substitute.For <IWebElement, ILocatable>();
            var elementA    = new ElementProxy(webElementA);
            var elementB    = new ElementProxy(webElementB);
            var command     = Substitute.ForPartsOf <DragCommand>(elementA, elementB);

            // Act
            IgnoreExceptions.Run(() => command.Execute(webDriver));

            // Assert
            command.Received().PerformDragElementToElement(webDriver, webElementA, webElementB);
        }
Esempio n. 11
0
        void AttachedDG_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            log.DebugFormat("Executing {0} on element {1}.", e.EditAction, e.EditingElement);
            var cell = UIUtils.GetAncestor <DataGridCell>(e.EditingElement);
            var row  = UIUtils.GetAncestor <DataGridRow>(cell);

            log.DebugFormat("Element container is {0}", row.GetHashCode());
            var adornerLayer = AdornerLayer.GetAdornerLayer(row);

            Adorner[] adorners = adornerLayer.GetAdorners(cell);

            if (adorners != null)
            {
                foreach (var adorner in adorners)
                {
                    adornerLayer.Remove(adorner);
                }
            }

            this.DGProxy.EnableCommands(SelectorProxy.NavigationCommands);

            ElementProxy          proxy    = ProxyFactory.GetProxy(e.EditingElement);
            DependencyProperty    property = proxy.GetValueProperty();
            BindingExpressionBase beb      = BindingOperations.GetBindingExpressionBase(e.EditingElement, property);

            if (beb != null)
            {
                BindingExpression be = beb as BindingExpression;
                if (be != null)
                {
                    var result = ValidateBinding(be, e.EditingElement, property);
                    if (result.ShouldShowIndication)
                    {
                        if (AdornerFactory != null)
                        {
                            adornerLayer.Add(AdornerFactory.CreateAdorner(result, cell));
                        }
                    }
                    if (result.ShouldBlock)
                    {
                        this.DGProxy.DisableCommands(SelectorProxy.NavigationCommands);
                        e.Cancel = true;
                    }
                }
            }
        }
Esempio n. 12
0
        private ElementTemplate AddElement(ElementProxy el)
        {
            var position = new Point();

            el.Position = position;

            var et = new ElementTemplate(el);

            et.MouseDown += Rectangle_MouseDown;
            et.MouseMove += Rectangle_MouseMove;
            et.MouseUp   += Rectangle_MouseUp;
            SchemeCanvas.Children.Add(et);

            et.WantsToBeDeleted += DeleteElement;
            et.AddOperation     += AddNewOperation;
            return(et);
        }
Esempio n. 13
0
        public void Properties_AccessedOnElement_RetreivedFromWebElement()
        {
            // Arrange
            IWebElement webElement = Substitute.For <IWebElement>();
            IElement    element    = new ElementProxy(webElement);

            // Act
            bool   displayed = element.Displayed;
            bool   enabled   = element.Enabled;
            bool   selected  = element.Selected;
            string tagName   = element.TagName;
            string text      = element.Text;

            // Assert
            displayed = webElement.Received().Displayed;
            enabled   = webElement.Received().Enabled;
            selected  = webElement.Received().Selected;
            tagName   = webElement.Received().TagName;
            text      = webElement.Received().Text;
        }
Esempio n. 14
0
 /// <summary>Returns a collection of UI Automation providers that represents all the column headers in a table.</summary>
 /// <returns>A collection of UI Automation providers.</returns>
 // Token: 0x060026B0 RID: 9904 RVA: 0x000B7B94 File Offset: 0x000B5D94
 IRawElementProviderSimple[] ITableProvider.GetColumnHeaders()
 {
     if (this._owner.HeaderRowPresenter != null)
     {
         List <IRawElementProviderSimple> list = new List <IRawElementProviderSimple>(this._owner.HeaderRowPresenter.ActualColumnHeaders.Count);
         ListViewAutomationPeer           listViewAutomationPeer = UIElementAutomationPeer.FromElement(this._listview) as ListViewAutomationPeer;
         if (listViewAutomationPeer != null)
         {
             foreach (UIElement element in this._owner.HeaderRowPresenter.ActualColumnHeaders)
             {
                 AutomationPeer automationPeer = UIElementAutomationPeer.CreatePeerForElement(element);
                 if (automationPeer != null)
                 {
                     list.Add(ElementProxy.StaticWrap(automationPeer, listViewAutomationPeer));
                 }
             }
         }
         return(list.ToArray());
     }
     return(new IRawElementProviderSimple[0]);
 }
Esempio n. 15
0
        private void Label_MouseDown(object sender, EventArgs e)
        {
            if (!(sender is MenuItem))
            {
                return;
            }

            var          app = (App)Application.Current;
            ElementProxy ep  = new ElementProxy(new Summator("Error"));

            switch ((sender as MenuItem).Header.ToString())
            {
            case "Сумматор":
                ep = new ElementProxy(new Summator("Сумматор ∑"));
                break;

            case "Инвертор":
                ep = new ElementProxy(new Inverter("Инвертор ⌐"));
                break;

            case "Конъюнктор":
                ep = new ElementProxy(new Сonjunctor("Конъюнктор &"));
                break;

            case "Дизъюнктор":
                ep = new ElementProxy(new Disjunctor("Дизъюнктор |"));
                break;

            case "Регистр":
                ep = new ElementProxy(new Register());
                break;
            }

            app.Machine.AddElement(ep);
            var et       = AddElement(ep);
            var position = new Point(50, 50);

            ep.Position = position;
        }
        // Token: 0x060025F7 RID: 9719 RVA: 0x000B5DDC File Offset: 0x000B3FDC
        private DataGridCellItemAutomationPeer GetPeerFromWeakRefStorage(object column)
        {
            DataGridCellItemAutomationPeer dataGridCellItemAutomationPeer = null;
            WeakReference weakReference = this.WeakRefElementProxyStorage[column];

            if (weakReference != null)
            {
                ElementProxy elementProxy = weakReference.Target as ElementProxy;
                if (elementProxy != null)
                {
                    dataGridCellItemAutomationPeer = (base.PeerFromProvider(elementProxy) as DataGridCellItemAutomationPeer);
                    if (dataGridCellItemAutomationPeer == null)
                    {
                        this.WeakRefElementProxyStorage.Remove(column);
                    }
                }
                else
                {
                    this.WeakRefElementProxyStorage.Remove(column);
                }
            }
            return(dataGridCellItemAutomationPeer);
        }
Esempio n. 17
0
        /// <summary>
        /// Collection of column headers
        /// </summary>
        IRawElementProviderSimple[] ITableProvider.GetColumnHeaders()
        {
            if (_owner.HeaderRowPresenter != null)
            {
                List <IRawElementProviderSimple> array  = new List <IRawElementProviderSimple>(_owner.HeaderRowPresenter.ActualColumnHeaders.Count);
                ListViewAutomationPeer           lvpeer = UIElementAutomationPeer.FromElement(_listview) as ListViewAutomationPeer;

                if (lvpeer != null)
                {
                    foreach (UIElement e in _owner.HeaderRowPresenter.ActualColumnHeaders)
                    {
                        AutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(e);
                        if (peer != null)
                        {
                            array.Add(ElementProxy.StaticWrap(peer, lvpeer));
                        }
                    }
                }
                return(array.ToArray());
            }

            return(new IRawElementProviderSimple[0]);
        }
Esempio n. 18
0
        // Token: 0x06002740 RID: 10048 RVA: 0x000B9990 File Offset: 0x000B7B90
        internal ItemAutomationPeer GetPeerFromWeakRefStorage(object item)
        {
            ItemAutomationPeer itemAutomationPeer = null;
            WeakReference      weakReference      = this.WeakRefElementProxyStorage[item];

            if (weakReference != null)
            {
                ElementProxy elementProxy = weakReference.Target as ElementProxy;
                if (elementProxy != null)
                {
                    itemAutomationPeer = (base.PeerFromProvider(elementProxy) as ItemAutomationPeer);
                    if (itemAutomationPeer == null)
                    {
                        this.WeakRefElementProxyStorage.Remove(item);
                    }
                }
                else
                {
                    this.WeakRefElementProxyStorage.Remove(item);
                }
            }
            return(itemAutomationPeer);
        }
Esempio n. 19
0
        // Provides Peer if exist in Weak Reference Storage
        private DataGridCellItemAutomationPeer GetPeerFromWeakRefStorage(object column)
        {
            DataGridCellItemAutomationPeer returnPeer = null;
            WeakReference weakRefEP = WeakRefElementProxyStorage[column];

            if (weakRefEP != null)
            {
                ElementProxy provider = weakRefEP.Target as ElementProxy;
                if (provider != null)
                {
                    returnPeer = PeerFromProvider(provider as IRawElementProviderSimple) as DataGridCellItemAutomationPeer;
                    if (returnPeer == null)
                    {
                        WeakRefElementProxyStorage.Remove(column);
                    }
                }
                else
                {
                    WeakRefElementProxyStorage.Remove(column);
                }
            }

            return(returnPeer);
        }
Esempio n. 20
0
        // Provides Peer if exist in Weak Reference Storage
        internal ItemAutomationPeer GetPeerFromWeakRefStorage(object item)
        {
            ItemAutomationPeer returnPeer = null;
            WeakReference      weakRefEP  = WeakRefElementProxyStorage[item];

            if (weakRefEP != null)
            {
                ElementProxy provider = weakRefEP.Target as ElementProxy;
                if (provider != null)
                {
                    returnPeer = PeerFromProvider(provider as IRawElementProviderSimple) as ItemAutomationPeer;
                    if (returnPeer == null)
                    {
                        WeakRefElementProxyStorage.Remove(item);
                    }
                }
                else
                {
                    WeakRefElementProxyStorage.Remove(item);
                }
            }

            return(returnPeer);
        }
        // Token: 0x0600252E RID: 9518 RVA: 0x000B346C File Offset: 0x000B166C
        private DateTimeAutomationPeer GetPeerFromWeakRefStorage(DateTimeCalendarModePair dateTimeCalendarModePairKey)
        {
            DateTimeAutomationPeer dateTimeAutomationPeer = null;
            WeakReference          weakReference          = null;

            this.WeakRefElementProxyStorage.TryGetValue(dateTimeCalendarModePairKey, out weakReference);
            if (weakReference != null)
            {
                ElementProxy elementProxy = weakReference.Target as ElementProxy;
                if (elementProxy != null)
                {
                    dateTimeAutomationPeer = (base.PeerFromProvider(elementProxy) as DateTimeAutomationPeer);
                    if (dateTimeAutomationPeer == null)
                    {
                        this.WeakRefElementProxyStorage.Remove(dateTimeCalendarModePairKey);
                    }
                }
                else
                {
                    this.WeakRefElementProxyStorage.Remove(dateTimeCalendarModePairKey);
                }
            }
            return(dateTimeAutomationPeer);
        }
Esempio n. 22
0
 // May be overridden to save some information about the tool state during page save.
 // Default does nothing.
 internal virtual void SaveSettings(ElementProxy toolbox)
 {
 }
Esempio n. 23
0
 // Just forwards to xLayoutRow.  This will layout elements from the start index to the end index.  RowBounds
 // was computed by a call to measure row and is used for alignment/boxstretch.  See the ElementProxy class
 // for an explaination of the elementProxy parameter.
 private void LayoutRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, int endIndex, Rectangle rowBounds) {
     int dummy;
     Size outSize = xLayoutRow(containerProxy, elementProxy, startIndex, endIndex, rowBounds, /* breakIndex = */ out dummy, /* measureOnly = */ false);
     Debug.Assert(dummy == endIndex, "EndIndex / BreakIndex mismatch.");
 }
Esempio n. 24
0
 private Size MeasureRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, Rectangle displayRectangle, out int breakIndex)
 {
     return(this.xLayoutRow(containerProxy, elementProxy, startIndex, containerProxy.Container.Children.Count, displayRectangle, out breakIndex, true));
 }
Esempio n. 25
0
 // May be overridden to save some information about the tool state during page save.
 // Default does nothing.
 internal virtual void SaveSettings(ElementProxy toolbox)
 {
 }
Esempio n. 26
0
        /// <summary>
        /// Given a node in the content section of the book that has a data-book attribute, see
        /// if this node holds an image and if so, look up the url of the image from the supplied
        /// dataset and stick it in there. Handle both img elements and divs that have a
        /// background-image in an inline style attribute.
        ///
        /// At the time of this writing, the only image that is handled here is the cover page.
        /// The URLs of images in the content of the book are not known to the data-div.
        /// But each time the book is loaded up, we collect up data from the xmatter and stick
        /// it in the data-div(in the DOM) / dataSet (in an object here in code), stick in a
        /// blank xmatter, then push the values back into the xmatter.
        /// </summary>
        /// <returns>true if this node is an image holder of some sort.</returns>
        private bool UpdateImageFromDataSet(DataSet data, XmlElement node, string key)
        {
            if (!HtmlDom.IsImgOrSomethingWithBackgroundImage(node))
                return false;

            var newImageUrl = UrlPathString.CreateFromUrlEncodedString(data.TextVariables[key].TextAlternatives.GetFirstAlternative());
            var oldImageUrl = HtmlDom.GetImageElementUrl(node);
            var imgOrDivWithBackgroundImage = new ElementProxy(node);
            HtmlDom.SetImageElementUrl(imgOrDivWithBackgroundImage,newImageUrl);

            if (!newImageUrl.Equals(oldImageUrl))
            {
                Guard.AgainstNull(_updateImgNode, "_updateImgNode");

                try
                {
                    _updateImgNode(node);
                }
                catch (TagLib.CorruptFileException e)
                {
                    NonFatalProblem.Report(ModalIf.Beta, PassiveIf.All, "Problem reading image metadata", newImageUrl.NotEncoded, e);
                    return false;
                }
            }
            return true;
        }
 private void LayoutRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, int endIndex, Rectangle rowBounds)
 {
     int num;
     this.xLayoutRow(containerProxy, elementProxy, startIndex, endIndex, rowBounds, out num, false);
 }
Esempio n. 28
0
 /// <summary>
 /// Gets the url for the image, either from an img element or any other element that has
 /// an inline style with background-image set.
 /// </summary>
 public static UrlPathString GetImageElementUrl(ElementProxy imgOrDivWithBackgroundImage)
 {
     if(imgOrDivWithBackgroundImage.Name.ToLower() == "img")
     {
         var src = imgOrDivWithBackgroundImage.GetAttribute("src");
         return UrlPathString.CreateFromUrlEncodedString(src);
     }
     else
     {
         var styleRule = imgOrDivWithBackgroundImage.GetAttribute("style") ?? "";
         var regex = new Regex("background-image\\s*:\\s*url\\((.*)\\)", RegexOptions.IgnoreCase);
         var match = regex.Match(styleRule);
         if(match.Groups.Count == 2)
         {
             return UrlPathString.CreateFromUrlEncodedString(match.Groups[1].Value.Trim(new[] {'\'', '"'}));
         }
     }
     //we choose to return this instead of null to reduce errors created by things like
     // HtmlDom.GetImageElementUrl(element).UrlEncoded. If we just returned null, that has to be written
     // as something that checks for null, like:
     //  var url = HtmlDom.GetImageElementUrl(element). if(url!=null) url.UrlEncoded
     return UrlPathString.CreateFromUnencodedString(string.Empty);
 }
Esempio n. 29
0
 // Just forwards to xLayoutRow.  breakIndex is the index of the first control not to fit in the displayRectangle.  The
 // returned Size is the size required to layout the controls from startIndex up to but not including breakIndex.  See
 // the ElementProxy class for an explaination of the elementProxy parameter.
 private Size MeasureRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, Rectangle displayRectangle, out int breakIndex)
 {
     return(xLayoutRow(containerProxy, elementProxy, startIndex, /* endIndex = */ containerProxy.Container.Children.Count, displayRectangle, out breakIndex, /* measureOnly = */ true));
 }
Esempio n. 30
0
 // Just forwards to xLayoutRow.  breakIndex is the index of the first control not to fit in the displayRectangle.  The
 // returned Size is the size required to layout the controls from startIndex up to but not including breakIndex.  See
 // the ElementProxy class for an explaination of the elementProxy parameter.
 private Size MeasureRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, Rectangle displayRectangle, out int breakIndex) {
     return xLayoutRow(containerProxy, elementProxy, startIndex, /* endIndex = */ containerProxy.Container.Children.Count, displayRectangle, out breakIndex, /* measureOnly = */ true);
 }
Esempio n. 31
0
 /// <summary>
 ///  Just forwards to TryCalculatePreferredSizeRow. breakIndex is the index of the first control not to
 ///  fit in the displayRectangle. The returned Size is the size required to layout the
 ///  controls from startIndex up to but not including breakIndex. See the ElementProxy
 ///  class for an explaination of the elementProxy parameter.
 /// </summary>
 private Size MeasureRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, Rectangle displayRectangle, out int breakIndex)
 {
     return(TryCalculatePreferredSizeRow(containerProxy, elementProxy, startIndex, endIndex: containerProxy.Container.Children.Count, rowBounds: displayRectangle, breakIndex: out breakIndex, measureOnly: true));
 }
Esempio n. 32
0
        /// <summary>
        ///  Just forwards to TryCalculatePreferredSizeRow. This will layout elements from the start index to the end
        ///  index. RowBounds was computed by a call to measure row and is used for alignment/boxstretch.
        ///  See the ElementProxy class for an explaination of the elementProxy parameter.
        /// </summary>
        private void LayoutRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, int endIndex, Rectangle rowBounds)
        {
            Size outSize = TryCalculatePreferredSizeRow(containerProxy, elementProxy, startIndex, endIndex, rowBounds, /* breakIndex = */ out int dummy, /* measureOnly = */ false);

            Debug.Assert(dummy == endIndex, "EndIndex / BreakIndex mismatch.");
        }
Esempio n. 33
0
        // To purge the collection corresponding to WeakReference for dead references
        //
        public void PurgeWeakRefCollection()
        {
            if (!(typeof(T).IsAssignableFrom(typeof(System.WeakReference))))
            {
                return;
            }
            List <object> cleanUpItemsCollection = new List <object>();

            if (_usesHashCode)
            {
                if (_hashtable == null)
                {
                    return;
                }
                foreach (DictionaryEntry dictionaryEntry in _hashtable)
                {
                    WeakReference weakRef = dictionaryEntry.Value as WeakReference;
                    if (weakRef == null)
                    {
                        cleanUpItemsCollection.Add(dictionaryEntry.Key);
                        continue;
                    }
                    ElementProxy proxy = weakRef.Target as ElementProxy;
                    if (proxy == null)
                    {
                        cleanUpItemsCollection.Add(dictionaryEntry.Key);
                        continue;
                    }
                    ItemAutomationPeer peer = proxy.Peer as ItemAutomationPeer;
                    if (peer == null)
                    {
                        cleanUpItemsCollection.Add(dictionaryEntry.Key);
                    }
                }
            }

            else
            {
                if (_list == null)
                {
                    return;
                }
                foreach (KeyValuePair <object, T> keyValuePair in _list)
                {
                    WeakReference weakRef = keyValuePair.Value as WeakReference;
                    if (weakRef == null)
                    {
                        cleanUpItemsCollection.Add(keyValuePair.Key);
                        continue;
                    }
                    ElementProxy proxy = weakRef.Target as ElementProxy;
                    if (proxy == null)
                    {
                        cleanUpItemsCollection.Add(keyValuePair.Key);
                        continue;
                    }
                    ItemAutomationPeer peer = proxy.Peer as ItemAutomationPeer;
                    if (peer == null)
                    {
                        cleanUpItemsCollection.Add(keyValuePair.Key);
                    }
                }
            }

            foreach (object item in cleanUpItemsCollection)
            {
                Remove(item);
            }
        }
Esempio n. 34
0
        // LayoutRow and MeasureRow both forward to this method.  The measureOnly flag determines which behavior we get.
        private Size xLayoutRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, int endIndex, Rectangle rowBounds, out int breakIndex, bool measureOnly) {
            Debug.Assert(startIndex < endIndex, "Loop should be in forward Z-order.");
            Point location = rowBounds.Location;
            Size rowSize = Size.Empty;
            int laidOutItems = 0;
            breakIndex = startIndex;

            bool wrapContents = GetWrapContents(containerProxy.Container);
            bool breakOnNextItem = false;

            
            ArrangedElementCollection collection = containerProxy.Container.Children;
            for(int i = startIndex; i < endIndex; i++, breakIndex++) {
                elementProxy.Element = collection[i];

                if(!elementProxy.ParticipatesInLayout) {
                    continue;
                }

                // Figure out how much space this element is going to need (requiredSize)
                //
                Size prefSize;
                if(elementProxy.AutoSize) {
                    Size elementConstraints = new Size(Int32.MaxValue, rowBounds.Height - elementProxy.Margin.Size.Height);
                    if(i == startIndex) {
                        // If the element is the first in the row, attempt to pack it to the row width.  (If its not 1st, it will wrap
                        // to the first on the next row if its too long and then be packed if needed by the next call to xLayoutRow).
                        elementConstraints.Width = rowBounds.Width - rowSize.Width - elementProxy.Margin.Size.Width;
                    }

                    // Make sure that subtracting the margins does not cause width/height to be <= 0, or we will
                    // size as if we had infinite space when in fact we are trying to be as small as possible.
                    elementConstraints = LayoutUtils.UnionSizes(new Size(1, 1), elementConstraints);                    
                    prefSize = elementProxy.GetPreferredSize(elementConstraints);
                } else {
                    // If autosizing is turned off, we just use the element's current size as its preferred size.
                    prefSize = elementProxy.SpecifiedSize;

                    // VSWhidbey 406227
                    // except if it is stretching - then ignore the affect of the height dimension.
                    if (elementProxy.Stretches) {
                        prefSize.Height = 0;
                    } 

                    // Enforce MinimumSize
                    if (prefSize.Height < elementProxy.MinimumSize.Height) {
                        prefSize.Height = elementProxy.MinimumSize.Height;
                    }
                }
                Size requiredSize = prefSize + elementProxy.Margin.Size;

                // Position the element (if applicable).
                //
                if(!measureOnly) {
                    // If measureOnly = false, rowBounds.Height = measured row hieght
                    // (otherwise its the remaining displayRect of the container)
                    
                    Rectangle cellBounds = new Rectangle(location, new Size(requiredSize.Width, rowBounds.Height));

                    // We laid out the rows with the elementProxy's margins included.
                    // We now deflate the rect to get the actual elementProxy bounds.
                    cellBounds = LayoutUtils.DeflateRect(cellBounds, elementProxy.Margin);
                    
                    AnchorStyles anchorStyles = elementProxy.AnchorStyles;
                    containerProxy.Bounds = LayoutUtils.AlignAndStretch(prefSize, cellBounds, anchorStyles);
                }
        
                // Keep track of how much space is being used in this row
                //
              
                location.X += requiredSize.Width;
                

               
                if (laidOutItems > 0) {
                    // If control does not fit on this row, exclude it from row and stop now.
                    //   Exception: If row is empty, allow this control to fit on it. So controls
                    //   that exceed the maximum row width will end up occupying their own rows.
                    if(location.X > rowBounds.Right) {
                        break;
                    }

                }
                // Control fits on this row, so update the row size.
                //   rowSize.Width != location.X because with a scrollable control
                //   we could have started with a location like -100.
                
                rowSize.Width = location.X - rowBounds.X;
                
                rowSize.Height = Math.Max(rowSize.Height, requiredSize.Height);

                // check for line breaks.
                if (wrapContents) {
                    if (breakOnNextItem) {
                        break;
                    }
                    else if (i+1 < endIndex && CommonProperties.GetFlowBreak(elementProxy.Element)) {
                        if (laidOutItems == 0) {
                            breakOnNextItem = true;
                        }
                        else {
                            breakIndex++;
                            break;
                        }
                   }
                }
                ++laidOutItems;
            }

            return rowSize;
        }
 private Size MeasureRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, Rectangle displayRectangle, out int breakIndex)
 {
     return this.xLayoutRow(containerProxy, elementProxy, startIndex, containerProxy.Container.Children.Count, displayRectangle, out breakIndex, true);
 }
        // Token: 0x0600274F RID: 10063 RVA: 0x000B9CDC File Offset: 0x000B7EDC
        public void PurgeWeakRefCollection()
        {
            if (!typeof(T).IsAssignableFrom(typeof(WeakReference)))
            {
                return;
            }
            List <object> list = new List <object>();

            if (this._usesHashCode)
            {
                if (this._hashtable == null)
                {
                    return;
                }
                using (IEnumerator <KeyValuePair <object, T> > enumerator = this._hashtable.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        KeyValuePair <object, T> keyValuePair  = enumerator.Current;
                        WeakReference            weakReference = keyValuePair.Value as WeakReference;
                        if (weakReference == null)
                        {
                            list.Add(keyValuePair.Key);
                        }
                        else
                        {
                            ElementProxy elementProxy = weakReference.Target as ElementProxy;
                            if (elementProxy == null)
                            {
                                list.Add(keyValuePair.Key);
                            }
                            else if (!(elementProxy.Peer is ItemAutomationPeer))
                            {
                                list.Add(keyValuePair.Key);
                            }
                        }
                    }
                    goto IL_165;
                }
            }
            if (this._list == null)
            {
                return;
            }
            foreach (KeyValuePair <object, T> keyValuePair2 in this._list)
            {
                WeakReference weakReference2 = keyValuePair2.Value as WeakReference;
                if (weakReference2 == null)
                {
                    list.Add(keyValuePair2.Key);
                }
                else
                {
                    ElementProxy elementProxy2 = weakReference2.Target as ElementProxy;
                    if (elementProxy2 == null)
                    {
                        list.Add(keyValuePair2.Key);
                    }
                    else if (!(elementProxy2.Peer is ItemAutomationPeer))
                    {
                        list.Add(keyValuePair2.Key);
                    }
                }
            }
IL_165:
            foreach (object item in list)
            {
                this.Remove(item);
            }
        }
Esempio n. 37
0
        // LayoutRow and MeasureRow both forward to this method.  The measureOnly flag determines which behavior we get.
        private Size xLayoutRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, int endIndex, Rectangle rowBounds, out int breakIndex, bool measureOnly)
        {
            Debug.Assert(startIndex < endIndex, "Loop should be in forward Z-order.");
            Point location     = rowBounds.Location;
            Size  rowSize      = Size.Empty;
            int   laidOutItems = 0;

            breakIndex = startIndex;

            bool wrapContents    = GetWrapContents(containerProxy.Container);
            bool breakOnNextItem = false;


            ArrangedElementCollection collection = containerProxy.Container.Children;

            for (int i = startIndex; i < endIndex; i++, breakIndex++)
            {
                elementProxy.Element = collection[i];

                if (!elementProxy.ParticipatesInLayout)
                {
                    continue;
                }

                // Figure out how much space this element is going to need (requiredSize)
                //
                Size prefSize;
                if (elementProxy.AutoSize)
                {
                    Size elementConstraints = new Size(Int32.MaxValue, rowBounds.Height - elementProxy.Margin.Size.Height);
                    if (i == startIndex)
                    {
                        // If the element is the first in the row, attempt to pack it to the row width.  (If its not 1st, it will wrap
                        // to the first on the next row if its too long and then be packed if needed by the next call to xLayoutRow).
                        elementConstraints.Width = rowBounds.Width - rowSize.Width - elementProxy.Margin.Size.Width;
                    }

                    // Make sure that subtracting the margins does not cause width/height to be <= 0, or we will
                    // size as if we had infinite space when in fact we are trying to be as small as possible.
                    elementConstraints = LayoutUtils.UnionSizes(new Size(1, 1), elementConstraints);
                    prefSize           = elementProxy.GetPreferredSize(elementConstraints);
                }
                else
                {
                    // If autosizing is turned off, we just use the element's current size as its preferred size.
                    prefSize = elementProxy.SpecifiedSize;

                    // except if it is stretching - then ignore the affect of the height dimension.
                    if (elementProxy.Stretches)
                    {
                        prefSize.Height = 0;
                    }

                    // Enforce MinimumSize
                    if (prefSize.Height < elementProxy.MinimumSize.Height)
                    {
                        prefSize.Height = elementProxy.MinimumSize.Height;
                    }
                }
                Size requiredSize = prefSize + elementProxy.Margin.Size;

                // Position the element (if applicable).
                //
                if (!measureOnly)
                {
                    // If measureOnly = false, rowBounds.Height = measured row hieght
                    // (otherwise its the remaining displayRect of the container)

                    Rectangle cellBounds = new Rectangle(location, new Size(requiredSize.Width, rowBounds.Height));

                    // We laid out the rows with the elementProxy's margins included.
                    // We now deflate the rect to get the actual elementProxy bounds.
                    cellBounds = LayoutUtils.DeflateRect(cellBounds, elementProxy.Margin);

                    AnchorStyles anchorStyles = elementProxy.AnchorStyles;
                    containerProxy.Bounds = LayoutUtils.AlignAndStretch(prefSize, cellBounds, anchorStyles);
                }

                // Keep track of how much space is being used in this row
                //

                location.X += requiredSize.Width;



                if (laidOutItems > 0)
                {
                    // If control does not fit on this row, exclude it from row and stop now.
                    //   Exception: If row is empty, allow this control to fit on it. So controls
                    //   that exceed the maximum row width will end up occupying their own rows.
                    if (location.X > rowBounds.Right)
                    {
                        break;
                    }
                }
                // Control fits on this row, so update the row size.
                //   rowSize.Width != location.X because with a scrollable control
                //   we could have started with a location like -100.

                rowSize.Width = location.X - rowBounds.X;

                rowSize.Height = Math.Max(rowSize.Height, requiredSize.Height);

                // check for line breaks.
                if (wrapContents)
                {
                    if (breakOnNextItem)
                    {
                        break;
                    }
                    else if (i + 1 < endIndex && CommonProperties.GetFlowBreak(elementProxy.Element))
                    {
                        if (laidOutItems == 0)
                        {
                            breakOnNextItem = true;
                        }
                        else
                        {
                            breakIndex++;
                            break;
                        }
                    }
                }
                ++laidOutItems;
            }

            return(rowSize);
        }
Esempio n. 38
0
 /// <summary>
 /// Sets the url attribute either of an img (the src attribute)
 /// or a div with an inline style with an background-image rule
 /// </summary>
 public static void SetImageElementUrl(ElementProxy imgOrDivWithBackgroundImage, UrlPathString url)
 {
     if(imgOrDivWithBackgroundImage.Name.ToLower() == "img")
     {
         imgOrDivWithBackgroundImage.SetAttribute("src", url.UrlEncoded);
     }
     else
     {
         imgOrDivWithBackgroundImage.SetAttribute("style", string.Format("background-image:url('{0}')", url.UrlEncoded));
     }
 }
Esempio n. 39
0
 internal override void SaveSettings(ElementProxy toolbox)
 {
     base.SaveSettings(toolbox);
     if (toolbox == null)
         return;
 }
 private Size xLayoutRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, int endIndex, Rectangle rowBounds, out int breakIndex, bool measureOnly)
 {
     Point location = rowBounds.Location;
     Size empty = Size.Empty;
     int num = 0;
     breakIndex = startIndex;
     bool wrapContents = GetWrapContents(containerProxy.Container);
     bool flag2 = false;
     ArrangedElementCollection children = containerProxy.Container.Children;
     int num2 = startIndex;
     while (num2 < endIndex)
     {
         elementProxy.Element = children[num2];
         if (elementProxy.ParticipatesInLayout)
         {
             Size preferredSize;
             if (elementProxy.AutoSize)
             {
                 Size b = new Size(0x7fffffff, rowBounds.Height - elementProxy.Margin.Size.Height);
                 if (num2 == startIndex)
                 {
                     b.Width = (rowBounds.Width - empty.Width) - elementProxy.Margin.Size.Width;
                 }
                 b = LayoutUtils.UnionSizes(new Size(1, 1), b);
                 preferredSize = elementProxy.GetPreferredSize(b);
             }
             else
             {
                 preferredSize = elementProxy.SpecifiedSize;
                 if (elementProxy.Stretches)
                 {
                     preferredSize.Height = 0;
                 }
                 if (preferredSize.Height < elementProxy.MinimumSize.Height)
                 {
                     preferredSize.Height = elementProxy.MinimumSize.Height;
                 }
             }
             Size size4 = preferredSize + elementProxy.Margin.Size;
             if (!measureOnly)
             {
                 Rectangle rect = new Rectangle(location, new Size(size4.Width, rowBounds.Height));
                 rect = LayoutUtils.DeflateRect(rect, elementProxy.Margin);
                 AnchorStyles anchorStyles = elementProxy.AnchorStyles;
                 containerProxy.Bounds = LayoutUtils.AlignAndStretch(preferredSize, rect, anchorStyles);
             }
             location.X += size4.Width;
             if ((num > 0) && (location.X > rowBounds.Right))
             {
                 return empty;
             }
             empty.Width = location.X - rowBounds.X;
             empty.Height = Math.Max(empty.Height, size4.Height);
             if (wrapContents)
             {
                 if (flag2)
                 {
                     return empty;
                 }
                 if (((num2 + 1) < endIndex) && CommonProperties.GetFlowBreak(elementProxy.Element))
                 {
                     if (num == 0)
                     {
                         flag2 = true;
                     }
                     else
                     {
                         breakIndex++;
                         return empty;
                     }
                 }
             }
             num++;
         }
         num2++;
         breakIndex++;
     }
     return empty;
 }
Esempio n. 41
0
        private Size xLayoutRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, int endIndex, Rectangle rowBounds, out int breakIndex, bool measureOnly)
        {
            Point location = rowBounds.Location;
            Size  empty    = Size.Empty;
            int   num      = 0;

            breakIndex = startIndex;
            bool wrapContents = GetWrapContents(containerProxy.Container);
            bool flag2        = false;
            ArrangedElementCollection children = containerProxy.Container.Children;
            int num2 = startIndex;

            while (num2 < endIndex)
            {
                elementProxy.Element = children[num2];
                if (elementProxy.ParticipatesInLayout)
                {
                    Size preferredSize;
                    if (elementProxy.AutoSize)
                    {
                        Size b = new Size(0x7fffffff, rowBounds.Height - elementProxy.Margin.Size.Height);
                        if (num2 == startIndex)
                        {
                            b.Width = (rowBounds.Width - empty.Width) - elementProxy.Margin.Size.Width;
                        }
                        b             = LayoutUtils.UnionSizes(new Size(1, 1), b);
                        preferredSize = elementProxy.GetPreferredSize(b);
                    }
                    else
                    {
                        preferredSize = elementProxy.SpecifiedSize;
                        if (elementProxy.Stretches)
                        {
                            preferredSize.Height = 0;
                        }
                        if (preferredSize.Height < elementProxy.MinimumSize.Height)
                        {
                            preferredSize.Height = elementProxy.MinimumSize.Height;
                        }
                    }
                    Size size4 = preferredSize + elementProxy.Margin.Size;
                    if (!measureOnly)
                    {
                        Rectangle rect = new Rectangle(location, new Size(size4.Width, rowBounds.Height));
                        rect = LayoutUtils.DeflateRect(rect, elementProxy.Margin);
                        AnchorStyles anchorStyles = elementProxy.AnchorStyles;
                        containerProxy.Bounds = LayoutUtils.AlignAndStretch(preferredSize, rect, anchorStyles);
                    }
                    location.X += size4.Width;
                    if ((num > 0) && (location.X > rowBounds.Right))
                    {
                        return(empty);
                    }
                    empty.Width  = location.X - rowBounds.X;
                    empty.Height = Math.Max(empty.Height, size4.Height);
                    if (wrapContents)
                    {
                        if (flag2)
                        {
                            return(empty);
                        }
                        if (((num2 + 1) < endIndex) && CommonProperties.GetFlowBreak(elementProxy.Element))
                        {
                            if (num == 0)
                            {
                                flag2 = true;
                            }
                            else
                            {
                                breakIndex++;
                                return(empty);
                            }
                        }
                    }
                    num++;
                }
                num2++;
                breakIndex++;
            }
            return(empty);
        }
Esempio n. 42
0
        private void LayoutRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, int endIndex, Rectangle rowBounds)
        {
            int num;

            this.xLayoutRow(containerProxy, elementProxy, startIndex, endIndex, rowBounds, out num, false);
        }
Esempio n. 43
0
        /// <summary>
        /// Obtain the IRawElementProviderSimple at an absolute position
        /// </summary>
        IRawElementProviderSimple IGridProvider.GetItem(int row, int column)
        {
            if (row < 0 || row >= ((IGridProvider)this).RowCount)
            {
                throw new ArgumentOutOfRangeException("row");
            }
            if (column < 0 || column >= ((IGridProvider)this).ColumnCount)
            {
                throw new ArgumentOutOfRangeException("column");
            }

            ListViewItem lvi = _listview.ItemContainerGenerator.ContainerFromIndex(row) as ListViewItem;

            //If item is virtualized, try to de-virtualize it
            if (lvi == null)
            {
                VirtualizingPanel itemsHost = _listview.ItemsHost as VirtualizingPanel;
                if (itemsHost != null)
                {
                    itemsHost.BringIndexIntoView(row);
                }

                lvi = _listview.ItemContainerGenerator.ContainerFromIndex(row) as ListViewItem;

                if (lvi != null)
                {
                    //Must call Invoke here to force run the render process
                    _listview.Dispatcher.Invoke(
                        System.Windows.Threading.DispatcherPriority.Loaded,
                        (System.Windows.Threading.DispatcherOperationCallback) delegate(object arg)
                    {
                        return(null);
                    },
                        null);
                }
            }

            //lvi is null, it is virtualized, so we can't return its cell
            if (lvi != null)
            {
                AutomationPeer lvpeer = UIElementAutomationPeer.FromElement(_listview);
                if (lvpeer != null)
                {
                    AutomationPeer peer = UIElementAutomationPeer.FromElement(lvi);
                    if (peer != null)
                    {
                        // use the GridViewItemAutomationPeer, if available
                        AutomationPeer eventSource = peer.EventsSource;
                        if (eventSource != null)
                        {
                            peer = eventSource;
                        }

                        List <AutomationPeer> columns = peer.GetChildren();
                        if (columns.Count > column)
                        {
                            return(ElementProxy.StaticWrap(columns[column], lvpeer));
                        }
                    }
                }
            }

            return(null);
        }