예제 #1
0
        internal object BuildObjectTree()
        { 
            IAddChild root;
            switch (_type) 
            { 
                case ElementType.Table:
                    root = new Table(); 
                    break;
                case ElementType.TableRowGroup:
                    root = new TableRowGroup();
                    break; 
                case ElementType.TableRow:
                    root = new TableRow(); 
                    break; 
                case ElementType.TableCell:
                    root = new TableCell(); 
                    break;
                case ElementType.Paragraph:
                    root = new Paragraph();
                    break; 
                case ElementType.Hyperlink:
                    Hyperlink link = new Hyperlink(); 
                    link.NavigateUri = GetValue(NavigateUriProperty) as Uri; 
                    link.RequestNavigate += new RequestNavigateEventHandler(ClickHyperlink);
                    AutomationProperties.SetHelpText(link, (String)this.GetValue(HelpTextProperty)); 
                    AutomationProperties.SetName(link, (String)this.GetValue(NameProperty));
                    root = link;
                    break;
                default: 
                    Debug.Assert(false);
                    root = null; 
                    break; 
            }
 
            ITextPointer pos = ((ITextPointer)_start).CreatePointer();

            while (pos.CompareTo((ITextPointer)_end) < 0)
            { 
                TextPointerContext tpc = pos.GetPointerContext(LogicalDirection.Forward);
                if (tpc == TextPointerContext.Text) 
                { 
                    root.AddText(pos.GetTextInRun(LogicalDirection.Forward));
                } 
                else if (tpc == TextPointerContext.EmbeddedElement)
                {
                    root.AddChild(pos.GetAdjacentElement(LogicalDirection.Forward));
                } 
                else if (tpc == TextPointerContext.ElementStart)
                { 
                    object obj = pos.GetAdjacentElement(LogicalDirection.Forward); 
                    if (obj != null)
                    { 
                        root.AddChild(obj);
                        pos.MoveToNextContextPosition(LogicalDirection.Forward);
                        pos.MoveToElementEdge(ElementEdge.BeforeEnd);
                    } 
                }
 
                pos.MoveToNextContextPosition(LogicalDirection.Forward); 

            } 
            return root;
        }
        internal object BuildObjectTree()
        {
            IAddChild root;

            switch (_type)
            {
            case ElementType.Table:
                root = new Table();
                break;

            case ElementType.TableRowGroup:
                root = new TableRowGroup();
                break;

            case ElementType.TableRow:
                root = new TableRow();
                break;

            case ElementType.TableCell:
                root = new TableCell();
                break;

            case ElementType.Paragraph:
                root = new Paragraph();
                break;

            case ElementType.Hyperlink:
                Hyperlink link = new Hyperlink();
                link.NavigateUri      = GetValue(NavigateUriProperty) as Uri;
                link.RequestNavigate += new RequestNavigateEventHandler(ClickHyperlink);
                AutomationProperties.SetHelpText(link, (String)this.GetValue(HelpTextProperty));
                AutomationProperties.SetName(link, (String)this.GetValue(NameProperty));
                root = link;
                break;

            default:
                Debug.Assert(false);
                root = null;
                break;
            }

            ITextPointer pos = ((ITextPointer)_start).CreatePointer();

            while (pos.CompareTo((ITextPointer)_end) < 0)
            {
                TextPointerContext tpc = pos.GetPointerContext(LogicalDirection.Forward);
                if (tpc == TextPointerContext.Text)
                {
                    root.AddText(pos.GetTextInRun(LogicalDirection.Forward));
                }
                else if (tpc == TextPointerContext.EmbeddedElement)
                {
                    root.AddChild(pos.GetAdjacentElement(LogicalDirection.Forward));
                }
                else if (tpc == TextPointerContext.ElementStart)
                {
                    object obj = pos.GetAdjacentElement(LogicalDirection.Forward);
                    if (obj != null)
                    {
                        root.AddChild(obj);
                        pos.MoveToNextContextPosition(LogicalDirection.Forward);
                        pos.MoveToElementEdge(ElementEdge.BeforeEnd);
                    }
                }

                pos.MoveToNextContextPosition(LogicalDirection.Forward);
            }
            return(root);
        }