/** * @brief Returns 0-based index of the first free row in the grid */ int firstFreeRow(const wxGrid &grid) { using cit = boost::counting_iterator<int>; const auto size = grid.GetNumberRows(); const auto row = find_if(cit(0), cit(size), [&grid](int x) { return "" == grid.GetCellValue(x, 0) && "" == grid.GetCellValue(x, 1); }); return *row; }
void MyFrame::OnOpen(wxCommandEvent & WXUNUSED(event)) { wxFileDialog dialog(this, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString, wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (dialog.ShowModal() == wxID_OK) { wxString filename(dialog.GetPath()); wxTextFile text_file(filename); if (!text_file.Open(wxConvUTF8)) { return; } grid->EnableEditing(false); if (text_file.GetLineCount() > grid->GetNumberRows()) { grid->AppendRows(text_file.GetLineCount() - grid->GetNumberRows()); } else if (text_file.GetLineCount() < grid->GetNumberRows()) { grid->DeleteRows(text_file.GetLineCount(), grid->GetNumberRows() - text_file.GetLineCount()); } grid->ClearGrid(); for (int row = 0; row < text_file.GetLineCount(); ++row) { wxStringTokenizer tokenizer(text_file[row], L","); for (int col = 0; tokenizer.HasMoreTokens() && col < grid->GetNumberCols(); ++col) { wxString token = tokenizer.GetNextToken(); grid->SetCellValue(row, col, token); } } grid->AutoSize(); text->Clear(); lines.clear(); for (int row = 0; row < text_file.GetLineCount(); ++row) { lines.push_back(text_file[row]); } text_file.Close(); topsizer->Layout(); SetStatusText(wxFileName(filename).GetFullName()); } }
void PopulateWXGridFromDataGrid(const CDataGrid& rSrcDataGrid, wxGrid& rDestWXGrid) { // Remove old rows, and insert new ones as appropriate rDestWXGrid.DeleteCols(0, rDestWXGrid.GetNumberCols()); rDestWXGrid.DeleteRows(0, rDestWXGrid.GetNumberRows()); rDestWXGrid.AppendCols(rSrcDataGrid.GetNumberCols()); rDestWXGrid.AppendRows(rSrcDataGrid.GetNumberRows()); rDestWXGrid.SetDefaultCellTextColour(wxColour(0, 0, 0)); rDestWXGrid.SetLabelTextColour(wxColour(0, 0, 0)); rDestWXGrid.SetRowLabelSize(0); rDestWXGrid.EnableDragRowSize(false); // Top Headings for (int iCol = 0; iCol < rSrcDataGrid.GetNumberCols(); iCol++) { rDestWXGrid.SetColLabelValue(iCol, wxString(rSrcDataGrid.GetTopHeadingText(iCol), wxConvUTF8)); } for (int iRow = 0; iRow < rSrcDataGrid.GetNumberRows(); iRow++) { // Side Heading rDestWXGrid.SetRowLabelValue(iRow, wxString(rSrcDataGrid.GetSideHeadingText(iRow), wxConvUTF8)); // Data Row for (int iCol = 0; iCol < rSrcDataGrid.GetNumberCols(); iCol++) { rDestWXGrid.SetCellValue(iRow, iCol, wxString(rSrcDataGrid.GetCellText(iRow, iCol), wxConvUTF8)); rDestWXGrid.SetReadOnly(iRow, iCol, true); wxFont vCellFont = rDestWXGrid.GetCellFont(iRow, iCol); if (rSrcDataGrid.IsCellBold(iRow, iCol)) vCellFont.SetWeight(wxFONTWEIGHT_BOLD); if (rSrcDataGrid.IsCellUnderlined(iRow, iCol)) vCellFont.SetUnderlined(true); rDestWXGrid.SetCellFont(iRow, iCol, vCellFont); } } rDestWXGrid.AutoSizeColumns(false); rDestWXGrid.AutoSizeRows(false); }
//------------------------------------------------------------------------------ // custom renderer //------------------------------------------------------------------------------ void CustomRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected) { dc.SetPen(wxPen(attr.GetBackgroundColour(), 1)); dc.SetBrush(wxBrush( attr.GetBackgroundColour(), wxBRUSHSTYLE_SOLID )); dc.DrawRectangle( rect ); if( m_IsDigit || m_dDir == GRIB_NOTDEF ) { //digital format wxString text(wxEmptyString); if( m_dDir != GRIB_NOTDEF ) text.Printf(_T("%03d\u00B0"), (int)m_dDir); dc.DrawLabel(text, rect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL); } else { //graphical format double si = sin( (m_dDir - 90) * M_PI / 180. ); double co = cos( (m_dDir - 90) * M_PI / 180. ); int i = rect.GetTopLeft().x + (rect.GetWidth() / 2); int j = rect.GetTopLeft().y + (rect.GetHeight() / 2); int arrowSize = rect.GetHeight() - 3; int dec = -arrowSize / 2; #if wxUSE_GRAPHICS_CONTEXT wxGraphicsContext *gdc; wxClientDC *cdc = new wxClientDC(wxDynamicCast( &grid, wxWindow)); cdc = wxDynamicCast(&dc, wxClientDC); if( cdc ) { gdc = wxGraphicsContext::Create(*cdc); #ifdef __WXGTK__ /*platforms don't manage the same way the gdc origin for linux, we have to re-compute the good one. To DO : verify it works on all other plateforms (done for MSW*/ bool vis = false; int r = 0; for( int c = 0; c < grid.GetNumberCols(); c++){ for(r = 0; r < grid.GetNumberRows(); r++) { if(grid.IsVisible(r, c)){ //find the first row/col vis = true; i -= (c * grid.GetColSize(0)); j -= (r * grid.GetRowHeight(0)); break; } } if(vis) break; } #endif gdc->SetPen(wxPen(attr.GetTextColour(), 3)); gdc->SetBrush(wxBrush( attr.GetBackgroundColour(), wxBRUSHSTYLE_SOLID )); double ii, jj, kk, ll; GetArrowsPoints( si, co, i, j, dec, 0, dec + arrowSize, 0, ii, jj, kk, ll ); gdc->StrokeLine( ii, jj, kk, ll ); GetArrowsPoints( si, co, i, j, dec - 3, 0, dec + 5, 3, ii, jj, kk, ll ); gdc->StrokeLine( ii, jj, kk, ll ); GetArrowsPoints( si, co, i, j, dec - 3, 0, dec + 5, -3, ii, jj, kk, ll ); gdc->StrokeLine( ii, jj, kk, ll ); delete gdc; } else #endif { dc.SetPen(wxPen(attr.GetTextColour(), 3)); double ii, jj, kk, ll; GetArrowsPoints( si, co, i, j, dec, 0, dec + arrowSize, 0, ii, jj, kk, ll ); dc.DrawLine( (int)ii, (int)jj, (int)kk, (int)ll ); GetArrowsPoints( si, co, i, j, dec - 3, 0, dec + 5, 3, ii, jj, kk, ll ); dc.DrawLine( (int)ii, (int)jj, (int)kk, (int)ll ); GetArrowsPoints( si, co, i, j, dec - 3, 0, dec + 5, -3, ii, jj, kk, ll ); dc.DrawLine( (int)ii, (int)jj, (int)kk, (int)ll ); } } }