public static bool Compare(VirtualTreeDisplayData operand1, VirtualTreeDisplayData operand2)
 {
     Debug.Assert(false); // There is no need to compare these
     return false;
 }
        /// <summary>
        ///     Returns structure describing how this branch should be displayed.
        /// </summary>
        /// <param name="row">Index into this branch</param>
        /// <param name="column">Column index</param>
        /// <param name="requiredData">The data that must be filled in</param>
        /// <returns>
        ///     Structure to be filled with display information.  By default,
        ///     No icon is specified, and read-only and creator nodes are grayed out.
        /// </returns>
        protected virtual VirtualTreeDisplayData GetDisplayData(int row, int column, VirtualTreeDisplayDataMasks requiredData)
        {
            var data = new VirtualTreeDisplayData(-1);

            // account for row insertion index
            if (_insertingIndex != -1
                && row > _insertingIndex)
            {
                row--;
            }

            var count = ElementCount;

            if ((requiredData.Mask & VirtualTreeDisplayMasks.StateImage) != 0
                && row < count)
            {
                var columnDescriptor = _columns[column];

                if (columnDescriptor.ColumnIsCheckBox)
                {
                    var checkState = columnDescriptor.GetCheckBoxValue(GetElement(row));

                    if (checkState != CheckBoxState.Unsupported)
                    {
                        // set state index
                        data.StateImageIndex = (short)checkState;
                    }
                }
            }

            if (row >= count)
            {
                // display creator nodes in gray
                data.GrayText = true;
            }
            else if (_lastText != null
                     && _lastText.Length > 0)
            {
                // use lastText here as an optimization.  If there's no text, there's no
                // reason to call derived classes to check the value, as GrayText setting is
                // irrelevant
                var supportedState = GetValueSupported(row, column);
                // display non-editable nodes in gray
                if ((supportedState & TreeGridDesignerValueSupportedStates.DisplayReadOnly) != 0)
                {
                    data.GrayText = true;
                }
            }
            return data;
        }
示例#3
0
        /// <summary>
        ///     Retrieves display data for the header row.
        /// </summary>
        protected virtual VirtualTreeDisplayData GetDisplayData(int row, int column, VirtualTreeDisplayDataMasks requiredData)
        {
            var data = new VirtualTreeDisplayData(-1);

            if (column == 0)
            {
                data.Bold = true;
            }

            if ((requiredData.Mask & VirtualTreeDisplayMasks.StateImage) != 0
                && row < _currentBranches.Count)
            {
                var columnDescriptor = _columns[column];

                if (columnDescriptor.ColumnIsCheckBox)
                {
                    var checkState = GetCheckBoxValue(row, column);

                    if (checkState != CheckBoxState.Unsupported)
                    {
                        // set state index
                        data.StateImageIndex = (short)checkState;
                    }
                }
            }

            return data;
        }
