//called recursively
        protected void FindText(DependencyObject searchIn, bool parentUIElementIsFindable)
        {
            if (searchIn == null)
            {
                return;
            }

            bool?isFindable = searchIn is UIElement?KFindBox.GetIsFindable(searchIn as UIElement) : true;

            IRunReader runReader = null;

            if (searchIn is UIElement && ((parentUIElementIsFindable && isFindable != false) || isFindable == true))//GetIsFindable is bool? - if null then just not set so use parentUIElementIsFindable
            {
                parentUIElementIsFindable = true;
                runReader = FindHandlerRegistry.CreateIRunReaderHandlerFor(searchIn);
            }

            if (runReader != null)
            {
                HighlightHandler handler = highlightHandlers.GetCreateHighlightHandler(searchIn as UIElement, bodyHighlightAdornerBrush, bodyHighlightAdornerPen);
                FindTextIn(runReader, handler.AddHighlight, searchText);
            }


            //recurse through children
            var childCount = VisualTreeHelper.GetChildrenCount(searchIn);

            for (var i = 0; i < childCount; ++i)
            {
                FindText(VisualTreeHelper.GetChild(searchIn, i), parentUIElementIsFindable);
            }
        }
        public void FlowProblem1_AsFlowDocument_WithRegistry()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
            bool         hit     = false;
            FlowDocument content = LoadFlowDocument("FlowDocument1.xaml");

            finder.FindTextIn(FindHandlerRegistry.CreateIRunReaderHandlerFor(content), delegate(Run run, int index, int length)
            {
                hit = true;
            }, new Query("urna jimmy"));

            Assert.IsTrue(hit);
        }
        public void Flow_3()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
            // finder.FindOptions.IgnoreWhitespaceCharacters = true;
            bool         hit     = false;
            FlowDocument content = LoadFlowDocument("FlowDocument3.xaml");

            finder.FindTextIn(FindHandlerRegistry.CreateIRunReaderHandlerFor(content), delegate(Run run, int index, int length)
            {
                hit = true;
            }, new Query("a b c"));

            Assert.IsTrue(hit);
        }
Esempio n. 4
0
        //called recursively, searchIn doesn't have to be a UIElement because we will look at it's children for any child UIElemenets
        /// <summary>
        /// Recursively searches <c>searchIn</c> for the Query.
        /// </summary>
        /// <param name="searchIn">DependencyObject to search inside.</param>
        /// <param name="parentUIElementIsFindable">Whether the parent UI element has been determined as 'findable'.  If the parent is findable then <c>searchIn</c> is finable too unless explicitly marked otherwise with IsFindable="false".</param>
        /// <returns>Whether searchIn or any of it's children where marked as either 'findable' or not (IsFindable="true" or IsFindable="false").</returns>
        protected bool FindText(DependencyObject searchIn, bool parentUIElementIsFindable)
        {
            bool foundIsFindableAttribute = false;//whether this element searchIn or its children were marked with isfindable

            bool searchChildren = parentUIElementIsFindable;

            if (searchIn == null)
            {
                return(foundIsFindableAttribute);
            }
            currentGlobalScanHighlightCount = 0;
            bool?isFindable = searchIn is UIElement?RapidFindReplaceControl.GetIsFindable(searchIn as UIElement) : true;

            if (searchIn is UIElement)
            {
                foundIsFindableAttribute = RapidFindReplaceControl.GetIsFindable(searchIn as UIElement) != null;
            }


            IRunReader runReader = null;

            if (searchIn is UIElement && WillSearchInElement(searchIn as UIElement, parentUIElementIsFindable, ref searchChildren, isFindable))//GetIsFindable is bool? - if null then just not set so use parentUIElementIsFindable
            {
                searchChildren = true;
                runReader      = FindHandlerRegistry.CreateIRunReaderHandlerFor(searchIn);
            }
            else if (!(searchIn is UIElement))
            {
                runReader = FindHandlerRegistry.CreateIRunReaderHandlerFor(searchIn);//we might be able to get a runreader for non UIElement (eg RunCollectionRunReader)
            }
            if (runReader != null)
            {
                HighlightHandler handler = highlightHandlers.GetCreateHighlightHandler(searchIn, bodyHighlightAdornerBrush, bodyHighlightAdornerPen, bodyIterativeHighlightAdornerBrush, bodyIterativeHighlightAdornerPen);
                FindTextIn(runReader, handler.AddHighlight, Query);
            }


            //recurse through children
            if (searchIn is Visual || searchIn is System.Windows.Media.Media3D.Visual3D)
            {
                var childCount = VisualTreeHelper.GetChildrenCount(searchIn);

                for (var i = 0; i < childCount; ++i)
                {
                    foundIsFindableAttribute |= FindText(VisualTreeHelper.GetChild(searchIn, i), searchChildren && isFindable != false);
                }
            }
            return(foundIsFindableAttribute);
        }
        //public event EventHandler NewSearchNeeded;
        public HighlightHandler GetCreateHighlightHandler(DependencyObject element, System.Windows.Media.Brush bodyHighlightAdornerBrush, System.Windows.Media.Pen bodyHighlightAdornerPen, Brush bodyIterativeHighlightAdornerBrush, Pen bodyIterativeHighlightAdornerPen)
        {
            int existingHandlerIndex = GetHighlightHandlerIndex(element);

            if (existingHandlerIndex >= 0)
            {
                return(this[existingHandlerIndex]);
            }

            HighlightHandler newHandler = FindHandlerRegistry.CreateHighlightHandlerFor(element, bodyHighlightAdornerBrush, bodyHighlightAdornerPen, bodyIterativeHighlightAdornerBrush, bodyIterativeHighlightAdornerPen);

            Add(newHandler);
            newHandler.NewSearchNeeded            += newHandler_NewSearchNeeded;
            newHandler.ElementToHighlightGotFocus += newHandler_ElementToHighlightGotFocus;
            return(newHandler);
        }