Esempio n. 1
0
        private string GetMatchesNumberText(DetailCellData cData, bool isSource)
        {
            string text = "";

            if (isSource)
            {
                if (_searchInSource)
                {
                    if (_searchInTags)
                    {
                        text = string.Format(Properties.Resources.gvMatchesNumberTag,
                                             cData.Source.TagMatchesCount);
                    }
                    else
                    {
                        text = string.Format(Properties.Resources.gvMatchesNumber,
                                             (cData.Source.MatchIndexes == null ? 0 : cData.Source.MatchIndexes.Count));
                    }
                }
                else
                {
                    text = Properties.Resources.gvMatchesNumberNA;
                }
            }
            else
            {
                if (_isSearch)
                {
                    if (_searchInTarget && _searchInTags)
                    {
                        text = string.Format(Properties.Resources.gvMatchesNumberTag,
                                             cData.Target.TagMatchesCount);
                    }
                    else if (_searchInTarget)
                    {
                        text = string.Format(Properties.Resources.gvMatchesNumber,
                                             (cData.Target.MatchIndexes == null ? 0 : cData.Target.MatchIndexes.Count));
                    }
                    else
                    {
                        text = Properties.Resources.gvMatchesNumberNA;
                    }
                }
                else
                {
                    text = string.Format(Properties.Resources.gvReplacesNumber,
                                         cData.Target.MatchIndexes.Count);
                    if (cData.Warnings != null && cData.Warnings.Count > 0)
                    {
                        text += string.Format(", " + Properties.Resources.gvWarningsNumber,
                                              cData.WarningsCount);
                    }
                }
            }

            return(text);
        }
