using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Documents; namespace Demos.Warden.TagTextEditing { internal class ProcessableElementsChecker { public bool Check(FlowDocument document) { bool result = true; foreach (Block block in document.Blocks.ToArray()) { if (block is Paragraph) { if (this.ProcessParagraph((Paragraph)block) == false) { return false; } } else if (block is ThreeColumnLayoutTable) { if (this.ProcessThreeColumnLayout((ThreeColumnLayoutTable)block) == false) { return false; } } else if (block is Table) { if (this.ProcessTable((Table)block) == false) { return false; } } else if (block is BlockUIContainer) { if (this.ProcessBlockUIContainer((BlockUIContainer)block) == false) { return false; } } else { return false; } } return result; } private bool ProcessBlockUIContainer(BlockUIContainer block) { bool result = true; if (block.Child is System.Windows.Controls.Image) { result = true; } else { result = false; } return result; } private bool ProcessParagraph(Paragraph para) { bool result = true; foreach (Inline inline in para.Inlines.ToArray()) { if (this.ProcessInline(inline) == false) { return false; } } return result; } private bool ProcessInline(Inline inline) { bool result = true; if (!(inline is Run) && !(inline is Span) && !(inline is InlineUIContainer && ((InlineUIContainer)inline).Child is System.Windows.Controls.Image)) { result = false; } if (inline is Span) { Span curSpan = (Span)inline; foreach (Inline subInline in curSpan.Inlines.ToArray()) { if (this.ProcessInline(subInline) == false) { return false; } } } return result; } private bool ProcessThreeColumnLayout(ThreeColumnLayoutTable threeColumnLayout) { bool result = true; foreach (TableRowGroup curRowGroup in threeColumnLayout.RowGroups) { foreach (TableRow curRow in curRowGroup.Rows) { foreach (TableCell tc in curRow.Cells) { foreach (Block curBlock in tc.Blocks) { if (curBlock is Paragraph) { if (this.ProcessParagraph((Paragraph)curBlock) == false) { return false; } } } } } } return result; } private bool ProcessTable(Table table) { bool result = true; int clmnCount = table.Columns.Count; int rowGroupCount = table.RowGroups.Count; for (int rgi = 0; rgi < rowGroupCount; rgi++) { TableRowGroup rg = table.RowGroups[rgi]; int rowsCount = rg.Rows.Count; for (int ri = 0; ri < rowsCount; ri++) { TableRow row = rg.Rows[ri]; for (int clmi = 0; clmi < clmnCount; clmi++) { BlockCollection curTableCellBlocks = row.Cells[clmi].Blocks; foreach (Block curBlock in curTableCellBlocks) { if (curBlock is Paragraph) { if (this.ProcessParagraph((Paragraph)curBlock) == false) { return false; } } } } } } return result; } } }