ZForge.Controls.ExplorerBar.Expando.CalcHeightAndLayout C# (CSharp) Method

CalcHeightAndLayout() private method

Calculates the height that the Expando would be if a call to DoLayout() were made
private CalcHeightAndLayout ( ) : int
return int
        internal int CalcHeightAndLayout()
        {
            // stop the layout engine
            this.SuspendLayout();

            // work out the height of the header section

            // is there an image to display on the titlebar
            if (this.titleImage != null)
            {
                // is the image bigger than the height of the titlebar
                if (this.titleImage.Height > this.titleBarHeight)
                {
                    this.headerHeight = this.titleImage.Height;
                }
                    // is the image smaller than the height of the titlebar
                else if (this.titleImage.Height < this.titleBarHeight)
                {
                    this.headerHeight = this.titleBarHeight;
                }
                    // is the image smaller than the current header height
                else if (this.titleImage.Height < this.headerHeight)
                {
                    this.headerHeight = this.titleImage.Height;
                }
            }
            else
            {
                this.headerHeight = this.titleBarHeight;
            }

            int y = -1;

            // do we need to layout our items
            if (this.AutoLayout)
            {
                Control c;
                TaskItem ti;
                Point p;

                // work out how wide to make the controls, and where
                // the top of the first control should be
                y = this.DisplayRectangle.Y + this.Padding.Top;
                int width = this.PseudoClientRect.Width - this.Padding.Left - this.Padding.Right;

                // for each control in our list...
                for (int i=0; i<this.itemList.Count; i++)
                {
                    c = (Control) this.itemList[i];

                    if (this.hiddenControls.Contains(c))
                    {
                        continue;
                    }

                    // set the starting point
                    p = new Point(this.Padding.Left, y);

                    // is the control a TaskItem?  if so, we may
                    // need to take into account the margins
                    if (c is TaskItem)
                    {
                        ti = (TaskItem) c;

                        // only adjust the y co-ord if this isn't the first item
                        if (i > 0)
                        {
                            y += ti.Margin.Top;

                            p.Y = y;
                        }

                        // adjust and set the width and height
                        ti.Width = width;
                        ti.Height = ti.PreferredHeight;
                    }
                    else
                    {
                        y += this.systemSettings.TaskItem.Margin.Top;

                        p.Y = y;
                    }

                    // set the location of the control
                    c.Location = p;

                    // update the next starting point.
                    y += c.Height;

                    // is the control a TaskItem?  if so, we may
                    // need to take into account the bottom margin
                    if (i < this.itemList.Count-1)
                    {
                        if (c is TaskItem)
                        {
                            ti = (TaskItem) c;

                            y += ti.Margin.Bottom;
                        }
                        else
                        {
                            y += this.systemSettings.TaskItem.Margin.Bottom;
                        }
                    }
                }

                // workout where the bottom of the Expando should be
                y += this.Padding.Bottom + this.Border.Bottom;
            }

            // restart the layout engine
            this.ResumeLayout(true);

            return y;
        }