Fix drawing custom colours for wxEnumProperty choice items in wxPG.
In order to draw choice items with custom colours there is necessary to merge custom cell object (wxPGCell) associated with individual item with default cell object (in wxPGProperty::GetDisplayInfo). wxPGProperty::GetDisplayInfo function should return customized cell object instead of returning pointer to the default cell object only. Closes #16509 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77505 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
0f60be60a2
commit
7e859ec6c9
@ -73,6 +73,7 @@ All (GUI):
|
||||
- Allow access to the currently shown wxInfoBar buttons (Hanmac).
|
||||
- Add wxGenericListCtrl::EndEditLabel() (Tim Kosse).
|
||||
- Use native renderer for drawing check boxes in wxPropertyGrid (Eran Ifrah).
|
||||
- Fix drawing custom colours of wxEnumProperty items in wxPG (Artur Wieczorek).
|
||||
|
||||
wxGTK:
|
||||
|
||||
|
@ -2298,11 +2298,20 @@ public:
|
||||
wxPGProperty* GetPropertyByName( const wxString& name ) const;
|
||||
|
||||
// Returns various display-related information for given column
|
||||
#ifdef WXWIN_COMPATIBILITY_3_0
|
||||
wxDEPRECATED_MSG("don't use GetDisplayInfo function with argument of 'const wxPGCell**' type. Use 'wxPGCell*' argument instead")
|
||||
void GetDisplayInfo( unsigned int column,
|
||||
int choiceIndex,
|
||||
int flags,
|
||||
wxString* pString,
|
||||
const wxPGCell** pCell );
|
||||
#endif // WXWIN_COMPATIBILITY_3_0
|
||||
// This function can return modfied (customized) cell object.
|
||||
void GetDisplayInfo( unsigned int column,
|
||||
int choiceIndex,
|
||||
int flags,
|
||||
wxString* pString,
|
||||
wxPGCell* pCell );
|
||||
|
||||
static wxString* sm_wxPG_LABEL;
|
||||
|
||||
|
@ -193,10 +193,10 @@ bool wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
||||
int column, int item, int flags ) const
|
||||
{
|
||||
const wxPGEditor* editor = NULL;
|
||||
const wxPGCell* cell = NULL;
|
||||
|
||||
wxString text;
|
||||
bool isUnspecified = property->IsValueUnspecified();
|
||||
int selItem = item;
|
||||
|
||||
if ( column == 1 && item == -1 )
|
||||
{
|
||||
@ -213,15 +213,20 @@ bool wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// We need to know the current selection to override default
|
||||
// cell settings (colours, etc.) with custom cell settings
|
||||
// which can be defined separately for any single choice item.
|
||||
selItem = property->GetChoiceSelection();
|
||||
}
|
||||
|
||||
int imageWidth = 0;
|
||||
int preDrawFlags = flags;
|
||||
bool res = false;
|
||||
wxPGCell cell;
|
||||
|
||||
property->GetDisplayInfo(column, item, flags, &text, &cell);
|
||||
property->GetDisplayInfo(column, selItem, flags, &text, &cell);
|
||||
|
||||
imageWidth = PreDrawCell( dc, rect, *cell, preDrawFlags );
|
||||
imageWidth = PreDrawCell( dc, rect, cell, preDrawFlags );
|
||||
|
||||
if ( column == 1 )
|
||||
{
|
||||
@ -312,7 +317,7 @@ bool wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
||||
}
|
||||
}
|
||||
|
||||
PostDrawCell(dc, propertyGrid, *cell, preDrawFlags);
|
||||
PostDrawCell(dc, propertyGrid, cell, preDrawFlags);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -749,32 +754,54 @@ void wxPGProperty::OnValidationFailure( wxVariant& WXUNUSED(pendingValue) )
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef WXWIN_COMPATIBILITY_3_0
|
||||
void wxPGProperty::GetDisplayInfo( unsigned int column,
|
||||
int choiceIndex,
|
||||
int flags,
|
||||
wxString* pString,
|
||||
const wxPGCell** pCell )
|
||||
{
|
||||
wxASSERT_MSG(!pCell || !(*pCell),
|
||||
wxT("Cell pointer is a dummy argument and shouldn't be used"));
|
||||
wxUnusedVar(pCell);
|
||||
GetDisplayInfo(column, choiceIndex, flags, pString, (wxPGCell*)NULL);
|
||||
}
|
||||
#endif // WXWIN_COMPATIBILITY_3_0
|
||||
|
||||
void wxPGProperty::GetDisplayInfo( unsigned int column,
|
||||
int choiceIndex,
|
||||
int flags,
|
||||
wxString* pString,
|
||||
wxPGCell* pCell )
|
||||
{
|
||||
wxCHECK_RET( GetGrid(),
|
||||
wxT("Cannot obtain display info for detached property") );
|
||||
const wxPGCell* cell = NULL;
|
||||
|
||||
// Get default cell
|
||||
wxPGCell cell = GetCell(column);
|
||||
|
||||
if ( !(flags & wxPGCellRenderer::ChoicePopup) )
|
||||
{
|
||||
// Not painting list of choice popups, so get text from property
|
||||
if ( column != 1 || !IsValueUnspecified() || IsCategory() )
|
||||
{
|
||||
cell = &GetCell(column);
|
||||
// Overrride default cell settings with
|
||||
// custom settings defined for choice item.
|
||||
if (column == 1 && !IsValueUnspecified() && choiceIndex != wxNOT_FOUND)
|
||||
{
|
||||
const wxPGChoiceEntry& entry = m_choices[choiceIndex];
|
||||
cell.MergeFrom(entry);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use special unspecified value cell
|
||||
cell = &GetGrid()->GetUnspecifiedValueAppearance();
|
||||
cell.MergeFrom(GetGrid()->GetUnspecifiedValueAppearance());
|
||||
}
|
||||
|
||||
if ( cell->HasText() )
|
||||
if ( cell.HasText() )
|
||||
{
|
||||
*pString = cell->GetText();
|
||||
*pString = cell.GetText();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -792,23 +819,24 @@ void wxPGProperty::GetDisplayInfo( unsigned int column,
|
||||
|
||||
if ( choiceIndex != wxNOT_FOUND )
|
||||
{
|
||||
// Overrride default cell settings with
|
||||
// custom settings defined for choice item.
|
||||
const wxPGChoiceEntry& entry = m_choices[choiceIndex];
|
||||
if ( entry.GetBitmap().IsOk() ||
|
||||
entry.GetFgCol().IsOk() ||
|
||||
entry.GetBgCol().IsOk() )
|
||||
cell = &entry;
|
||||
cell.MergeFrom(entry);
|
||||
|
||||
*pString = m_choices.GetLabel(choiceIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if ( !cell )
|
||||
cell = &GetCell(column);
|
||||
|
||||
wxASSERT_MSG( cell->GetData(),
|
||||
wxASSERT_MSG( cell.GetData(),
|
||||
wxString::Format("Invalid cell for property %s",
|
||||
GetName().c_str()) );
|
||||
|
||||
*pCell = cell;
|
||||
// We need to return customized cell object.
|
||||
if (pCell)
|
||||
{
|
||||
*pCell = cell;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -798,9 +798,8 @@ int wxPropertyGridPageState::GetColumnFitWidth(wxClientDC& dc,
|
||||
wxPGProperty* p = pwc->Item(i);
|
||||
if ( !p->IsCategory() )
|
||||
{
|
||||
const wxPGCell* cell = NULL;
|
||||
wxString text;
|
||||
p->GetDisplayInfo(col, -1, 0, &text, &cell);
|
||||
p->GetDisplayInfo(col, -1, 0, &text, (wxPGCell*)NULL);
|
||||
dc.GetTextExtent(text, &w, &h);
|
||||
if ( col == 0 )
|
||||
w += ( ((int)p->m_depth-1) * pg->m_subgroup_extramargin );
|
||||
@ -834,9 +833,8 @@ int wxPropertyGridPageState::GetColumnFullWidth( wxClientDC &dc, wxPGProperty *p
|
||||
if ( p->IsCategory() )
|
||||
return 0;
|
||||
|
||||
const wxPGCell* cell = NULL;
|
||||
wxString text;
|
||||
p->GetDisplayInfo(col, -1, 0, &text, &cell);
|
||||
p->GetDisplayInfo(col, -1, 0, &text, (wxPGCell*)NULL);
|
||||
int w = dc.GetTextExtent(text).x;
|
||||
|
||||
if ( col == 0 )
|
||||
|
Loading…
Reference in New Issue
Block a user