internal void RefreshIfExpanded(CellEditorData cellData)
        {
            Debug.Assert(cellData != null, "cellData != null");

            if (cellData.IsExpanded)
            {
                // If the value has changed collapse the expanded cell. Then expand it again, unless the value was
                // set to null or has become unavailable.

                if (cellData.Wrapper.ValueIsNullOrUnavailable || cellData.Wrapper.Modified)
                {
                    MemberWrapperEventArgs args = new MemberWrapperEventArgs(cellData.Wrapper);
                    OnCollapse(args);
                    cellData.IsExpanded = false;

                    if (!cellData.Wrapper.ValueIsNullOrUnavailable)
                    {
                        OnExpand(args);
                        cellData.IsExpanded = true;
                    }
                }
            }
            else
            {
                // Needed in case the member has no children to allow the user to try expanding it again.
                cellData.Children = null;
            }
        }
        private static int GetTotalButtonSpaceWidth(MemberWrapper property)
        {
            CellEditorData cellData = (CellEditorData)property.Tag;
            int            level    = (cellData == null ? 0 : cellData.Level);

            return(level * m_indent + m_expandBoxSide + 8);
        }
Exemple #3
0
        private void nameColumn_Expand(object sender, MemberWrapperEventArgs e)
        {
            using (new LongRunningMonitor(this))
            {
                int index = m_properties.IndexOf(e.Wrapper);
                Debug.Assert(index != -1, "index != -1");
                Debug.Assert(!e.Wrapper.ValueIsNullOrUnavailable, "Trying to expand a null or unavailable value.");

                CellEditorData cellData = (CellEditorData)e.Wrapper.Tag;
                Debug.Assert(!cellData.IsExpanded, "Expanding an already expanded row.");

                // Create a new GenericWrapper object for the expanded value and get its properties.

                GenericWrapper genericWrapper = e.Wrapper.CreateWrapper();
                Debug.Assert(genericWrapper != null, "CreateWrapper() returned null for the member being expanded.");
                cellData.Children = genericWrapper.GetMembers();

                foreach (MemberWrapper childProperty in cellData.Children)
                {
                    childProperty.SetValueFormat(m_valueFormat);
                    childProperty.Tag           = new CellEditorData(childProperty, cellData.Level + 1, cellData);
                    childProperty.ValueChanged += new EventHandler(m_handler.ItemValueChanged);
                    m_properties.Insert(++index, childProperty);
                }

                if (cellData.Children.Count == 0)
                {
                    ((DataGridExpandableColumn)sender).Invalidate();
                }
                else
                {
                    ((CellEditorData)cellData.Children[cellData.Children.Count - 1].Tag).IsLastInLevel = true;
                }
            }
        }
        private static Rectangle GetBoxBoundsForCellBounds(Rectangle cellBounds, MemberWrapper property,
                                                           out int totalWidth)
        {
            CellEditorData cellData = (CellEditorData)property.Tag;

            int level = (cellData == null ? 0 : cellData.Level);
            int x     = cellBounds.X + 2 + level * m_indent;

            totalWidth = level * m_indent + m_expandBoxSide + 8;

            return(new Rectangle(x, cellBounds.Y + 2, m_expandBoxSide, m_expandBoxSide));
        }
        private static bool CanExpandProperty(MemberWrapper property)
        {
            Debug.Assert(property != null, "property != null");

            if (!property.MayHaveChildren || !property.CanRead || !property.CanCreateWrapper ||
                property.ValueIsNullOrUnavailable || property.ValueTypeIsParseableSystemType() ||
                !(property.ValueAsString is string))
            {
                return(false);
            }

            CellEditorData cellData = (CellEditorData)property.Tag;

            return(!cellData.HasNoChildren);
        }
        internal void ExpandRow(CurrencyManager source, int rowNum)
        {
            MemberWrapper  wrapper  = GetProperty(source, rowNum);
            CellEditorData cellData = (CellEditorData)wrapper.Tag;

            if (cellData.IsExpanded)
            {
                return;                 // Already expanded.
            }
            OnExpand(new MemberWrapperEventArgs(wrapper));

            if (!cellData.HasNoChildren)
            {
                cellData.IsExpanded = !cellData.IsExpanded;
            }
        }
Exemple #7
0
        public void RestoreExpandedRows(RowTree rows)
        {
            if (rows == null)
            {
                return;
            }

            CurrencyManager source = grid.CurrencyManager;

            if (source == null)
            {
                return;                 // No data source.
            }
            RowTree current      = rows;
            int     currentLevel = 0;

            for (int index = 0; index < source.List.Count; index++)
            {
                MemberWrapper wrapper = (MemberWrapper)source.List[index];
                Debug.Assert(wrapper != null, "wrapper != null");
                CellEditorData cellData = (CellEditorData)wrapper.Tag;
                Debug.Assert(cellData != null, "cellData != null");

                if (cellData.IsExpanded || cellData.Level > currentLevel)
                {
                    continue;                     // Already expanded or below an expanded node for which we don't have any children listed.
                }
                while (cellData.Level < currentLevel)
                {
                    current = current.Parent;
                    currentLevel--;
                }

                RowTree expanded = current[wrapper.Name];
                if (expanded != null)
                {
                    // Found it - expand this row.

                    NameColumn.ExpandRow(source, index);

                    // Look for child expanded rows (if any).

                    current = expanded;
                    currentLevel++;
                }
            }
        }