示例#4
0
 public static bool Compare(VirtualTreeDisplayData operand1, VirtualTreeDisplayData operand2)
 {
     Debug.Assert(false); // There is no need to compare these
     return(false);
 }
        private void DrawIndentLines(
            Graphics graphics, Color backColor, Color foreColor, int absIndex, int nativeColumn, VirtualTreeItemInfo info,
            VirtualTreeDisplayData tdd, int remainingWidth, int adjustedItemHeight, ref int textLeft)
        {
            var level = info.Level;
            var expandable = HasButtons && info.Expandable;
            var expanded = expandable && info.Expanded;

            Brush brush = null;
            try
            {
                // Fill the background with the given backColor.
                EnsureBrush(ref brush, backColor);

                if (0 == (myStyleFlags & VTCStyleFlags.MaskHasIndentBitmaps))
                {
                    if (level > 0)
                    {
                        textLeft = level * myIndentWidth;
                        graphics.FillRectangle(brush, 0, 0, textLeft, adjustedItemHeight);
                    }
                }
                else
                {
                    int iRow;
                    var iColumn = 0;
                    if (!HasLines) // HasLines and HasRootLines are synchronized, only HasButtons (and possibly HasRootButtons) is set
                    {
                        if (HasRootButtons && (nativeColumn == 0 || !info.SimpleCell))
                        {
                            ++level;
                        }
                        if (level > 0)
                        {
                            textLeft = level * myIndentWidth;
                            if (info.Blank)
                            {
                                if (tdd.Image != -1)
                                {
                                    textLeft += myImageWidth;
                                }
                                if (tdd.StateImageIndex != -1)
                                {
                                    textLeft += myImageWidth;
                                }
                            }
                            // We're just looking at buttons
                            if (expandable)
                            {
                                --level;
                                iColumn = 0;
                                iRow = expanded ? 1 : 0;
                                var destRect = new Rectangle(textLeft - myIndentWidth, 0, myIndentWidth, adjustedItemHeight);
                                if (destRect.Left < remainingWidth)
                                {
                                    // Ensure indent image doesn't draw outside bounding rectangle for this column
                                    if (destRect.Right > remainingWidth)
                                    {
                                        destRect.Width = remainingWidth - destRect.X;
                                    }
                                    graphics.DrawImage(
                                        GetIndentBitmap(backColor, foreColor), destRect, 0, iRow * myItemHeight, destRect.Width,
                                        adjustedItemHeight, GraphicsUnit.Pixel);
                                }
                            }
                        }
                        if (level > 0)
                        {
                            graphics.FillRectangle(brush, 0, 0, level * myIndentWidth, adjustedItemHeight);
                        }
                    }
                    else
                    {
                        // Determine the row to blit based on expansion state
                        // The rows are laid out {no expansion, plus, minus}
                        // The columns are laid out {level bmp, middle, bottom, top, single}
                        iRow = expandable ? (expanded ? 2 : 1) : 0;

                        // Determine the column to blit based on the position in the list
                        //						if (relIndex == (branch.ItemCount - 1))
                        if (info.LastBranchItem)
                        {
                            // Last item
                            //							if (HasRootLines && (branch.ItemCount == 1))
                            //							if (info.Blank)
                            //							{
                            //								skipGlyph = true;
                            //								levelAdjust = 1;
                            //							}
                            //							else
                            if (info.FirstBranchItem)
                            {
                                iColumn = (level == 0) ? 4 : 2;
                            }
                            else
                            {
                                iColumn = 2;
                            }
                        }
                            //						else if (info.Blank)
                            //						{
                            //							levelAdjust = 1;
                            //							if (info.Expanded)
                            //							{
                            //								iColumn = 0;
                            //								iRow = 0;
                            //							}
                            //							else
                            //							{
                            //								skipGlyph = true;
                            //							}
                            //						}
                        else
                        {
                            //							if ((relIndex == 0) && HasRootLines)
                            if (info.FirstBranchItem
                                && HasRootLines
                                && (nativeColumn == 0 || !info.SimpleCell))
                            {
                                iColumn = (level == 0) ? 3 : 1;
                            }
                            else
                            {
                                iColumn = 1;
                            }
                        }

                        var iStartColumn = 0;
                        if ((absIndex & 1) == 1
                            && (myItemHeight & 1) == 1)
                        {
                            // in the odd item height case, use different bitmaps in alternating rows to keep the gridlines looking good.
                            // see comment in CreateIndentBmp() for more info.
                            iStartColumn = (HasRootLines || HasRootButtons) ? 5 : 3;
                        }
                        iColumn += iStartColumn;

                        // Blit in the level bitmaps. This is trickier than it looks because
                        // a check is required at each level to see if the parent root lines
                        // are required.
                        if (GetAnyStyleFlag(VTCStyleFlags.HasRootLines | VTCStyleFlags.HasRootButtons)
                            && (nativeColumn == 0 || !info.SimpleCell))
                        {
                            ++level;
                        }

                        if (level > 0)
                        {
                            var bmp = GetIndentBitmap(backColor, foreColor);
                            var cxSrc = myIndentWidth;
                            var cySrc = myItemHeight;
                            textLeft = level * cxSrc;
                            var skipGlyph = false;
                            var destRect = new Rectangle((level - 1) * cxSrc, 0, cxSrc, cySrc);

                            if (info.Blank)
                            {
                                if (tdd.Image != -1)
                                {
                                    textLeft += myImageWidth;
                                }
                                if (tdd.StateImageIndex != -1)
                                {
                                    textLeft += myImageWidth;
                                }
                                iColumn = iStartColumn;
                                iRow = 0;
                                if (info.LastBranchItem)
                                {
                                    skipGlyph = true;
                                }
                                if (info.Expanded)
                                {
                                    destRect.Offset(cxSrc, 0);
                                    if (destRect.Left < remainingWidth)
                                    {
                                        // Ensure indent image doesn't draw outside bounding rectangle for this column.
                                        if (destRect.Right <= remainingWidth)
                                        {
                                            graphics.DrawImage(bmp, destRect, iColumn * cxSrc, 0, cxSrc, cySrc, GraphicsUnit.Pixel);
                                        }
                                        else
                                        {
                                            graphics.DrawImage(
                                                bmp, new Rectangle(destRect.X, destRect.Y, remainingWidth - destRect.X, destRect.Height),
                                                iColumn * cxSrc, 0, remainingWidth - destRect.X, cySrc, GraphicsUnit.Pixel);
                                        }
                                    }
                                    destRect.Offset(-cxSrc, 0);
                                }
                            }

                            var xSrc = iColumn * cxSrc;
                            var ySrc = iRow * myItemHeight; //cySrc;

                            if (!skipGlyph
                                && destRect.Left < remainingWidth)
                            {
                                // Do the initial glyph.  Ensure indent image doesn't draw outside bounding rectangle for this column.
                                if (destRect.Right <= remainingWidth)
                                {
                                    graphics.DrawImage(bmp, destRect, xSrc, ySrc, cxSrc, cySrc, GraphicsUnit.Pixel);
                                }
                                else
                                {
                                    graphics.DrawImage(
                                        bmp, new Rectangle(destRect.X, destRect.Y, remainingWidth - destRect.X, destRect.Height), xSrc, ySrc,
                                        remainingWidth - destRect.X, cySrc, GraphicsUnit.Pixel);
                                }
                            }

                            if (level > 1)
                            {
                                // Move back to the parent glyph, reset cySrc and destRect to non-adjusted item height.
                                xSrc = iStartColumn * cxSrc;
                                cySrc = destRect.Height = myItemHeight;

                                //								int parentRelIndex;
                                //								int dummyLevel;
                                //								IBranch parentBranch;
                                var parentIndex = absIndex;
                                VirtualTreeItemInfo parentInfo;
                                while (--level > 0)
                                {
                                    destRect.Offset(-cxSrc, 0);
                                    parentIndex = myTree.GetParentIndex(parentIndex, nativeColumn);

                                    if (destRect.Left < remainingWidth)
                                    {
                                        parentInfo = myTree.GetItemInfo(parentIndex, nativeColumn, true);
                                        //									if ((parentRelIndex + 1) == parentBranch.ItemCount)
                                        if (parentInfo.LastBranchItem)
                                        {
                                            graphics.FillRectangle(brush, destRect.X, destRect.Y, cxSrc, adjustedItemHeight);
                                                // fill adjusted rectangle so we don't paint over gridlines.
                                        }
                                        else
                                        {
                                            // Ensure indent image doesn't draw outside bounding rectangle for this column.
                                            if (destRect.Right <= remainingWidth)
                                            {
                                                graphics.DrawImage(bmp, destRect, xSrc, ySrc, cxSrc, cySrc, GraphicsUnit.Pixel);
                                            }
                                            else
                                            {
                                                graphics.DrawImage(
                                                    bmp, new Rectangle(destRect.X, destRect.Y, remainingWidth - destRect.X, destRect.Height),
                                                    xSrc, ySrc, remainingWidth - destRect.X, cySrc, GraphicsUnit.Pixel);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                CleanBrush(ref brush, backColor);
            }
        }
 private void DoDrawImageAndOverlays(
     Graphics graphics, VirtualTreeDisplayData tdd, int itemHeight, bool selected, Color controlBackColor)
 {
     var xOffset = (int)graphics.Transform.OffsetX;
     var yOffset = ((int)graphics.Transform.OffsetY) + (itemHeight - myImageHeight) / 2;
     tdd.ImageList.Draw(graphics, xOffset, yOffset, selected ? tdd.SelectedImage : tdd.Image);
     int overlayIndex = tdd.OverlayIndex;
     var overlayIndices = tdd.OverlayIndices;
     if (overlayIndex != -1)
     {
         if (overlayIndices == null)
         {
             // Use the index directly
             tdd.ImageList.Draw(graphics, xOffset, yOffset, overlayIndex);
         }
         else if (overlayIndex != 0)
         {
             // Use the index as a list of bits into the indices array.
             // Do this typed if possible. It returns an IList to be CLS
             // compliant.
             int[] indicesArray;
             IList<int> typedList;
             int indicesCount;
             int curIndex;
             int curBit;
             indicesCount = overlayIndices.Count;
             curBit = 1 << (indicesCount - 1);
             if (null != (indicesArray = overlayIndices as int[]))
             {
                 for (curIndex = indicesCount - 1; curIndex >= 0; --curIndex)
                 {
                     if (0 != (curBit & overlayIndex))
                     {
                         tdd.ImageList.Draw(graphics, xOffset, yOffset, indicesArray[curIndex]);
                     }
                     curBit >>= 1;
                 }
             }
             else if (null != (typedList = overlayIndices as IList<int>))
             {
                 for (curIndex = indicesCount - 1; curIndex >= 0; --curIndex)
                 {
                     if (0 != (curBit & overlayIndex))
                     {
                         tdd.ImageList.Draw(graphics, xOffset, yOffset, typedList[curIndex]);
                     }
                     curBit >>= 1;
                 }
             }
             else
             {
                 for (curIndex = indicesCount - 1; curIndex >= 0; --curIndex)
                 {
                     if (0 != (curBit & overlayIndex))
                     {
                         tdd.ImageList.Draw(graphics, xOffset, yOffset, (int)overlayIndices[curIndex]);
                     }
                     curBit >>= 1;
                 }
             }
         }
     }
     if (tdd.Cut)
     {
         using (Brush brush = new SolidBrush(Color.FromArgb(128, controlBackColor)))
         {
             graphics.FillRectangle(brush, 0, 0, myImageWidth + 1, myImageHeight + 1);
         }
     }
 }
 private static StringAlignment GetLabelTextAlignment(ref VirtualTreeDisplayData tdd)
 {
     // TODO: center alignment
     return 0 != (tdd.State & VirtualTreeDisplayStates.TextAlignFar) ? StringAlignment.Far : StringAlignment.Near;
 }