Esempio n. 2
0
        protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds,
                                      System.Drawing.Rectangle cellBounds, int rowIndex,
                                      DataGridViewElementStates cellState, object value,
                                      object formattedValue, string errorText,
                                      DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            // general settings
            _fileFilter     = ((ControlColumn)this.OwningColumn).FileFilter;
            _isSearch       = ((ControlColumn)this.OwningColumn).IsSearch;
            _searchInTags   = ((ControlColumn)this.OwningColumn).SearchInTags;
            _searchInSource = ((ControlColumn)this.OwningColumn).SearchInSource;
            _searchInTarget = ((ControlColumn)this.OwningColumn).SearchInTarget;

            bool isCellSelected = (cellState & DataGridViewElementStates.Selected) != 0;

            // paint border
            PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);

            // Discard the space taken up by the borders.
            Rectangle borderWidths = BorderWidths(advancedBorderStyle);
            Rectangle valBounds    = cellBounds;

            valBounds.Offset(borderWidths.X, borderWidths.Y);
            valBounds.Width  -= borderWidths.Right;
            valBounds.Height -= borderWidths.Bottom;

            // paint background
            using (SolidBrush backgroundBrush = new SolidBrush(isCellSelected ? cellStyle.SelectionBackColor : cellStyle.BackColor))
            {
                Rectangle backgroundRect = valBounds;
                backgroundRect.Intersect(clipBounds);
                graphics.FillRectangle(backgroundBrush, backgroundRect);
            }

            // Discard the space taken up by the padding area.
            if (cellStyle.Padding != Padding.Empty)
            {
                valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                valBounds.Width  -= cellStyle.Padding.Horizontal;
                valBounds.Height -= cellStyle.Padding.Vertical;
            }

            // DRAW CONTENT
            if (formattedValue != null && formattedValue is DetailCellData)
            {
                DetailCellData cellData = (DetailCellData)formattedValue;

                int currTopPos = valBounds.Top + _cellMargin;
                if (formattedValue.ToString().Length > 0)
                {
                    // TODO - REMOVE
                    //// draw image
                    //if (valBounds.Width > 0 && valBounds.Height > 0)
                    //{
                    //    Image img = null;
                    //    if (cellData.Type == Properties.Resources.typeWarning)
                    //        img = Properties.Resources.warningIcon;
                    //    else if (cellData.Type == Properties.Resources.typeReplaced)
                    //        img = Properties.Resources.acceptIcon;
                    //    else if (cellData.Type == Properties.Resources.typeTarget)
                    //        img = Properties.Resources.targetIcon;
                    //    else img = Properties.Resources.sourceIcon;

                    //    graphics.DrawImage(img, valBounds.Left + _cellMargin, currTopPos);
                    //}

                    int paddingTop = cellStyle.Font.Height + _cellMargin;

                    // if file in File Filter was not selected
                    // TODO - REMOVE
                    //if (!_fileFilter)
                    //{
                    //    // draw label -> FILE NAME
                    //    if (valBounds.Width > 0 && valBounds.Height > 0)
                    //    {
                    //        Font cellFont = new Font(cellStyle.Font, FontStyle.Bold);
                    //        Point glyphLocation = new Point(valBounds.Left + _cellMargin, currTopPos);
                    //        Size glyphSz = new System.Drawing.Size(valBounds.Width - _cellMargin * 2, _textBoxHeight);
                    //        Rectangle glyphRect = new Rectangle(glyphLocation, glyphSz);
                    //        TextRenderer.DrawText(graphics, cellData.FileName, cellFont, glyphRect,
                    //                            (isCellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor),
                    //                            (isCellSelected ? cellStyle.SelectionBackColor : cellStyle.BackColor),
                    //                            TextFormatFlags.Left);
                    //    }

                    //    // Discard the space
                    //    currTopPos += paddingTop;
                    //    valBounds.Height -= paddingTop;
                    //}
                    valBounds.Height -= _cellMargin;

                    // SIDE-BY-SIDE
                    int panelWidth = valBounds.Width / 2;
                    int xMiddlePos = valBounds.Left + panelWidth;
                    if (valBounds.Width > 0 && valBounds.Height > 0)
                    {
                        // draw line-separator
                        using (Pen linePen = new Pen(isCellSelected ? _selectedLineColor : _lineColor))
                        {
                            Point topPoint    = new Point(xMiddlePos, currTopPos);
                            Point bottomPoint = new Point(xMiddlePos, currTopPos + valBounds.Height - _cellMargin);
                            graphics.DrawLine(linePen, topPoint, bottomPoint);
                        }

                        // draw label -> MATCHES NUMBER
                        // 1 - SOURCE
                        // image
                        var img = Properties.Resources.sourceIcon;
                        graphics.DrawImage(img, valBounds.Left + _cellMargin, currTopPos - 1);

                        // label
                        string labelText = GetMatchesNumberText(cellData, true);

                        Font cellFont = new Font(cellStyle.Font, FontStyle.Bold);

                        Point     glyphLocation = new Point(valBounds.Left + _textLeftMargin, currTopPos);
                        Size      glyphSz       = new System.Drawing.Size(panelWidth - _cellMargin - _textLeftMargin, _textBoxHeight);
                        Rectangle glyphRect     = new Rectangle(glyphLocation, glyphSz);
                        TextRenderer.DrawText(graphics, labelText,
                                              cellFont, glyphRect,
                                              (isCellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor),
                                              (isCellSelected ? cellStyle.SelectionBackColor : cellStyle.BackColor),
                                              TextFormatFlags.Left);

                        // 2 - TARGET
                        // image
                        if (_isSearch)
                        {
                            img = Properties.Resources.targetIcon;
                        }
                        else if (cellData.Warnings != null && cellData.Warnings.Count > 0)
                        {
                            img = Properties.Resources.warningIcon;
                        }
                        else
                        {
                            img = Properties.Resources.acceptIcon;
                        }

                        graphics.DrawImage(img, xMiddlePos + _cellMargin, currTopPos - 1);

                        // label
                        labelText = GetMatchesNumberText(cellData, false);

                        glyphLocation = new Point(xMiddlePos + _textLeftMargin, currTopPos);
                        glyphSz       = new System.Drawing.Size(panelWidth - _cellMargin - _textLeftMargin, _textBoxHeight);
                        glyphRect     = new Rectangle(glyphLocation, glyphSz);
                        TextRenderer.DrawText(graphics, labelText,
                                              cellFont, glyphRect,
                                              (isCellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor),
                                              (isCellSelected ? cellStyle.SelectionBackColor : cellStyle.BackColor),
                                              TextFormatFlags.Left);

                        // Discard the space
                        currTopPos       += paddingTop;
                        valBounds.Height -= paddingTop;
                        // valBounds.Height -= _cellMargin; - > to leave more space for text
                    }

                    // draw richtextbox -> TEXT
                    if (valBounds.Width > 0 && valBounds.Height > 0)
                    {
                        // set richtextbox with text
                        RichTextBox rtbControl = new RichTextBox();
                        rtbControl.Size = new Size(panelWidth - _textLeftMargin - _cellMargin, valBounds.Height);

                        // paint image from richtextbox
                        Size imgSize = new Size(rtbControl.Width - 1, rtbControl.Height - 1);

                        // 1 - SOURCE
                        if (cellData.Source.Text.Length > 0)
                        {
                            // create image
                            var img = PrintCellText(ref rtbControl, imgSize, cellStyle, cellData.Source, isCellSelected);
                            // draw image in cell
                            graphics.DrawImage(img, valBounds.Left + _textLeftMargin + _rtbCellMargin, currTopPos);
                        }

                        rtbControl.Clear();

                        // 2 - TARGET
                        if (cellData.Target.Text.Length > 0)
                        {
                            // create image
                            var img = PrintCellText(ref rtbControl, imgSize, cellStyle, cellData.Target, isCellSelected);
                            // draw image in cell
                            graphics.DrawImage(img, xMiddlePos + _textLeftMargin + _rtbCellMargin, currTopPos);
                        }
                    }

                    // TODO - REMOVE
                    //// draw label -> MATCHES NUMBER
                    //if (valBounds.Width > 0 && valBounds.Height > 0)
                    //{
                    //    string labelText = "";
                    //    if (cellData.IsTagMatch)
                    //        labelText = string.Format(Properties.Resources.gvMatchesNumberTag,
                    //         cellData.TagMatchesCount);
                    //    else labelText = string.Format(Properties.Resources.gvMatchesNumber,
                    //         cellData.MatchStart.Count);
                    //    Font cellFont = new Font(cellStyle.Font, FontStyle.Bold);

                    //    Point glyphLocation = new Point(valBounds.Left + _textLeftMargin, currTopPos);
                    //    Size glyphSz = new System.Drawing.Size(valBounds.Width - _cellMargin - _textLeftMargin, _textBoxHeight);
                    //    Rectangle glyphRect = new Rectangle(glyphLocation, glyphSz);
                    //    TextRenderer.DrawText(graphics, labelText,
                    //                        cellFont, glyphRect,
                    //                        (isCellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor),
                    //                        (isCellSelected ? cellStyle.SelectionBackColor : cellStyle.BackColor),
                    //                        TextFormatFlags.Left);
                    //}

                    //// Discard the space
                    //currTopPos += paddingTop;
                    //valBounds.Height -= paddingTop;
                    //valBounds.Height -= _cellMargin;

                    //// draw label -> WARNING
                    //if (cellData.Type == Properties.Resources.typeWarning && cellData.WarningText.Length > 0)
                    //{
                    //    if (valBounds.Width > 0 && valBounds.Height > 0)
                    //    {
                    //        Point glyphLocation = new Point(valBounds.Left + _textLeftMargin, currTopPos);
                    //        Size glyphSz = new System.Drawing.Size(valBounds.Width - _cellMargin - _textLeftMargin, _textBoxHeight);
                    //        Rectangle glyphRect = new Rectangle(glyphLocation, glyphSz);
                    //        TextRenderer.DrawText(graphics, cellData.WarningText,
                    //                            cellStyle.Font, glyphRect,
                    //                            (isCellSelected ? cellStyle.SelectionForeColor : Color.Red),
                    //                            (isCellSelected ? cellStyle.SelectionBackColor : cellStyle.BackColor),
                    //                            TextFormatFlags.Left);
                    //    }

                    //    // Discard the space
                    //    currTopPos += paddingTop;
                    //    valBounds.Height -= paddingTop;
                    //    //valBounds.Height -= _cellMargin; < -- better without it
                    //}

                    //// draw richtextbox -> TEXT
                    //if (valBounds.Width > 0 && valBounds.Height > 0)
                    //{
                    //    Image img = null;

                    //    // set richtextbox with text
                    //    RichTextBox rtbControl = new RichTextBox();
                    //    rtbControl.Size = new Size(valBounds.Width - _textLeftMargin - _cellMargin, valBounds.Height);

                    //    // paint image from richtextbox
                    //    Size imgSize = new Size(rtbControl.Width - 1, rtbControl.Height - 1);
                    //    if (isCellSelected)
                    //    {
                    //        // Selected cell state
                    //        rtbControl.BackColor = cellStyle.SelectionBackColor;
                    //        rtbControl.ForeColor = cellStyle.SelectionForeColor;

                    //        SetRichTextBoxText(rtbControl, cellData.Source, isCellSelected, imgSize.Width, imgSize.Height);

                    //        // Print image
                    //        img = RTBControlPrinter.Print(rtbControl, imgSize.Width, imgSize.Height);

                    //        // Restore RichTextBox
                    //        rtbControl.BackColor = cellStyle.SelectionBackColor;
                    //        rtbControl.ForeColor = cellStyle.ForeColor;
                    //    }
                    //    else
                    //    {
                    //        SetRichTextBoxText(rtbControl, cellData.Source, isCellSelected, imgSize.Width, imgSize.Height);

                    //        img = RTBControlPrinter.Print(rtbControl, imgSize.Width, imgSize.Height);
                    //    }

                    //    // draw image in cell
                    //    graphics.DrawImage(img, valBounds.Left + _textLeftMargin + _rtbCellMargin, currTopPos);
                    //}
                }
            }
        }