internal static void Search_Window_Tabs_Text(ref SearchDescriptor searchData) { for (int currentModule = 0; currentModule < searchData.Modules.Count; currentModule++) { searchData.CurrentModuleIndex = currentModule; Root moduleNode = Searching_Window_Tabs_Text(ref searchData); if (moduleNode != null) { TreeNode treeNode = new TreeNode(moduleNode.Title); treeNode.Tag = moduleNode.WindowInfo; List<TreeNode> treeNodes = new List<TreeNode>(moduleNode.Nodes.Count); foreach (Node nodeInTheList in moduleNode.Nodes) { TreeNode leaf = new TreeNode(nodeInTheList.InnerText); leaf.ToolTipText = nodeInTheList.ToolTipText; leaf.Tag = nodeInTheList.Position; treeNodes.Add(leaf); } treeNode.Nodes.AddRange(treeNodes.ToArray()); searchData.ResultNode.Nodes.Add(treeNode); } if (CancelOperationOrReportUI(System.Convert.ToInt32(System.Convert.ToDouble(currentModule) / searchData.Modules.Count * 100))) return; } if (CancelOperationOrReportUI((int)SearchProgress.Done, SearchProgress.Done)) return; }
private static void Search_Window_Tab_HTML(ref SearchDescriptor searchData) { ModuleDescriptor moduleDesc = searchData.Modules[searchData.CurrentModuleIndex]; if (moduleDesc.HTMLDoc != null) { moduleDesc.Form = new HTMLForm(); moduleDesc.Form.Text = moduleDesc.HTMLDoc.title; mshtml.IHTMLElement element = moduleDesc.HTMLDoc.documentElement; moduleDesc.Form.richHtmlText.Text = element.outerHTML; List<int> positions = null; List<Node> nodes = new List<Node>(); Marshal.ReleaseComObject(element); Root root = null; if (CancelOperationOrReportUI((int)SearchProgress.Initializing)) return; int length = moduleDesc.Form.richHtmlText.Lines.Length; if (searchData.CheckCase) { if (searchData.CheckWholeWord) { for (int line = 0; line < length; line++) { if ((positions = VisibleContent.CaseSensitive.WholeWord.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); if (IsCancelled) return; } if (CancelOperationOrReportUI((int)SearchProgress.Searching, System.Convert.ToInt32((Convert.ToDouble(line) / length) * 100))) return; } } if (nodes.Count > Const.Ok) { root = new Root(moduleDesc.HTMLDoc.title, nodes, new WindowInfoTag(moduleDesc, searchData.Term, searchData.Flags)); } } else { for (int line = 0; line < length; line++) { if ((positions = VisibleContent.CaseSensitive.WordAsPart.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); if (IsCancelled) return; } if (CancelOperationOrReportUI((int)SearchProgress.Searching, System.Convert.ToInt32((Convert.ToDouble(line) / length) * 100))) return; } } if (nodes.Count > Const.Ok) { root = new Root(moduleDesc.HTMLDoc.title, nodes, new WindowInfoTag(moduleDesc, searchData.Term, searchData.Flags)); } } } else { if (searchData.CheckWholeWord) { for (int line = 0; line < length; line++) { if ((positions = VisibleContent.CaseInsensetive.WholeWord.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); if (IsCancelled) return; } if (CancelOperationOrReportUI((int)SearchProgress.Searching, System.Convert.ToInt32((Convert.ToDouble(line) / length) * 100))) return; } } if (nodes.Count > Const.Ok) { root = new Root(moduleDesc.HTMLDoc.title, nodes, new WindowInfoTag(moduleDesc, searchData.Term, searchData.Flags)); } } else { for (int line = 0; line < length; line++) { if ((positions = VisibleContent.CaseInsensetive.WordAsPart.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); if (IsCancelled) return; } if (CancelOperationOrReportUI((int)SearchProgress.Searching, System.Convert.ToInt32((Convert.ToDouble(line) / length) * 100))) return; } } if (nodes.Count > Const.Ok) { root = new Root(moduleDesc.HTMLDoc.title, nodes, new WindowInfoTag(moduleDesc, searchData.Term, searchData.Flags)); } } } if (root != null) { TreeNode treeNode = new TreeNode(root.Title); treeNode.Tag = root.WindowInfo; List<TreeNode> treeNodes = new List<TreeNode>(root.Nodes.Count); foreach (Node nodeInTheList in root.Nodes) { TreeNode leaf = new TreeNode(nodeInTheList.InnerText); leaf.ToolTipText = nodeInTheList.ToolTipText; leaf.Tag = nodeInTheList.HtmlTag; treeNodes.Add(leaf); } treeNode.Nodes.AddRange(treeNodes.ToArray()); searchData.ResultNode.Nodes.Add(treeNode); } if (element != null) Marshal.ReleaseComObject(element); element = null; if (CancelOperationOrReportUI((int)SearchProgress.Done, SearchProgress.Done)) return; } }
internal static void Search_Window_Tab_Text(ref SearchDescriptor searchData) { if (searchData.Modules.Count > 0) { searchData.CurrentModuleIndex = 0; mshtml.IHTMLElement element = searchData.Modules[searchData.CurrentModuleIndex].HTMLDoc.body; if (element != null && !String.IsNullOrEmpty(element.innerText)) { List<int> positions = null; string body = element.innerText; Marshal.ReleaseComObject(element); if (CancelOperationOrReportUI((int)SearchProgress.Initializing)) return; if (searchData.CheckCase) { if (searchData.CheckWholeWord) { positions = VisibleContent.CaseSensitive.WholeWord.AdvancedSearchEngine.Contains(body, searchData.Term); searchData.Flags = SearchFlags.ieMatchCase | SearchFlags.ieMatchWholeWordsOnly; } else { positions = VisibleContent.CaseSensitive.WordAsPart.AdvancedSearchEngine.Contains(body, searchData.Term); searchData.Flags = SearchFlags.ieMatchCase | SearchFlags.ieMatchPartialWords; } } else { if (searchData.CheckWholeWord) { positions = VisibleContent.CaseInsensetive.WholeWord.AdvancedSearchEngine.Contains(body, searchData.Term); searchData.Flags = SearchFlags.ieMatchWholeWordsOnly; } else { positions = VisibleContent.CaseInsensetive.WordAsPart.AdvancedSearchEngine.Contains(body, searchData.Term); searchData.Flags = SearchFlags.ieMatchPartialWords; } } if (CancelOperationOrReportUI((int)SearchProgress.Searching)) return; Root moduleNode = CollectTextNodes(positions, ref searchData); if (moduleNode != null) { TreeNode treeNode = new TreeNode(moduleNode.Title); treeNode.Tag = moduleNode.WindowInfo; List<TreeNode> treeNodes = new List<TreeNode>(moduleNode.Nodes.Count); foreach (Node nodeInTheList in moduleNode.Nodes) { TreeNode leaf = new TreeNode(nodeInTheList.InnerText); leaf.ToolTipText = nodeInTheList.ToolTipText; leaf.Tag = nodeInTheList.Position; treeNodes.Add(leaf); } treeNode.Nodes.AddRange(treeNodes.ToArray()); searchData.ResultNode.Nodes.Add(treeNode); } Marshal.ReleaseComObject(element); element = null; if (CancelOperationOrReportUI((int)SearchProgress.Done, (int)SearchProgress.Done)) return; } } }
internal void Highlight(ProgressForm form, TreeNode resultNode, SearchDescriptor searchData) { int moduleCount = GetModuleCount(); IEAdvancedSearch module = null; for (int i = 0; i < resultNode.Nodes.Count; i++) { int percent = System.Convert.ToInt32(System.Convert.ToDouble(i) / resultNode.Nodes.Count * 100); TreeNode root = resultNode.Nodes[i]; WindowInfoTag wTag = root.Tag as WindowInfoTag; try { module = GetModuleByThread(wTag.ThreadID) as IEAdvancedSearch; } catch { } if (module != null) { foreach (TreeNode leaf in root.Nodes) { module.HighlightHtmlPageElements(isHighlighted, (int)leaf.Tag, (int)flags, searchData.Term); form.progressBar.Increment(percent - form.progressBar.Value); } } } form.progressBar.Value = 100; this.isHighlighted = !this.isHighlighted; }
internal static Root CollectHtmlNodes(ref SearchDescriptor searchData) { Root root = null; List<int> positions = null; List<Node> nodes = new List<Node>(); ModuleDescriptor moduleDesc = searchData.Modules[searchData.CurrentModuleIndex]; moduleDesc.Form = new HTMLForm(); try { if (moduleDesc.HTMLDoc != null) { moduleDesc.Form.Text = moduleDesc.HTMLDoc.title; mshtml.IHTMLElement documentElement = moduleDesc.HTMLDoc.documentElement; if (documentElement != null && !String.IsNullOrEmpty(documentElement.outerHTML)) { moduleDesc.Form.richHtmlText.Text = documentElement.outerHTML; int length = moduleDesc.Form.richHtmlText.Lines.Length; for (int line = 0; line < length; line++) { if (searchData.CheckCase) { if (searchData.CheckWholeWord) { if ((positions = VisibleContent.CaseSensitive.WholeWord.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); } } } else { if ((positions = VisibleContent.CaseSensitive.WordAsPart.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); } } } } else { if (searchData.CheckWholeWord) { if ((positions = VisibleContent.CaseInsensetive.WholeWord.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); } } } else { if ((positions = VisibleContent.CaseInsensetive.WordAsPart.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); } } } } } if (nodes.Count > Const.Ok) root = new Root(moduleDesc.HTMLDoc.title, nodes, new WindowInfoTag(moduleDesc, searchData.Term, searchData.Flags)); Marshal.ReleaseComObject(documentElement); documentElement = null; } } } finally { if (moduleDesc.Form != null) { moduleDesc.Form.Dispose(); moduleDesc.Form = null; } } return root; }
private static Root CollectTextNodes(List<int> pos, ref SearchDescriptor searchData) { Root root = null; if (pos == null) return root; ModuleDescriptor moduleDesc = searchData.Modules[searchData.CurrentModuleIndex]; mshtml.IHTMLElement documentElement = moduleDesc.HTMLDoc.documentElement; if (documentElement != null && !String.IsNullOrEmpty(documentElement.outerHTML)) { List<Node> nodes = new List<Node>(); mshtml.IHTMLTxtRange range = null; for (int position = 0; position < pos.Count; position++) { mshtml.IHTMLSelectionObject sel = moduleDesc.HTMLDoc.selection; if (sel != null) { sel.empty(); Marshal.ReleaseComObject(sel); } mshtml.IHTMLSelectionObject selectionObject = moduleDesc.HTMLDoc.selection; mshtml.IHTMLElement bodyElement = moduleDesc.HTMLDoc.body; range = selectionObject.createRange() as mshtml.IHTMLTxtRange; range.moveToElementText(bodyElement); for (int i = 1; i <= position; i++) { range.findText(searchData.Term, bodyElement.innerText.Length, (int)searchData.Flags); range.moveStart("character", 1); } range.findText(searchData.Term, bodyElement.innerText.Length, (int)searchData.Flags); mshtml.IHTMLElement parentElement = range.parentElement(); Node node = new Node(parentElement.innerText, moduleDesc.HTMLDoc.title, position, null); nodes.Add(node); Marshal.ReleaseComObject(parentElement); parentElement = null; Marshal.ReleaseComObject(bodyElement); bodyElement = null; Marshal.ReleaseComObject(selectionObject); selectionObject = null; Marshal.ReleaseComObject(range); range = null; } if (nodes.Count > Const.Ok) root = new Root(moduleDesc.HTMLDoc.title, nodes, new WindowInfoTag(moduleDesc, searchData.Term, searchData.Flags)); Marshal.ReleaseComObject(documentElement); documentElement = null; } return root; }
internal static Root Searching_Window_Tabs_Text(ref SearchDescriptor searchData) { Root root = null; List<int> positions = null; ModuleDescriptor moduleDesc = searchData.Modules[searchData.CurrentModuleIndex]; mshtml.IHTMLElement body = moduleDesc.HTMLDoc.body; if (body != null && !String.IsNullOrEmpty(body.innerText)) { if (searchData.CheckCase) { if (searchData.CheckWholeWord) { positions = VisibleContent.CaseSensitive.WholeWord.AdvancedSearchEngine.Contains(moduleDesc.HTMLDoc.body.innerText, searchData.Term); searchData.Flags = SearchFlags.ieMatchCase | SearchFlags.ieMatchWholeWordsOnly; } else { positions = VisibleContent.CaseSensitive.WordAsPart.AdvancedSearchEngine.Contains(moduleDesc.HTMLDoc.body.innerText, searchData.Term); searchData.Flags = SearchFlags.ieMatchCase | SearchFlags.ieMatchPartialWords; } } else { if (searchData.CheckWholeWord) { positions = VisibleContent.CaseInsensetive.WholeWord.AdvancedSearchEngine.Contains(moduleDesc.HTMLDoc.body.innerText, searchData.Term); searchData.Flags = SearchFlags.ieMatchWholeWordsOnly; } else { positions = VisibleContent.CaseInsensetive.WordAsPart.AdvancedSearchEngine.Contains(moduleDesc.HTMLDoc.body.innerText, searchData.Term); searchData.Flags = SearchFlags.ieMatchPartialWords; } } root = CollectTextNodes(positions, ref searchData); Marshal.ReleaseComObject(body); body = null; } return root; }
private static void Search_Windows_Tab_HTML(ref SearchDescriptor searchData) { for (int currentModule = 0; currentModule < searchData.Modules.Count; currentModule++) { searchData.CurrentModuleIndex = currentModule; if (IsWindowVisible(searchData.Modules[currentModule].TabWnd)) { if (CancelOperationOrReportUI(System.Convert.ToInt32(System.Convert.ToDouble(currentModule) / searchData.Modules.Count * 100))) return; Root root = CollectHtmlNodes(ref searchData); if (root != null) { TreeNode treeNode = new TreeNode(root.Title); treeNode.Tag = root.WindowInfo; List<TreeNode> treeNodes = new List<TreeNode>(root.Nodes.Count); foreach (Node nodeInTheList in root.Nodes) { TreeNode leaf = new TreeNode(nodeInTheList.InnerText); leaf.ToolTipText = nodeInTheList.ToolTipText; leaf.Tag = nodeInTheList.HtmlTag; treeNodes.Add(leaf); } treeNode.Nodes.AddRange(treeNodes.ToArray()); searchData.ResultNode.Nodes.Add(treeNode); } } if (CancelOperationOrReportUI(System.Convert.ToInt32(System.Convert.ToDouble(currentModule) / searchData.Modules.Count * 100))) return; } if (CancelOperationOrReportUI((int)SearchProgress.Done, SearchProgress.Done)) return; }