Exemple #8
0
        public void SaveExpandedRows(ref RowTree rows)
        {
            CurrencyManager source = grid.CurrencyManager;

            if (source == null)
            {
                return;                 // No data source.
            }
            if (rows == null)
            {
                rows = new RowTree(null, null);
            }
            RowTree parent       = rows;
            int     currentLevel = 0;

            for (int index = 0; index < source.List.Count; index++)
            {
                MemberWrapper wrapper = (MemberWrapper)source.List[index];
                Debug.Assert(wrapper != null, "wrapper != null");
                CellEditorData cellData = (CellEditorData)wrapper.Tag;
                Debug.Assert(cellData != null, "cellData != null");

                while (cellData.Level < currentLevel)
                {
                    Debug.Assert(parent.Parent != null, "parent.Parent != null");
                    parent = parent.Parent;
                    currentLevel--;
                }

                if (cellData.IsExpanded)
                {
                    RowTree current = parent[wrapper.Name];
                    if (current == null)
                    {
                        current = new RowTree(wrapper.Name, parent);
                        parent.Add(current);
                    }

                    parent = current;
                    currentLevel++;
                }
                else if (parent[wrapper.Name] != null)
                {
                    parent.Remove(wrapper.Name);
                }
            }
        }
        private void ExpandCollapseCurrent()
        {
            CellEditorData cellData = (CellEditorData)m_currentValue.Tag;

            if (cellData.IsExpanded)
            {
                OnCollapse(new MemberWrapperEventArgs(m_currentValue));
            }
            else
            {
                OnExpand(new MemberWrapperEventArgs(m_currentValue));
            }

            if (!cellData.HasNoChildren)
            {
                cellData.IsExpanded = !cellData.IsExpanded;
            }
        }
Exemple #10
0
        private void nameColumn_Collapse(object sender, MemberWrapperEventArgs e)
        {
            int index = m_properties.IndexOf(e.Wrapper);

            Debug.Assert(index != -1, "index != -1");

            CellEditorData cellData = (CellEditorData)e.Wrapper.Tag;

            Debug.Assert(cellData.IsExpanded, "Collapsing a row that is not expanded.");

            int totalRows = cellData.TotalExpandedRows;

            for (int i = 1; i <= totalRows; i++)
            {
                m_properties[index + i].ValueChanged -= new EventHandler(m_handler.ItemValueChanged);
            }

            m_properties.RemoveRange(index + 1, totalRows);
            cellData.Children = null;
        }
        private static void PaintExpandControls(Graphics g, ref Rectangle bounds, CurrencyManager source, int rowNum,
                                                Brush backBrush, Brush foreBrush)
        {
            MemberWrapper property = GetProperty(source, rowNum);

            int       totalWidth;
            Rectangle box          = GetBoxBoundsForCellBounds(bounds, property, out totalWidth);
            Rectangle buttonBounds = new Rectangle(bounds.X, bounds.Y, totalWidth, bounds.Height);

            Pen forePen = new Pen(foreBrush);

            // Fill in the whole expand box area.

            g.FillRectangle(backBrush, buttonBounds);

            bool drawBox = CanExpandProperty(property);

            if (drawBox)
            {
                // Draw the box and the horizontal bar (-).

                g.DrawRectangle(forePen, box);

                int y = box.Y + box.Height / 2;
                g.DrawLine(forePen, box.Left + 3, y, box.Right - 3, y);

                if (IsPropertyExpanded(property))
                {
                    // Expanded - draw the line going down.

                    int x = box.X + box.Width / 2;
                    g.DrawLine(forePen, x, box.Bottom, x, bounds.Bottom);
                }
                else
                {
                    // Not expanded - draw the vertical bar to make a +.

                    int x = box.X + box.Width / 2;
                    g.DrawLine(forePen, x, box.Top + 3, x, box.Bottom - 3);
                }
            }

            CellEditorData cellData = (CellEditorData)property.Tag;

            if (cellData != null && cellData.Level > 0)
            {
                // Draw lines to the parent. Note that we have to go 1 pixel above the bounds to draw across
                // the horizontal grid line.

                int xLeft   = box.X - m_indent + m_expandBoxSide / 2;
                int xRight  = (drawBox ? box.X : box.X + m_expandBoxSide / 2);
                int yMiddle = box.Y + box.Height / 2;
                int yBottom = (cellData.IsLastInLevel ? yMiddle : bounds.Bottom);

                g.DrawLine(forePen, xLeft, yMiddle, xRight, yMiddle);
                g.DrawLine(forePen, xLeft, bounds.Top - 1, xLeft, yBottom);

                // Draw lines going past us from other ancestors to further children, unless we are the last child.

                int level = cellData.Level - 1;
                cellData = cellData.Parent;

                while (cellData.Parent != null)
                {
                    if (!cellData.IsLastInLevel)
                    {
                        int xMiddle = bounds.X + level * m_indent - m_expandBoxSide / 2 - 2;
                        g.DrawLine(forePen, xMiddle, bounds.Top - 1, xMiddle, bounds.Bottom);
                    }

                    cellData = cellData.Parent;
                    level--;
                }
            }

            bounds = new Rectangle(bounds.X + totalWidth, bounds.Y, bounds.Width - totalWidth, bounds.Height);
        }
Exemple #12
0
 internal CellEditorData(MemberWrapper wrapper, int level, CellEditorData parent)
 {
     m_wrapper = wrapper;
     m_level   = level;
     m_parent  = parent;
 }