24 #include <wx/tokenzr.h> 31 #define MIN_GRIDCELL_MARGIN 3 34 WX_GRID::WX_GRID( wxWindow *parent, wxWindowID
id,
const wxPoint& pos,
const wxSize& size,
35 long style,
const wxString&
name ) :
36 wxGrid( parent, id, pos, size, style,
name ),
39 SetDefaultCellOverflow(
false );
44 #if wxCHECK_VERSION( 3, 1, 0 ) 45 Connect( wxEVT_DPI_CHANGED, wxDPIChangedEventHandler( WX_GRID::onDPIChanged ),
nullptr,
this );
56 #if wxCHECK_VERSION( 3, 1, 0 ) 57 Disconnect( wxEVT_DPI_CHANGED, wxDPIChangedEventHandler( WX_GRID::onDPIChanged ),
nullptr,
this );
63 #if wxCHECK_VERSION( 3, 1, 0 ) 64 void WX_GRID::onDPIChanged(wxDPIChangedEvent& aEvt)
78 wxGrid::SetColLabelSize( 0 );
85 SetLabelFont( headingFont );
89 wxGrid::SetColLabelSize( std::max( aHeight, minHeight ) );
97 int numberCols = GetNumberCols();
98 int* formBuilderColWidths =
new int[numberCols];
100 for(
int i = 0; i < numberCols; ++i )
101 formBuilderColWidths[ i ] = GetColSize( i );
103 wxGrid::SetTable( aTable );
107 numberCols = std::min( numberCols, GetNumberCols() );
109 for(
int i = 0; i < numberCols; ++i )
114 SetColSize( i, std::max( formBuilderColWidths[ i ], headingWidth ) );
117 delete[] formBuilderColWidths;
132 int row = aEvent.GetRow();
133 int col = aEvent.GetCol();
135 if( row >= 0 && col >= 0 )
136 SelectBlock(row,col,row,col,
false);
148 wxGrid::SetTable(
nullptr );
155 wxString shownColumns;
157 for(
int i = 0; i < GetNumberCols(); ++i )
159 if( IsColShown( i ) )
161 if( shownColumns.Length() )
162 shownColumns << wxT(
" " );
174 for(
int i = 0; i < GetNumberCols(); ++i )
177 wxStringTokenizer shownTokens( shownColumns );
179 while( shownTokens.HasMoreTokens() )
182 shownTokens.GetNextToken().ToLong( &colNumber );
184 if( colNumber >= 0 && colNumber < GetNumberCols() )
185 ShowCol( colNumber );
192 if( GetColWidth( col ) <= 0 || m_colLabelHeight <= 0 )
195 int colLeft = GetColLeft( col );
197 wxRect rect( colLeft, 0, GetColWidth( col ), m_colLabelHeight );
198 static wxGridColumnHeaderRendererDefault rend;
203 #if wxCHECK_VERSION( 3, 1, 3 ) 204 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
206 wxDCBrushChanger setBrush( dc, m_colWindow->GetBackgroundColour() );
208 dc.DrawRectangle(rect);
210 rend.DrawBorder( *
this, dc, rect );
213 dc.SetFont( GetLabelFont() );
216 GetColLabelAlignment( &hAlign, &vAlign );
217 const int orient = GetColLabelTextOrientation();
219 if( col == 0 && GetRowLabelSize() == 0 )
220 hAlign = wxALIGN_LEFT;
222 rend.DrawLabel( *
this, dc, GetColLabelValue( col ), rect, hAlign, vAlign, orient );
228 if( !IsCellEditControlEnabled() )
231 if( !aQuietMode && SendEvent( wxEVT_GRID_EDITOR_HIDDEN ) == -1 )
234 HideCellEditControl();
237 m_cellEditCtrlEnabled =
false;
239 int row = m_currentCellCoords.GetRow();
240 int col = m_currentCellCoords.GetCol();
242 wxString oldval = GetCellValue( row, col );
245 wxGridCellAttr* attr = GetCellAttr( row, col );
246 wxGridCellEditor*
editor = attr->GetEditor(
this, row, col );
248 bool changed =
editor->EndEdit( row, col,
this, oldval, &newval );
255 if( !aQuietMode && SendEvent( wxEVT_GRID_CELL_CHANGING, newval ) == -1 )
258 editor->ApplyEdit( row, col,
this );
263 if( !aQuietMode && SendEvent( wxEVT_GRID_CELL_CHANGED, oldval ) == -1 )
266 SetCellValue( row, col, oldval );
289 size = GetRowLabelSize();
294 for(
int row = 0; aContents && row < GetNumberRows(); row++ )
295 size = std::max( size,
int( GetTextExtent( GetRowLabelValue( row ) + wxT(
"M" ) ).x * 1.1 ) );
300 size = GetColSize( aCol );
310 size = std::max( size,
int( GetTextExtent( GetColLabelValue( aCol ) + wxT(
"M" ) ).x * 1.1 ) );
313 for(
int row = 0; aContents && row < GetNumberRows(); row++ )
316 if( GetTable()->CanGetValueAs( row, aCol, wxGRID_VALUE_STRING ) )
317 size = std::max( size, GetTextExtent( GetCellValue( row, aCol ) + wxT(
"M" ) ).x );
319 size = std::max( size, GetTextExtent(
"MM" ).x );
332 int line_height = int( GetTextExtent(
"Mj" ).y * 1.1 ) + 3;
333 int row_height = GetColLabelSize();
334 int initial_row_height = row_height;
339 for(
int col = 0; col < GetNumberCols(); col++ )
341 int nl_count = GetColLabelValue( col ).Freq(
'\n' );
346 if( row_height < line_height * ( nl_count+1 ) )
347 row_height += line_height * nl_count;
353 if( initial_row_height != row_height )
void DrawColLabel(wxDC &dc, int col) override
A re-implementation of wxGrid::DrawColLabel which left-aligns the first column when there are no row ...
WX_GRID(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxWANTS_CHARS, const wxString &name=wxGridNameStr)
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
wxFont GetControlFont(wxWindow *aWindow)
#define MIN_GRIDCELL_MARGIN
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=false, bool aKeep=true)
Calculates the specified column based on the actual size of the text on screen.
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
void onGridColMove(wxGridEvent &aEvent)
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Functions to provide common constants and other functions to assist in making a consistent UI.
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
void onGridCellSelect(wxGridEvent &aEvent)
void SetColLabelSize(int aHeight)
Hide wxGrid's SetColLabelSize() method with one which makes sure the size is tall enough for the syst...