KissCount/src/view/grid/wxGridCellTreeButtonRenderer.cpp
2011-02-13 19:30:12 +01:00

86 lines
2.5 KiB
C++

/*
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 <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellTreeButtonRenderer.h"
wxGridCellTreeButtonRenderer::wxGridCellTreeButtonRenderer(bool collapsed) : _collapsed(collapsed)
{
}
wxGridCellRenderer* wxGridCellTreeButtonRenderer::Clone () const
{
return new wxGridCellTreeButtonRenderer(_collapsed);
}
bool wxGridCellTreeButtonRenderer::IsCollapsed()
{
return _collapsed;
}
void wxGridCellTreeButtonRenderer::Invert()
{
_collapsed = !_collapsed;
}
void wxGridCellTreeButtonRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &_rect, int row, int col, bool isSelected)
{
wxRect rect = _rect;
wxBrush originalBrush = dc.GetBrush();
wxPen originalPen = dc.GetPen();
dc.SetPen(wxPen(grid.GetCellBackgroundColour(row, col)));
dc.SetBrush(wxBrush(grid.GetCellBackgroundColour(row, col)));
dc.DrawRectangle(rect);
rect.x += 4 ;
rect.y += 4 ;
rect.width -= 8 ;
rect.height -= 8 ;
if (rect.width > rect.height)
rect.width = rect.height;
else if (rect.height > rect.width)
rect.height = rect.width;
dc.SetPen(wxPen(*wxBLACK));
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.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);
rect.x += 2 ;
rect.y += 2 ;
rect.width -= 4 ;
rect.height -= 4 ;
dc.DrawLine(rect.x+1, rect.y + rect.height/2, rect.x + rect.width + 1, rect.y + rect.height/2);
if (!_collapsed)
dc.DrawLine(rect.x + rect.width/2 + 1, rect.y, rect.x + rect.width/2 + 1, rect.y + rect.height);
}
wxSize wxGridCellTreeButtonRenderer::GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col)
{
return wxSize(8, 8);
}