//--------------------------------------------------------- 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(); }
//--------------------------------------------------------- void CActive_Attributes_Control::On_Size(wxSizeEvent &event)//&WXUNUSED(event)) { if( m_Field_Offset ) // feature attributes { if( GetNumberCols() > 0 && GetClientSize().x > GetRowLabelSize() ) { SetColSize(0, GetClientSize().x - GetRowLabelSize()); } } event.Skip(); }
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); } } }
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 CVIEW_Table_Control::On_RClick_Label(wxGridEvent &event) { wxMenu Menu; //----------------------------------------------------- if( event.GetCol() != -1 ) { Menu.SetTitle(wxString::Format(wxT("%s"), _TL("Columns"))); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_ADD); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_DEL); Menu.AppendSeparator(); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_AUTOSIZE_COLS); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_SORT); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_RENAME); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_TYPE); PopupMenu(&Menu, event.GetPosition().x, event.GetPosition().y - GetColLabelSize()); } //----------------------------------------------------- else if( event.GetRow() != -1 ) { Menu.SetTitle(wxString::Format(wxT("%s"), _TL("Rows"))); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_RECORD_ADD); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_RECORD_INS); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_RECORD_DEL); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_RECORD_DEL_ALL); Menu.AppendSeparator(); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_AUTOSIZE_ROWS); if( !FIXED_ROWS ) { Menu.AppendSeparator(); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_SELECTION_TO_TOP); CMD_Menu_Add_Item(&Menu, true, ID_CMD_TABLE_SELECTION_ONLY); } PopupMenu(&Menu, event.GetPosition().x - GetRowLabelSize(), event.GetPosition().y); } //----------------------------------------------------- else { ClearSelection(); } }
//--------------------------------------------------------- void CActive_Attributes_Control::On_RClick_Label(wxGridEvent &event) { wxMenu Menu; //----------------------------------------------------- if( event.GetCol() != -1 ) { Menu.SetTitle(_TL("Columns")); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_TO_CLIPBOARD); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_AUTOSIZE_COLS); if( g_pActive->Get_Active_Data_Item() && g_pActive->Get_Active_Data_Item()->Get_Type() == WKSP_ITEM_Grids ) { Menu.AppendSeparator(); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_ADD); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_DEL); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_RENAME); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_FIELD_TYPE); } } else if( event.GetRow() != -1 ) { Menu.SetTitle(_TL("Rows")); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_TO_CLIPBOARD); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_AUTOSIZE_ROWS); } else { Menu.SetTitle(_TL("Attributes")); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_TO_CLIPBOARD); } //----------------------------------------------------- PopupMenu(&Menu, event.GetPosition().x - GetRowLabelSize(), event.GetPosition().y); }
wxSize MultiDimGridGrid::DoGetBestSize() const { // 100 is the default minimal size of a widget - taken from wx headers. int width = std::max(GetRowLabelSize() + GetColSize(0), 100); int height = std::max(GetColLabelSize() + GetRowSize(0), 100); // The following is from the wx header file for wxScrollWindow: // Round up to a multiple the scroll rate NOTE: this still doesn't get rid // of the scrollbars, is there any magic incantaion for that? int xpu, ypu; GetScrollPixelsPerUnit(&xpu, &ypu); if(xpu) { width += 1 + xpu - (width % xpu); } if(ypu) { height += 1 + ypu - (height % ypu); } return wxSize(width, height); }
//--------------------------------------------------------- void CActive_Attributes_Control::On_RClick_Label(wxGridEvent &event) { //----------------------------------------------------- if( event.GetCol() != -1 ) { wxMenu Menu(_TL("Columns")); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_AUTOSIZE_COLS); PopupMenu(&Menu, event.GetPosition().x, event.GetPosition().y - GetColLabelSize()); } //----------------------------------------------------- else if( event.GetRow() != -1 ) { wxMenu Menu(_TL("Rows")); CMD_Menu_Add_Item(&Menu, false, ID_CMD_TABLE_AUTOSIZE_ROWS); PopupMenu(&Menu, event.GetPosition().x - GetRowLabelSize(), event.GetPosition().y); } }
//--------------------------------------------------------- bool CActive_Attributes_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; } } //----------------------------------------------------- if( (Difference = m_pTable->Get_Count() - GetNumberRows()) > 0 ) { AppendRows(Difference); } else if( Difference < 0 && (Difference = -Difference < GetNumberRows() ? -Difference : GetNumberRows()) > 0 ) { DeleteRows(0, Difference); } //------------------------------------------------- for(int iRecord=0; iRecord<m_pTable->Get_Count(); iRecord++) { _Set_Record(iRecord); } //----------------------------------------------------- if( GetNumberCols() > 0 && GetNumberRows() > 0 ) { SetRowLabelSize(wxGRID_AUTOSIZE); if( m_Field_Offset ) // feature attributes { if( GetClientSize().x > GetRowLabelSize() ) { SetColSize(0, GetClientSize().x - GetRowLabelSize()); } } else // grid cell values { AutoSizeColumns(); } } Enable(GetNumberRows() > 0); m_pTable->Set_Modified(false); //----------------------------------------------------- EndBatch(); return( true ); }
void ctlSQLGrid::AutoSizeColumns(bool setAsMin) { wxCoord newSize, oldSize; wxCoord maxSize, totalSize = 0, availSize; int col, nCols = GetNumberCols(); int row, nRows = GetNumberRows(); colMaxSizes.Empty(); /* We need to check each cell's width to choose best. wxGrid::AutoSizeColumns() * is good, but looping through long result sets gives a noticeable slowdown. * Thus we'll check every first 500 cells for each column. */ // First pass: auto-size columns for (col = 0 ; col < nCols; col++) { ColKeySizeHashMap::iterator it = colSizes.find(GetColKeyValue(col)); if (it != colSizes.end()) // Restore user-specified size { newSize = it->second; colMaxSizes.Add(-1); } else { wxClientDC dc(GetGridWindow()); newSize = 0; // get cells's width for (row = 0 ; row < wxMin(nRows, 500) ; row++) { wxSize size = GetBestSize(row, col); if ( size.x > newSize ) newSize = size.x; } // get column's label width wxCoord w, h; dc.SetFont( GetLabelFont() ); dc.GetMultiLineTextExtent( GetColLabelValue(col), &w, &h ); if ( GetColLabelTextOrientation() == wxVERTICAL ) w = h; if ( w > newSize ) newSize = w; if (!newSize) newSize = GetRowLabelSize(); else // leave some space around text newSize += 6; colMaxSizes.Add(newSize); } SetColSize(col, newSize); totalSize += newSize; } availSize = GetClientSize().GetWidth() - GetRowLabelSize(); // Second pass: shrink wide columns if exceeded available width if (totalSize > availSize) { // A wide column shouldn't take up more than 50% of the visible space maxSize = availSize / 2; for (col = 0 ; col < nCols ; col++) { oldSize = GetColSize(col); // Is too wide and no user-specified size if (oldSize > maxSize && !(col < (int)colMaxSizes.GetCount() && colMaxSizes[col] == -1)) { 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 first pass) */ newSize = wxMin(oldSize, wxMax(maxSize, availSize - totalSize)); SetColSize(col, newSize); totalSize += newSize; } } } }