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; }
void CCJListCtrl::SetColumnWidth(int nCol) { int iWidth = GetRegColumnWidth( nCol ); if( iWidth < MINCOLWIDTH ) AutoSizeColumn( nCol ); else CListCtrl::SetColumnWidth( nCol, iWidth ); }
/* Utility function to Autosize all columns in the case there is no registry entry. */ void CMultiColumnSortListCtrl::AutoSizeAllColumns() { int iNumCols = GetColumnCount(); for( int i = 0; i < iNumCols; i++ ) { AutoSizeColumn( i ); } }
/* Utility function to set the width on the column based on the registry value and a set minimum column width. */ void CMultiColumnSortListCtrl::SetColumnWidth( int nCol ) { int iWidth = GetRegColumnWidth( nCol ); if( iWidth > -1 ) { if( iWidth < MINCOLWIDTH ) { AutoSizeColumn( nCol ); } else { CListCtrl::SetColumnWidth( nCol, iWidth ); } } }
//------------------------------------------------------------------------------ // // Function Name: CMLListCtrl::AutoSizeColumns() // // Parameters: None // // Return Value: None // // Description: Called to resize the columns to fit their content // //------------------------------------------------------------------------------ void CMLListCtrl::AutoSizeColumns() { // Size each of the columns if(m_pColumns != NULL) { // Use the full client area if only one column in the list if(m_pColumns->GetUpperBound() == 0) { this->SetColumnWidth(0, -2); } else { for(int i = 0; i <= m_pColumns->GetUpperBound(); i++) AutoSizeColumn(i, m_pColumns->GetAt(i)); } }// if(m_pColumns != NULL) }
/** InitGridSizes * * Initializes the Grid Sizes */ void MemoryGrid::InitGridSizes() { int w, h; GetClientSize(&w, &h); w -= 24; AutoSizeColumn(MemoryBinary); w -= GetColSize(MemoryBinary); SetColSize(MemoryInfo, 22); SetColSize(MemoryAddress, 8 * w / 75 - 8); SetColSize(MemoryHexadecimal, 8 * w / 75); SetColSize(MemoryDecimal, 10 * w / 75); //SetColSize(MemoryBinary, 25 * w / 100); SetColSize(MemoryLabel, 18 * w / 75); SetColSize(MemoryInstruction, 31 * w / 75 + 9); wxGridCellAttr* info = new wxGridCellAttr; info->SetReadOnly(); info->SetTextColour(*wxBLACK); info->SetRenderer(new GridCellInfoRenderer()); wxGridCellAttr* addr = new wxGridCellAttr; addr->SetReadOnly(); addr->SetTextColour(*wxBLACK); wxGridCellAttr* instr = new wxGridCellAttr; instr->SetTextColour(*wxBLACK); wxGridCellAttr* hex = new wxGridCellAttr; hex->SetTextColour(*wxBLUE); wxGridCellAttr* decimal = new wxGridCellAttr; decimal->SetTextColour(*wxRED); wxGridCellAttr* binary = new wxGridCellAttr; binary->SetTextColour(*wxWHITE); binary->SetBackgroundColour(wxTransparentColor); binary->SetRenderer(new GridCellBinaryRenderer()); //binary->SetFont(wxFont( 10, 70, 90, wxFONTWEIGHT_BOLD, false, wxT("Courier New"))); wxGridCellAttr* label = new wxGridCellAttr; label->SetTextColour(wxColour(64, 64, 64)); SetColAttr(MemoryInfo, info); SetColAttr(MemoryAddress, addr); SetColAttr(MemoryHexadecimal, hex); SetColAttr(MemoryDecimal, decimal); SetColAttr(MemoryBinary, binary); SetColAttr(MemoryLabel, label); SetColAttr(MemoryInstruction, instr); }
void ctlSQLGrid::OnLabelDoubleClick(wxGridEvent &event) { int maxHeight, maxWidth; GetClientSize(&maxWidth, &maxHeight); int row = event.GetRow(); int col = event.GetCol(); int extent, extentWant = 0; if (row >= 0) { for (col = 0 ; col < GetNumberCols() ; col++) { extent = GetBestSize(row, col).GetHeight(); if (extent > extentWant) extentWant = extent; } extentWant += EXTRAEXTENT_HEIGHT; extentWant = wxMax(extentWant, GetRowMinimalAcceptableHeight()); extentWant = wxMin(extentWant, maxHeight * 3 / 4); int currentHeight = GetRowHeight(row); if (currentHeight >= maxHeight * 3 / 4 || currentHeight == extentWant) extentWant = GetRowMinimalAcceptableHeight(); else if (currentHeight < maxHeight / 4) extentWant = wxMin(maxHeight / 4, extentWant); else if (currentHeight < maxHeight / 2) extentWant = wxMin(maxHeight / 2, extentWant); else if (currentHeight < maxHeight * 3 / 4) extentWant = wxMin(maxHeight * 3 / 4, extentWant); if (extentWant != currentHeight) { BeginBatch(); if(IsCellEditControlShown()) { HideCellEditControl(); SaveEditControlValue(); } SetRowHeight(row, extentWant); EndBatch(); } } else if (col >= 0) { // Holding Ctrl or Meta switches back to automatic column's sizing if (event.ControlDown() || event.CmdDown()) { colSizes.erase(GetColKeyValue(col)); BeginBatch(); if(IsCellEditControlShown()) { HideCellEditControl(); SaveEditControlValue(); } AutoSizeColumn(col, false); EndBatch(); } else // toggle between some predefined sizes { if (col < (int)colMaxSizes.GetCount() && colMaxSizes[col] >= 0) extentWant = colMaxSizes[col]; else { for (row = 0 ; row < GetNumberRows() ; row++) { if (CheckRowPresent(row)) { extent = GetBestSize(row, col).GetWidth(); if (extent > extentWant) extentWant = extent; } } } extentWant += EXTRAEXTENT_WIDTH; extentWant = wxMax(extentWant, GetColMinimalAcceptableWidth()); extentWant = wxMin(extentWant, maxWidth * 3 / 4); int currentWidth = GetColumnWidth(col); if (currentWidth >= maxWidth * 3 / 4 || currentWidth == extentWant) extentWant = GetColMinimalAcceptableWidth(); else if (currentWidth < maxWidth / 4) extentWant = wxMin(maxWidth / 4, extentWant); else if (currentWidth < maxWidth / 2) extentWant = wxMin(maxWidth / 2, extentWant); else if (currentWidth < maxWidth * 3 / 4) extentWant = wxMin(maxWidth * 3 / 4, extentWant); if (extentWant != currentWidth) { BeginBatch(); if(IsCellEditControlShown()) { HideCellEditControl(); SaveEditControlValue(); } SetColumnWidth(col, extentWant); EndBatch(); colSizes[GetColKeyValue(col)] = extentWant; } } } }
void CGridCMF::UpdateEmptyLoci() { size_t nRows = m_vpSample.size(); if(nRows) { wxFont fnBold = GetDefaultCellFont(); wxString sEmptyLoci; wxString COMMA(", "); size_t i; size_t j; size_t nLocusCount; bool bPartial; bool bEmpty; COARlocus *pLocus; COARsample *pSample; fnBold.SetWeight(wxFONTWEIGHT_BOLD); if(m_vsLocus.empty()) { // setup locus names size_t nChannelCount = m_pFile->GetChannelCount(); size_t nLocusCount; const COARchannel *pChannel; m_vsLocus.reserve(24); for(i = 0; i < nChannelCount; i++) { pChannel = m_pFile->GetChannel(i); nLocusCount = pChannel->GetLocusCount(); for(j = 0; j < nLocusCount; j++) { m_vsLocus.push_back(pChannel->GetLocusName(j)); } } } nLocusCount = m_vsLocus.size(); for(i = 0; i < nRows; i++) { // now look for empty loci bPartial = false; bEmpty = true; sEmptyLoci.Empty(); pSample = m_vpSample.at(i); for(j = 0; j < nLocusCount; j++) { pLocus = pSample->FindLocus(m_vsLocus.at(j)); if( (pLocus == NULL) || (!pLocus->EnabledAlleleCount()) ) { // this is an empty locus if(!sEmptyLoci.IsEmpty()) { sEmptyLoci.Append(COMMA); } sEmptyLoci.Append(pLocus->GetName()); bPartial = true; } else { bEmpty = false; } } if(bEmpty) { SetBoolValue((int)i,EXCLUDE,bEmpty); sEmptyLoci = "ALL LOCI"; SetCellFont((int)i,EMPTY_LOCI,fnBold); } else { // // may need to be restored if user pressed // 'finish later' and then edited alleles // SetCellFont((int)i,EMPTY_LOCI,GetDefaultCellFont()); } SetCellValue((int)i,EMPTY_LOCI,sEmptyLoci); if(bPartial) { SetBoolValue((int)i,PARTIAL,bPartial); } DisableEditRow((int) i,bEmpty); SetReadOnly((int)i,EMPTY_LOCI,true); } AutoSizeColumn(EMPTY_LOCI,false); } }
bool CGridCMF::TransferDataToGrid() { size_t n = m_vpSample.size(); bool bRtn = (n > 0); if(bRtn) { // loop through samples const CLabSettings &lab(m_pFile->GetLabSettings()); wxString sName; wxString sCat; COARsample *pSample; const CLabNameStrings *pNameStr; size_t i; for(i = 0; i < n; i++) { pSample = m_vpSample.at(i); // sample name and category sName = pSample->GetName(); pNameStr = lab.GetLabStrings(); if(pNameStr == NULL) { sCat = DEFAULT; } else { sCat = pNameStr->GetCategory(sName); if(sCat.IsEmpty()) { sCat = DEFAULT; } } // now set cell values SetBoolValue((int)i,EXCLUDE,false); SetCellValue((int)i,SPECIMEN_TYPE,sCat); SetCellValue((int)i,SAMPLE,pSample->GetName()); SetTextLength((int)i,SAMPLE,nwxXmlCMFSpecimen::LEN_SPECIMEN_ID); SetTextLength((int)i,SOURCE_ID,nwxXmlCMFSpecimen::LEN_SOURCE_ID); SetTextLength((int)i,CASE_ID,nwxXmlCMFSpecimen::LEN_CASE_ID); SetTextLength((int)i,COMMENT,nwxXmlCMFSpecimen::LEN_SPECIMEN_COMMENT); } UpdateEmptyLoci(); nwxGrid::UpdateLabelSizes(this); AutoSizeColumn(EXCLUDE); AutoSizeColumn(SAMPLE); AutoSizeColumn(PARTIAL); // compute size of SPECIMENT_TYPE columns int nWidth = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); const char *ps = CLabSpecimenCategory::LongestType(); wxClientDC dc(this); dc.SetFont(GetDefaultCellFont()); wxSize sz = dc.GetTextExtent(ps); if(!nWidth) { nWidth = 20; } nWidth += sz.GetWidth(); nWidth += 6; SetColSize(SPECIMEN_TYPE,nWidth); sz = dc.GetTextExtent( "This is sample text to determine the width of the comment column."); nWidth = sz.GetWidth(); nWidth += 2; SetColSize(COMMENT,nWidth); } return bRtn; }