26#include <wx/artprov.h>
28#include <wx/textctrl.h>
36 const wxArrayString& names ) :
44 wxSize aPreferredIconSize ) :
46 m_iconSize( aPreferredIconSize )
52 const wxRect& aRect,
int aRow,
int aCol,
bool isSelected )
54 wxString value = aGrid.GetCellValue( aRow, aCol );
60 wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
63 int leftCut = aDC.FromDIP( 4 );
68 ?
m_icon.GetPreferredBitmapSizeAtScale( aDC.GetContentScaleFactor() )
74 bitmap.SetScaleFactor(
scale );
76 aDC.DrawBitmap( bitmap,
77 rect.GetLeft() + leftCut,
78 rect.GetTop() + ( rect.GetHeight() - bitmap.GetLogicalHeight() ) / 2,
81 leftCut += bitmap.GetLogicalWidth();
87 int position =
m_names.Index( value );
89 if( position < (
int)
m_icons.size() && position != wxNOT_FOUND )
93 wxBitmap bitmap = bundle.GetBitmap(
94 bundle.GetPreferredBitmapSizeAtScale( aDC.GetContentScaleFactor() ) );
96 aDC.DrawBitmap( bitmap,
97 rect.GetLeft() + leftCut,
98 rect.GetTop() + ( rect.GetHeight() - bitmap.GetLogicalHeight() ) / 2,
101 leftCut += bitmap.GetLogicalWidth();
107 wxBitmap bitmap = bundle.GetBitmap(
108 bundle.GetPreferredBitmapSizeAtScale( aDC.GetContentScaleFactor() ) );
110 leftCut += bitmap.GetLogicalWidth();
114 leftCut += aDC.FromDIP( 4 );
117 rect.width -= leftCut;
120 SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
121 aGrid.DrawTextRectangle( aDC, value, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
134 ?
m_icon.GetPreferredBitmapSizeAtScale( dc.GetContentScaleFactor() )
139 int bmpIdx = ( row < (int)
m_icons.size() && row >= 0 ) ? row : 0;
142 bitmap = bundle.GetBitmap(
143 bundle.GetPreferredBitmapSizeAtScale( dc.GetContentScaleFactor() ) );
144 bitmapSize = wxSize( bitmap.GetLogicalWidth(), -1 );
147 wxString
text =
grid.GetCellValue( row, col );
148 wxSize size = wxGridCellStringRenderer::DoGetBestSize( attr, dc,
text );
150 size.x += bitmapSize.x + dc.FromDIP( 8 );
151 size.y = std::max( size.y, bitmapSize.y + dc.FromDIP( 2 ) );
164 const wxRect& aRect,
int aRow,
int aCol,
bool isSelected )
170 wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
176 rect.GetLeft() + ( rect.GetWidth() -
m_icon.GetWidth() ) / 2,
177 rect.GetTop() + ( rect.GetHeight() -
m_icon.GetHeight() ) / 2,
186 return wxSize(
m_icon.GetWidth() + 6,
m_icon.GetHeight() + 4 );
205 m_bitmap = wxArtProvider::GetBitmap( wxArtProvider::GetMessageBoxIconId(
m_status ),
211 m_bitmap = wxArtProvider::GetBitmap( wxArtProvider::GetMessageBoxIconId( wxICON_INFORMATION ),
218 const wxRect& aRect,
int aRow,
int aCol,
225 wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
231 rect.GetLeft() + ( rect.GetWidth() -
m_bitmap.GetWidth() ) / 2,
232 rect.GetTop() + ( rect.GetHeight() -
m_bitmap.GetHeight() ) / 2,
252 const wxArrayString& names ) :
266 wxEvtHandler* aEventHandler )
268 m_control =
new wxBitmapComboBox( aParent, aId, wxEmptyString, wxDefaultPosition,
269 wxDefaultSize, 0,
nullptr,
270 wxCB_READONLY | wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxBORDER_NONE );
272 for(
unsigned i = 0; i <
m_names.size(); ++i )
276 if( i <
m_icons.size() &&
m_icons[ i ] != BITMAPS::INVALID_BITMAP )
282 wxGridCellEditor::Create(aParent, aId, aEventHandler);
288 return Combo()->GetValue();
294 wxRect rect( aRect );
297#if !defined( __WXMSW__ ) && !defined( __WXGTK__ )
299 Combo()->SetButtonPosition( 0, 0, wxRIGHT, 2 );
302#if defined( __WXMAC__ )
306 Combo()->SetSize( rect, wxSIZE_ALLOW_MINUS_ONE );
312 auto evtHandler =
static_cast<wxGridCellEditorEvtHandler*
>( m_control->GetEventHandler() );
315 evtHandler->SetInSetFocus(
true );
317 m_value = aGrid->GetTable()->GetValue( aRow, aCol );
322#ifdef __WXOSX_COCOA__
332#if !defined(__WXGTK__)
333 evtHandler->SetInSetFocus(
false );
341 const wxString value =
Combo()->GetValue();
357 aGrid->GetTable()->SetValue( aRow, aCol,
m_value );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
wxGridCellRenderer * Clone() const override
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
GRID_CELL_ICON_RENDERER(const wxBitmap &icon)
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
GRID_CELL_ICON_TEXT_RENDERER(const std::vector< BITMAPS > &icons, const wxArrayString &names)
Construct a renderer that maps a list of icons from the bitmap system to a list of strings.
std::vector< BITMAPS > m_icons
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
wxGridCellRenderer * Clone() const override
GRID_CELL_STATUS_ICON_RENDERER(int aStatus)
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override