/* Copyright 2010-2011 Grégory Soutadé This file is part of KissCount. KissCount is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. KissCount is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with KissCount. If not, see . */ #include "wxGridCellButtonRenderer.h" wxGridCellButtonRenderer::wxGridCellButtonRenderer(const wxString& text) : _text(text) { } wxGridCellRenderer* wxGridCellButtonRenderer::Clone () const { return new wxGridCellButtonRenderer(_text); } void wxGridCellButtonRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &_rect, int row, int col, bool isSelected) { wxRect rect = _rect; wxCoord w, h, descent, external_leading; wxBrush originalBrush = dc.GetBrush(); wxPen originalPen = dc.GetPen(); dc.SetPen(wxPen(*wxLIGHT_GREY)); dc.SetBrush(wxBrush(grid.GetCellBackgroundColour(row, col))); dc.DrawRectangle(rect); rect.x += 2 ; rect.y += 2 ; rect.width -= 6 ; rect.height -= 6 ; dc.SetPen(wxPen(*wxWHITE)); dc.DrawLine(rect.x, rect.y, rect.x + rect.width, rect.y); dc.DrawLine(rect.x, rect.y, rect.x, rect.y + rect.height); dc.SetPen(wxPen(*wxBLACK)); dc.DrawLine(rect.x, rect.y + rect.height, rect.x + rect.width + 1, rect.y + rect.height); dc.DrawLine(rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + rect.height); dc.SetPen(wxPen(wxColor(0x80, 0x80, 0x80))); dc.DrawLine(rect.x + 1, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1); dc.DrawLine(rect.x + rect.width - 1, rect.y + 1, rect.x + rect.width - 1, rect.y + rect.height); rect.x += 1 ; rect.y += 1 ; rect.width -= 2 ; rect.height -= 2 ; dc.SetPen(wxPen(*wxLIGHT_GREY)); dc.SetBrush(wxBrush(*wxLIGHT_GREY)); dc.DrawRectangle(rect); dc.GetTextExtent(_text, &w, &h, &descent, &external_leading); if (w < rect.width) rect.x += (rect.width - w) / 2; if (h < rect.height) rect.y += (rect.height - h) / 2; rect.y -= (external_leading + descent); dc.SetTextForeground(*wxBLACK); // dc.SetTextBackground(wxColor(128, 128, 128, 255)); dc.SetTextBackground(*wxLIGHT_GREY); dc.DrawText(_text, rect.x, rect.y); dc.SetBrush(originalBrush); dc.SetPen(originalPen); } wxSize wxGridCellButtonRenderer::GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) { wxCoord w, h; dc.GetTextExtent(_text, &w, &h); return wxSize(w+14, h+14); // (2 + 2 + 3) * 2 }