int wxDDGrid::StretchIt() { int new_width = GetClientSize().GetWidth() - GetRowLabelSize() - 10; int fixedWidth = 0, numStretches = 0, numStretched = 0; for( int i = 0; i < GetNumberCols(); ++i ) { if( sf[i] == 0 ) fixedWidth += GetColSize(i); else if( sf[i] < 0 ) { AutoSizeColumn(i, false); fixedWidth += GetColSize(i); } else { numStretches += sf[i]; numStretched += 1; } } // Now either we have space for normal layout or resort to wxGrid default behaviour if( numStretched && ((fixedWidth + numStretched * 10) < new_width) ) { int stretchSpace = (new_width - fixedWidth) / numStretches; //BeginBatch(); int i, max = GetNumberCols(); for(i = 0; i < max; ++i ) if( sf[i] > 0 ) SetColSize(i, stretchSpace * sf[i]); //EndBatch(); return 1; } return 0; }
//--------------------------------------------------------- bool CVIEW_Table_Control::Update_Table(void) { if( GetBatchCount() > 0 ) { return( false ); } BeginBatch(); //----------------------------------------------------- int Difference = (m_pTable->Get_Field_Count() - m_Field_Offset) - GetNumberCols(); if( Difference > 0 ) { AppendCols(Difference); } else if( (Difference = -Difference < GetNumberCols() ? -Difference : GetNumberCols()) > 0 ) { // here is (or was!?) a memory leak - solution: use own wxGridTableBase derived grid table class DeleteCols(0, Difference); } //----------------------------------------------------- for(int iCol=0, iField=m_Field_Offset; iField<m_pTable->Get_Field_Count(); iCol++, iField++) { SetColLabelValue(iCol, m_pTable->Get_Field_Name(iField)); switch( m_pTable->Get_Field_Type(iField) ) { default: case SG_DATATYPE_Byte: case SG_DATATYPE_Char: case SG_DATATYPE_String: case SG_DATATYPE_Date: case SG_DATATYPE_Binary: SetColFormatCustom(iCol, wxGRID_VALUE_STRING); break; case SG_DATATYPE_Bit: case SG_DATATYPE_Word: case SG_DATATYPE_Short: case SG_DATATYPE_DWord: case SG_DATATYPE_Int: case SG_DATATYPE_ULong: case SG_DATATYPE_Long: case SG_DATATYPE_Color: SetColFormatNumber(iCol); break; case SG_DATATYPE_Float: case SG_DATATYPE_Double: SetColFormatFloat(iCol); break; } } //----------------------------------------------------- EndBatch(); return( _Set_Records() ); }
void CDDBaseGrid::SelectRow(long row) { if (row >= 0 && row < GetNumberRows() && GetNumberCols() > 0) { SetMultiSelectMode(TRUE); GotoRow(row); SelectRange(0, row, (GetNumberCols() - 1), row); } }
void ctlResultGrid::fillGrid( PGresult * result ) { int rowCount = PQntuples( result ); int colCount = PQnfields( result ); // If this PGresult represents a non-query command // (like an INSERT), there won't be any columns in // the result set - just return if( colCount == 0 ) return; // Disable repaints to we don't flicker too much BeginBatch(); // Clear out the old results (if any) and resize // grid to match the result set if( GetNumberRows()) DeleteRows( 0, GetNumberRows()); if( GetNumberCols()) DeleteCols( 0, GetNumberCols()); AppendRows( rowCount ); AppendCols( colCount ); EnableEditing( false ); // Copy the column names from the result set into the column headers for( int col = 0; col < colCount; ++col ) SetColLabelValue( col, wxString( PQfname( result, col ), wxConvUTF8 )); // Now copy each value from the result set into the grid for( int row = 0; row < rowCount; ++row ) { for( int col = 0; col < colCount; ++col ) { if( PQgetisnull( result, row, col )) SetCellValue( row, col, wxT( "" )); else SetCellValue( row, col, wxString( PQgetvalue( result, row, col ), wxConvUTF8 )); } } // Resize each column to fit its content AutoSizeColumns( false ); // Enable repaints EndBatch(); }
bool CGridLabThresholds::_SetData( CLabThresholds *pData, const wxString &sKitName, const wxChar * const *psLabels) { m_pData = pData; bool bOK = CGridLocusColumns::SetupKit( this,sKitName,true,m_bILS,true,true); // set row labels if(bOK) { const wxChar * const *pRowLabel; int nColCount = GetNumberCols(); int j = 1; for(pRowLabel = psLabels; (*pRowLabel) != NULL; pRowLabel++) { SetRowLabelValue(j++,*pRowLabel); } // put junk in row 1 to set cell width _CreateGrid(m_nRows,nColCount); for(j = 0; j < nColCount ; j++) { SetCellValue(1,j,"0000000000"); // set cell width } nwxGrid::UpdateLabelSizes(this); AutoSize(); } return bOK; }
void CGridLabThresholds::_SetColCount(int nCols) { int nOldCount = m_bCreated ? GetNumberCols() : 0; int nCol; int nRow; _CreateGrid(m_nRows,nCols); if(nOldCount <= 1) { nOldCount = 0; } else { // ummerge all cells in first row for(nCol = 0; nCol < nOldCount; nCol++) { SetCellSize(0,nCol,1,1); } } // set Renderer and Editor for(nRow = 1; nRow < m_nRows; nRow++) { for(nCol = nOldCount; nCol < nCols; nCol++) { SetCellEditor(nRow,nCol,new wxGridCellFloatEditor(-1,4)); SetReadOnly(nRow,nCol,m_bReadOnly); } } }
void CLayerTypeGrid::OnDClicked(int col,long row, RECT *rect,POINT *point,BOOL processed) { int lastColIndx = GetNumberCols() - 1; CString cellText(QuickGetText(lastColIndx, row)); int layerType = atoi(cellText); // Edit color if a layerType row (not a group name row) // and double click was not in the layer type column. if (layerType > -1 && col > 0) { CUGCell cell; GetCell(col, row, &cell); COLORREF color = cell.GetBackColor(); // current color CPersistantColorDialog dialog(color); if (dialog.DoModal() == IDOK) { color = dialog.GetColor(); cell.SetBackColor(color); SetCell(col, row, &cell); RedrawAll(); } } }
void CGridAlleleBase::CheckRowCount() { wxString s; int nRows = GetNumberRows(); int nCols = GetNumberCols(); int nStart = nRows - 2; int nCol; int nRow; if(nStart < 0) { nStart = 0; } for(nRow = nStart; nRow < nRows; nRow++) { for(nCol = 0; nCol < nCols; nCol++) { s = GetCellValue(nRow,nCol); nwxString::Trim(&s); if(s.Len()) { nwxGrid::SetRowCount(nRows + 4); nCol = nCols; // loop exit nRow = nRows; } } } }
bool CGridLabThresholdsSample::SetData(CLabThresholds *pData, const wxString &sKitName) { const wxChar * const psLabels[] = { FRACTION_MAX_PEAK, PULLUP_FRACTIONAL_FILTER, STUTTER_THRESHOLD, PLUS_STUTTER_THRESHOLD, ADENYLATION_THRESHOLD, wxS("Min. heterozygote balance (0 - 1.0) "), wxS("Min. homozygote threshold (RFU) "), NULL }; bool bOK = _SetData(pData,sKitName,psLabels); if(bOK) { int nCols = GetNumberCols(); int i; for(i = 0; i < nCols; i++) { SetCellEditor( ROW_MIN_BOUND_HOMOZYGOTE,i,new wxGridCellFloatEditor(-1,0)); } } return bOK; }
void ctPropertyEditorGrid::OnSize(wxSizeEvent& event) { if (m_stretchableColumn != -1) { // This window's client size = the internal window's // client size if it has no borders wxSize sz = GetClientSize(); int totalSize = 0; int i; for (i = 0; i < GetNumberCols(); i ++) { if (i != m_stretchableColumn) { totalSize += GetColSize(i); } } // Allow for grid lines totalSize += 1; int stretchSize = wxMax(5, sz.x - totalSize); SetColSize(m_stretchableColumn, stretchSize); } event.Skip(); }
const std::string wex::grid::get_selected_cells_value() const { // This does not work, only filled in for singly selected cells. // wxGridCellCoordsArray cells = GetSelectedCells(); wxString text; for (int i = 0; i < GetNumberRows(); i++) { bool value_added = false; for (int j = 0; j < GetNumberCols(); j++) { if (IsInSelection(i, j)) { if (value_added) { text << "\t"; } text << GetCellValue(i, j); value_added = true; } } if (value_added) { text << "\n"; } } return text; }
void ctlSQLGrid::AutoSizeColumn(int col, bool setAsMin, bool doLimit) { ColKeySizeHashMap::iterator it = colSizes.find(GetColKeyValue(col)); if (it != colSizes.end()) // Restore user-specified size SetColSize(col, it->second); else wxGrid::AutoSizeColumn(col, setAsMin); if (doLimit) { int newSize, oldSize; int maxSize, totalSize = 0, availSize; oldSize = GetColSize(col); availSize = GetClientSize().GetWidth() - GetRowLabelSize(); maxSize = availSize / 2; for (int i = 0 ; i < GetNumberCols() ; i++) totalSize += GetColSize(i); if (oldSize > maxSize && totalSize > availSize) { totalSize -= oldSize; /* Shrink wide column to maxSize. * If the rest of the columns are short, make sure to use all the remaining space, * but no more than oldSize (which is enough according to AutoSizeColumns()) */ newSize = wxMin(oldSize, wxMax(maxSize, availSize - totalSize)); SetColSize(col, newSize); } } }
void ctlSQLGrid::OnMouseWheel(wxMouseEvent &event) { if (event.ControlDown() || event.CmdDown()) { wxFont fontlabel = GetLabelFont(); wxFont fontcells = GetDefaultCellFont(); if (event.GetWheelRotation() > 0) { fontlabel.SetPointSize(fontlabel.GetPointSize() - 1); fontcells.SetPointSize(fontcells.GetPointSize() - 1); } else { fontlabel.SetPointSize(fontlabel.GetPointSize() + 1); fontcells.SetPointSize(fontcells.GetPointSize() + 1); } SetLabelFont(fontlabel); SetDefaultCellFont(fontcells); SetColLabelSize(fontlabel.GetPointSize() * 4); SetDefaultRowSize(fontcells.GetPointSize() * 2); for (int index = 0; index < GetNumberCols(); index++) SetColSize(index, -1); ForceRefresh(); } else event.Skip(); }
void wex::grid::set_cells_value( const wxGridCellCoords& start_coords, const std::string& data) { tokenizer tkz(data, "\n"); auto start_at_row = start_coords.GetRow(); while (tkz.has_more_tokens()) { const auto line(tkz.get_next_token()); tokenizer tkz(line, "\t"); auto next_col = start_coords.GetCol(); while (tkz.has_more_tokens() && next_col < GetNumberCols()) { const std::string value = tkz.get_next_token(); if (!IsReadOnly(start_at_row, next_col)) { set_grid_cell_value(wxGridCellCoords(start_at_row, next_col), value); } next_col++; } start_at_row++; } }
wxString ctlSQLGrid::GetExportLine(int row, wxArrayInt cols) { wxString str; unsigned int col; if (GetNumberCols() == 0) return str; for (col = 0 ; col < cols.Count() ; col++) { if (col > 0) str.Append(settings->GetCopyColSeparator()); wxString text = GetCellValue(row, cols[col]); bool needQuote = false; if (settings->GetCopyQuoting() == 1) { needQuote = IsColText(cols[col]); } else if (settings->GetCopyQuoting() == 2) /* Quote everything */ needQuote = true; if (needQuote) str.Append(settings->GetCopyQuoteChar()); str.Append(text); if (needQuote) str.Append(settings->GetCopyQuoteChar()); } return str; }
void CGridAlleleBase::_FitString(const wxString &s, int nStartColumn) { int nCols = GetNumberCols(); int nRows = GetNumberRows(); int nCol; int nRow; if(nStartColumn < 0) { nStartColumn = (int)m_vsLeftColumns.size(); } if(nRows > 1 && nCols > 0) { for(nCol = nStartColumn; nCol < nCols; nCol++) { SetCellValue(1,nCol,s); } for(nRow = 0; nRow < nRows; nRow++) { SetRowLabelValue(nRow,wxEmptyString); } UpdateLabelSizes(); SetRowLabelSize(2); AutoSize(); } }
void CTWenUGCtrlEx::AppendRow_ButtonAdd(void) { int nRow = CUGCtrl::GetNumberRows(); if(nRow > 0) { CUGCell cell; GetCell(0, nRow-1, &cell); if(cell.GetBitmap()==GetBitmap(m_nIndexBMP_Add))//如果有增加行 { return; } } if(AppendRow() != UG_SUCCESS) return; int nCol = GetNumberCols(); JoinCells(1, nRow, nCol-1, nRow); if(nCol>1) { QuickSetBackColor(1, nRow, RGB(240,240,240)); QuickSetBorder(1, nRow, UG_BDR_RAISED|UG_BDR_LTHIN|UG_BDR_RTHIN|UG_BDR_TTHIN|UG_BDR_BTHIN); } QuickSetBitmap(0, nRow, m_nIndexBMP_Add); }
void wxSheetValueProviderBase::Clear() { const int numRows = GetNumberRows(); const int numCols = GetNumberCols(); if (numRows > 0) UpdateRows(0, -numRows); if (numCols > 0) UpdateCols(0, -numCols); }
void CGridLabThresholds::_CreateGrid(int nRows, int nCols) { int nPrevCols = 0; int nPrevRows = 0; int nCol; if(!m_bCreated) { m_bCreated = true; CreateGrid(nRows,nCols); SetRowLabelAlignment(wxALIGN_LEFT, wxALIGN_CENTRE); EnableDragColSize(false); EnableDragRowSize(false); SetDefaultCellAlignment(wxALIGN_RIGHT,wxALIGN_CENTRE); } else { nPrevRows = GetNumberRows(); nPrevCols = GetNumberCols(); nwxGrid::SetRowColCount(this,nRows,nCols); } for(nCol = nPrevCols; nCol < nCols; nCol++) { // set alignment for Channel row SetCellAlignment(0,nCol,wxALIGN_CENTRE, wxALIGN_CENTRE); } }
void CGridAlerts::OnCellChange(wxGridEvent &e) { if( !(m_nInCellChangeEvent || IsTableReadOnly()) ) { CIncrementer x(m_nInCellChangeEvent); nwxGridBatch xxxx(this); int nRow = e.GetRow(); int nCol = e.GetCol(); COARmessage *pMsg = m_pMsgEdit->GetMessage((size_t) nRow); int nCols = GetNumberCols(); const wxString &sName(pMsg->GetMessageName()); if(nCol == (nCols - 1)) { UpdateTextFromRow(nRow,pMsg); } else if(nCol == (nCols - 2)) { UpdateDisabledFromRow(nRow,pMsg); if((!sName.IsEmpty()) && GetBoolValue(nRow,nCol)) { // a row has been enabled // check for mutually exclusive rows // that are enabled and disable them set<wxString> ss; const COARmsgExportMap *pMsgExp = m_pMsgEdit->GetMsgExport(); if(pMsgExp->GetGroupsByMsgName(sName,&ss)) { // we found group names size_t nCount = m_pMsgEdit->GetMessageCount(); size_t iRow; for(iRow = 0; iRow < nCount; iRow++) { if(iRow == (size_t)nRow) {} else if(!GetBoolValue(iRow,nCol)) {} // already unchecked, fuhgeddaboudit. else { COARmessage *pMsgA = m_pMsgEdit->GetMessage(iRow); const wxString &sNameA(pMsgA->GetMessageName()); if(sNameA.IsEmpty()) {} else if( (sNameA == sName) || (pMsgExp->HasGroupByMsgName(sNameA,ss)) ) { // need to uncheck message SetBoolValue(iRow,nCol,false); UpdateDisabledFromRow(iRow,pMsgA); } } } } } } } e.Skip(true); }
wxPen CGridLabThresholds::GetColGridLinePen(int nCol) { int nBlackCol = GetNumberCols() - (m_bILS ? 2 : 1); if(nCol >= nBlackCol) { return *wxBLACK_PEN; } return wxGrid::GetColGridLinePen(nCol); }
void CGridAlerts::UpdateDisabledFromRow( int nRow, COARmessage *pMsg) { int nCols = GetNumberCols() - 2; bool bHidden = !GetBoolValue(nRow,nCols++); pMsg->SetHidden(bHidden); DisableEdit(nRow,nCols,bHidden); Refresh(); }
wxString wxDbGridTableBase::GetColLabelValue(int col) { if (GetNumberCols() > col) { return m_ColInfo[col].Title; } wxFAIL_MSG (_T("unknown column")); return wxString(); }
//--------------------------------------------------------- void CVIEW_Table_Control::On_Size(wxSizeEvent &event)//&WXUNUSED(event)) { if( m_Field_Offset && GetNumberCols() && GetClientSize().x > GetRowLabelSize() ) { SetColSize(0, GetClientSize().x - GetRowLabelSize()); } event.Skip(); }
wxString wxGISTable::GetValue(int row, int col) { if(GetNumberCols() <= col || GetNumberRows() <= row) return wxString(); //fetch more data wxBusyCursor wait; return m_pwxGISDataset->GetAsString(row, col); }
//--------------------------------------------------------- void CVIEW_Table_Control::On_LClick(wxGridEvent &event) { int iField = m_Field_Offset + event.GetCol(); CSG_Table_Record *pRecord = m_pRecords[event.GetRow()]; //----------------------------------------------------- if( event.AltDown() ) { if( m_pTable->Get_Field_Type(iField) == SG_DATATYPE_String ) { if( event.ControlDown() ) { g_pData->Open (pRecord->asString(iField)); } else { Open_Application(pRecord->asString(iField)); } } } //----------------------------------------------------- else if( event.ControlDown() ) { m_pTable->Select(pRecord, true); Update_Selection(); } else if( event.ShiftDown() ) { SelectBlock(event.GetRow(), 0, GetGridCursorRow(), GetNumberCols(), false); } else { SelectRow(event.GetRow(), false); if( pRecord && iField >= m_Field_Offset && iField < m_pTable->Get_Field_Count() && m_pTable->Get_Field_Type(iField) == SG_DATATYPE_Color ) { long lValue; if( DLG_Color(lValue = pRecord->asInt(iField)) ) { pRecord->Set_Value(iField, lValue); SetCellBackgroundColour(event.GetRow(), event.GetCol(), Get_Color_asWX(pRecord->asInt(iField))); ForceRefresh(); } } } //----------------------------------------------------- SetGridCursor(event.GetRow(), event.GetCol()); }
BOOL CTWenUGCtrlEx::SetTitle(int nCol, CString cStrTitleName, int nColWidth, int nTitleNO) { if(nCol>=GetNumberCols()) return FALSE; QuickSetText(nCol, nTitleNO, cStrTitleName); QuickSetFont(nCol, nTitleNO, m_nFontID_Title); SetColWidth(nCol, nColWidth); return TRUE; }
const std::string wex::grid::build_page() { wxString text; text << "<TABLE "; if (GridLinesEnabled()) text << "border=1"; else text << "border=0"; text << " cellpadding=4 cellspacing=0 >\n"; text << "<tr>\n"; // Add the col labels only if they are shown. if (GetColLabelSize() > 0) { for (int c = 0 ; c < GetNumberCols(); c++) { text << "<td><i>" << GetColLabelValue(c) << "</i>\n"; } } for (int i = 0 ; i < GetNumberRows(); i++) { text << "<tr>\n"; for (int j = 0 ; j < GetNumberCols(); j++) { text << "<td>" << (GetCellValue(i, j).empty() ? " ": GetCellValue(i, j)) << "\n"; } } text << "</TABLE>\n"; // This can be useful for testing, paste in a file and // check in your browser (there indeed rules are okay). // clipboard_add(text); return text; }
wxString wxGISGridTable::GetValue(int row, int col) { if(GetNumberCols() <= col || GetNumberRows() <= row) return wxEmptyString; //fetch more data wxGISFeature Feature = m_pGISDataset->GetFeature(row); if(Feature.IsOk()) return Feature.GetFieldAsString(col); return wxEmptyString; }
void CTWenUGCtrlEx::SwapRow(long i, long j) { CUGCell ci, cj; for(int cols=0; cols<GetNumberCols(); cols++) { GetCell(cols, i, &ci); GetCell(cols, j, &cj); SetCell(cols, i, &cj); SetCell(cols, j, &ci); } }