示例#1
0
void wxGridCellStringRenderer::Draw(wxGrid& grid,
                                    wxGridCellAttr& attr,
                                    wxDC& dc,
                                    const wxRect& rectCell,
                                    int row, int col,
                                    bool isSelected)
{
    wxRect rect = rectCell;
    rect.Inflate(-1);

    // erase only this cells background, overflow cells should have been erased
    wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);

    int hAlign, vAlign;
    attr.GetAlignment(&hAlign, &vAlign);

    int overflowCols = 0;

    if (attr.GetOverflow())
    {
        int cols = grid.GetNumberCols();
        int best_width = GetBestSize(grid,attr,dc,row,col).GetWidth();
        int cell_rows, cell_cols;
        attr.GetSize( &cell_rows, &cell_cols ); // shouldn't get here if <= 0
        if ((best_width > rectCell.width) && (col < cols) && grid.GetTable())
        {
            int i, c_cols, c_rows;
            for (i = col+cell_cols; i < cols; i++)
            {
                bool is_empty = true;
                for (int j=row; j < row + cell_rows; j++)
                {
                    // check w/ anchor cell for multicell block
                    grid.GetCellSize(j, i, &c_rows, &c_cols);
                    if (c_rows > 0)
                        c_rows = 0;
                    if (!grid.GetTable()->IsEmptyCell(j + c_rows, i))
                    {
                        is_empty = false;
                        break;
                    }
                }

                if (is_empty)
                {
                    rect.width += grid.GetColSize(i);
                }
                else
                {
                    i--;
                    break;
                }

                if (rect.width >= best_width)
                    break;
            }

            overflowCols = i - col - cell_cols + 1;
            if (overflowCols >= cols)
                overflowCols = cols - 1;
        }

        if (overflowCols > 0) // redraw overflow cells w/ proper hilight
        {
            hAlign = wxALIGN_LEFT; // if oveflowed then it's left aligned
            wxRect clip = rect;
            clip.x += rectCell.width;
            // draw each overflow cell individually
            int col_end = col + cell_cols + overflowCols;
            if (col_end >= grid.GetNumberCols())
                col_end = grid.GetNumberCols() - 1;
            for (int i = col + cell_cols; i <= col_end; i++)
            {
                clip.width = grid.GetColSize(i) - 1;
                dc.DestroyClippingRegion();
                dc.SetClippingRegion(clip);

                SetTextColoursAndFont(grid, attr, dc,
                        grid.IsInSelection(row,i));

                grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
                        rect, hAlign, vAlign);
                clip.x += grid.GetColSize(i) - 1;
            }

            rect = rectCell;
            rect.Inflate(-1);
            rect.width++;
            dc.DestroyClippingRegion();
        }
    }

    // now we only have to draw the text
    SetTextColoursAndFont(grid, attr, dc, isSelected);

    grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
                           rect, hAlign, vAlign);
}
void wxGridCellChoiceRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
                                    const wxRect& rectCell, int row, int col, bool isSelected)
{
    wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
    // first calculate button size
    // don't draw outside the cell
    int nButtonWidth = 17;
    if (rectCell.height < 2) return;
    wxRect rectButton;
    rectButton.x = rectCell.x + rectCell.width - nButtonWidth;
    rectButton.y = rectCell.y + 1;
    int cell_rows, cell_cols;
    attr.GetSize(&cell_rows, &cell_cols);
    rectButton.width = nButtonWidth;
    if (cell_rows == 1)
        rectButton.height = rectCell.height-2;
    else
        rectButton.height = nButtonWidth;

    SetTextColoursAndFont(grid, attr, dc, isSelected);
    int hAlign, vAlign;
    attr.GetAlignment(&hAlign, &vAlign);
    // leave room for button
    wxRect rect = rectCell;
    rect.SetWidth(rectCell.GetWidth() - rectButton.GetWidth()-2);
    rect.Inflate(-1);
    grid.DrawTextRectangle(dc, grid.GetCellValue(row, col), rect, hAlign, vAlign);

    // don't bother drawing if the cell is too small
    if (rectButton.height < 4 || rectButton.width < 4) return;
    // draw 3-d button
    wxColour colourBackGround = wxColour(COLORBASE);
    dc.SetBrush(wxBrush(colourBackGround, wxSOLID));
    dc.SetPen(wxPen(colourBackGround, 1, wxSOLID));
    dc.DrawRectangle(rectButton);
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), 1, wxSOLID));
    dc.DrawLine(rectButton.GetLeft(), rectButton.GetBottom(),
                rectButton.GetRight(), rectButton.GetBottom());
    dc.DrawLine(rectButton.GetRight(), rectButton.GetBottom(),
                rectButton.GetRight(), rectButton.GetTop()-1);
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW),
                    1, wxSOLID));
    dc.DrawLine(rectButton.GetLeft()+1, rectButton.GetBottom()-1,
                rectButton.GetRight()-1, rectButton.GetBottom()-1);
    dc.DrawLine(rectButton.GetRight()-1, rectButton.GetBottom()-1,
                rectButton.GetRight()-1, rectButton.GetTop());
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT),
                    1, wxSOLID));
    dc.DrawLine(rectButton.GetRight()-2, rectButton.GetTop()+1,
                rectButton.GetLeft()+1, rectButton.GetTop()+1);
    dc.DrawLine(rectButton.GetLeft()+1, rectButton.GetTop()+1,
                rectButton.GetLeft()+1, rectButton.GetBottom()-1);
    // Draw little triangle
    int nTriWidth = 7;
    int nTriHeight = 4;
    wxPoint point[3];
    point[0] = wxPoint(rectButton.GetLeft() + (rectButton.GetWidth()-nTriWidth)/2,
                       rectButton.GetTop()+(rectButton.GetHeight()-nTriHeight)/2);
    point[1] = wxPoint(point[0].x+nTriWidth-1, point[0].y);
    point[2] = wxPoint(point[0].x+3, point[0].y+nTriHeight-1);
    dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), wxSOLID));
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), 1, wxSOLID));
    dc.DrawPolygon(3, point);
    if (m_border == wxLAYOUT_TOP)
    {
        dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
        dc.DrawLine(rectCell.GetRight(), rectCell.GetTop(),
                    rectCell.GetLeft(), rectCell.GetTop());
    }
}