void OnLayoutEditor(object sender, TextEditorLayoutEventArgs args)
        {
            Rectangle r = this.GetTextBounds(this.selectedNode);

            r.Offset(this.scrollPosition);
            args.PreferredBounds = r;
            args.MaxBounds       = r;
        }
Пример #2
0
 public void PerformLayout()
 {
     if (this.LayoutEditor != null)
     {
         TextEditorLayoutEventArgs args = new TextEditorLayoutEventArgs(this._currentEditor.Text);
         LayoutEditor(this, args);
         SetEditorBounds(args);
     }
 }
Пример #3
0
        void AdjustBounds(string text, Graphics g, TextEditorLayoutEventArgs args)
        {
            Rectangle r = args.PreferredBounds;

            if (AutoSize)
            {
                if (string.IsNullOrEmpty(text))
                {
                    text = "W"; // double the size if it was empty to begin with.
                }
                text += "W";    // leave room to grow by one more char
            }
            if (text.EndsWith("\n"))
            {
                text += ".";                      // cause MeasureString to include space for newlines.
            }
            SizeF size      = SizeF.Empty;
            int   maxHeight = (this._parent.Height * 2) / 3;

            try
            {
                if (text.Length >= 10000)
                {
                    // MeasureString gets too slow after a certain size.
                    text = text.Substring(0, 10000);
                }
                size = g.MeasureString(text, this._parent.Font, this._parent.Width, StringFormat.GenericDefault);
            }
            catch (Exception)
            {
                // string might be too long to measure!
                size = new SizeF(r.Width, maxHeight);
            }
            int h = (int)Math.Max(r.Height, Math.Ceiling(size.Height));

            if (h > r.Height)
            {
                // when multiline, add padding so that it aligns correctly.
                h += this._parent.Font.Height / 2;
            }
            r.Height = Math.Min(maxHeight, h); // no more than 2/3rd of the window.
            if (AutoSize)
            {
                r.Width = Math.Max(r.Width, (int)size.Width + 2);
            }
            if (r.Right > args.MaxBounds.Right)
            {
                r.Width = args.MaxBounds.Right - r.Left;
            }
            args.PreferredBounds = r;
        }
Пример #4
0
        void SetEditorBounds(TextEditorLayoutEventArgs args)
        {
            string   text = this._currentEditor.Text;
            Graphics g    = this._parent.CreateGraphics();

            using (g)
            {
                AdjustBounds(text, g, args);
            }
            Rectangle r = args.PreferredBounds;

            if (r.Bottom > this._parent.Height)
            {
                // todo: scroll the view so we don't have to pop-up backwards, but this is tricky because
                // we may need to scroll more than the XmlTreeView scrollbar maximum in the case where the
                // last node has a lot of text...
                r.Offset(new Point(0, this._parent.Height - r.Bottom));
            }
            int maxHeight = (this._parent.Height * 2) / 3;

            if (r.Height < maxHeight)
            {
                int h = this._currentEditor.PreferredSize.Height;
                if (r.Height < h)
                {
                    r.Y -= (h - r.Height) / 2;
                    if (r.Y < 0)
                    {
                        r.Y = 0;
                    }
                    r.Height = h;
                }
            }
            Rectangle or = this._currentEditor.Bounds;

            if (or.Left != r.Left || or.Right != r.Right || or.Top != r.Top || or.Bottom != r.Bottom)
            {
                this._currentEditor.Bounds = r;
            }
        }
Пример #5
0
 void OnLayoutEditor(object sender, TextEditorLayoutEventArgs args)
 {
     Rectangle r = this.GetTextBounds(this.selectedNode);
     r.Offset(this.scrollPosition);
     args.PreferredBounds = r;
     args.MaxBounds = r;
 }
Пример #6
0
 void SetEditorBounds(TextEditorLayoutEventArgs args)
 {
     string text = this.currentEditor.Text;
     Graphics g = this.parent.CreateGraphics();
     using (g) {
         AdjustBounds(text, g, args);
     }
     Rectangle r = args.PreferredBounds;
     if (r.Bottom > this.parent.Height) {
         // todo: scroll the view so we don't have to pop-up backwards, but this is tricky because
         // we may need to scroll more than the XmlTreeView scrollbar maximum in the case where the
         // last node has a lot of text...
         r.Offset(new Point(0, this.parent.Height - r.Bottom));
     }
     int maxHeight = (this.parent.Height * 2) / 3;
     if (r.Height < maxHeight) {
         int h = this.currentEditor.PreferredSize.Height;
         if (r.Height < h) {
             r.Y -= (h - r.Height) / 2;
             if (r.Y < 0) r.Y = 0;
             r.Height = h;
         }
     }
     Rectangle or = this.currentEditor.Bounds;
     if (or.Left != r.Left || or.Right != r.Right || or.Top != r.Top || or.Bottom != r.Bottom) {
         this.currentEditor.Bounds = r;
     }
 }
Пример #7
0
 void AdjustBounds(string text, Graphics g, TextEditorLayoutEventArgs args)
 {
     Rectangle r = args.PreferredBounds;
     if (AutoSize) {
         if (string.IsNullOrEmpty(text))
             text = "W"; // double the size if it was empty to begin with.
         text += "W"; // leave room to grow by one more char
     }
     if (text.EndsWith("\n")) text += "."; // cause MeasureString to include space for newlines.
     SizeF size = SizeF.Empty;
     int maxHeight = (this.parent.Height * 2) / 3;
     try {
         if (text.Length >= 10000) {
             // MeasureString gets too slow after a certain size.
             text = text.Substring(0, 10000);
         }
         size = g.MeasureString(text, this.parent.Font, this.parent.Width, StringFormat.GenericDefault);
     } catch (Exception) {
         // string might be too long to measure!
         size = new SizeF(r.Width, maxHeight);
     }
     int h = (int)Math.Max(r.Height, Math.Ceiling(size.Height));
     if (h > r.Height ) {
         // when multiline, add padding so that it aligns correctly.
         h += this.parent.Font.Height / 2;
     }
     r.Height = Math.Min(maxHeight, h); // no more than 2/3rd of the window.
     if (AutoSize) {
         r.Width = Math.Max(r.Width, (int)size.Width + 2);
     }
     if (r.Right > args.MaxBounds.Right)
         r.Width = args.MaxBounds.Right - r.Left;
     args.PreferredBounds = r;
 }
Пример #8
0
 public void PerformLayout()
 {
     if (this.LayoutEditor != null) {
         TextEditorLayoutEventArgs args = new TextEditorLayoutEventArgs(this.currentEditor.Text);
         LayoutEditor(this, args);
         SetEditorBounds(args);
     }
 }