|
NIREP
|
00001 00002 #include "GridCellChoiceRenderer.h" 00003 00004 // For compilers that support precompilation, includes "wx/wx.h". 00005 #include "wx/wxprec.h" 00006 00007 #ifdef __BORLANDC__ 00008 #pragma hdrstop 00009 #endif 00010 00011 #ifndef WX_PRECOMP 00012 #include "wx/wx.h" 00013 #endif 00014 00015 void wxGridCellChoiceRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, 00016 const wxRect& rectCell, int row, int col, bool isSelected) 00017 { 00018 wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected); 00019 // first calculate button size 00020 // don't draw outside the cell 00021 int nButtonWidth = 17; 00022 if (rectCell.height < 2) return; 00023 wxRect rectButton; 00024 rectButton.x = rectCell.x + rectCell.width - nButtonWidth; 00025 rectButton.y = rectCell.y + 1; 00026 int cell_rows, cell_cols; 00027 attr.GetSize(&cell_rows, &cell_cols); 00028 rectButton.width = nButtonWidth; 00029 if (cell_rows == 1) 00030 rectButton.height = rectCell.height-2; 00031 else 00032 rectButton.height = nButtonWidth; 00033 00034 SetTextColoursAndFont(grid, attr, dc, isSelected); 00035 int hAlign, vAlign; 00036 attr.GetAlignment(&hAlign, &vAlign); 00037 // leave room for button 00038 wxRect rect = rectCell; 00039 rect.SetWidth(rectCell.GetWidth() - rectButton.GetWidth()-2); 00040 rect.Inflate(-1); 00041 grid.DrawTextRectangle(dc, grid.GetCellValue(row, col), rect, hAlign, vAlign); 00042 00043 // don't bother drawing if the cell is too small 00044 if (rectButton.height < 4 || rectButton.width < 4) return; 00045 // draw 3-d button 00046 wxColour colourBackGround = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); 00047 dc.SetBrush(wxBrush(colourBackGround, wxSOLID)); 00048 dc.SetPen(wxPen(colourBackGround, 1, wxSOLID)); 00049 dc.DrawRectangle(rectButton); 00050 dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), 1, wxSOLID)); 00051 dc.DrawLine(rectButton.GetLeft(), rectButton.GetBottom(), 00052 rectButton.GetRight(), rectButton.GetBottom()); 00053 dc.DrawLine(rectButton.GetRight(), rectButton.GetBottom(), 00054 rectButton.GetRight(), rectButton.GetTop()-1); 00055 dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW), 00056 1, wxSOLID)); 00057 dc.DrawLine(rectButton.GetLeft()+1, rectButton.GetBottom()-1, 00058 rectButton.GetRight()-1, rectButton.GetBottom()-1); 00059 dc.DrawLine(rectButton.GetRight()-1, rectButton.GetBottom()-1, 00060 rectButton.GetRight()-1, rectButton.GetTop()); 00061 dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT), 00062 1, wxSOLID)); 00063 dc.DrawLine(rectButton.GetRight()-2, rectButton.GetTop()+1, 00064 rectButton.GetLeft()+1, rectButton.GetTop()+1); 00065 dc.DrawLine(rectButton.GetLeft()+1, rectButton.GetTop()+1, 00066 rectButton.GetLeft()+1, rectButton.GetBottom()-1); 00067 // Draw little triangle 00068 int nTriWidth = 7; 00069 int nTriHeight = 4; 00070 wxPoint point[3]; 00071 point[0] = wxPoint(rectButton.GetLeft() + (rectButton.GetWidth()-nTriWidth)/2, 00072 rectButton.GetTop()+(rectButton.GetHeight()-nTriHeight)/2); 00073 point[1] = wxPoint(point[0].x+nTriWidth-1, point[0].y); 00074 point[2] = wxPoint(point[0].x+3, point[0].y+nTriHeight-1); 00075 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), wxSOLID)); 00076 dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), 1, wxSOLID)); 00077 dc.DrawPolygon(3, point); 00078 if (m_border == wxLAYOUT_TOP) 00079 { 00080 dc.SetPen(wxPen(*wxBLACK, 1, wxDOT)); 00081 dc.DrawLine(rectCell.GetRight(), rectCell.GetTop(), 00082 rectCell.GetLeft(), rectCell.GetTop()); 00083 } 00084 } 00085