Changed wxPropertyCategory to use same cell rendering code as regular properties. This allows labels for category columns other than the first. Rendering code was heavily modified to allow 'merging' of cells when needed.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63012 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -98,7 +98,11 @@ public:
|
||||
DontUseCellBgCol
|
||||
};
|
||||
|
||||
virtual void Render( wxDC& dc,
|
||||
/**
|
||||
Returns @true if rendered something in the foreground (text or
|
||||
bitmap.
|
||||
*/
|
||||
virtual bool Render( wxDC& dc,
|
||||
const wxRect& rect,
|
||||
const wxPropertyGrid* propertyGrid,
|
||||
wxPGProperty* property,
|
||||
@@ -171,7 +175,7 @@ public:
|
||||
class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer : public wxPGCellRenderer
|
||||
{
|
||||
public:
|
||||
virtual void Render( wxDC& dc,
|
||||
virtual bool Render( wxDC& dc,
|
||||
const wxRect& rect,
|
||||
const wxPropertyGrid* propertyGrid,
|
||||
wxPGProperty* property,
|
||||
@@ -2484,6 +2488,7 @@ public:
|
||||
int GetTextExtent( const wxWindow* wnd, const wxFont& font ) const;
|
||||
|
||||
virtual wxString ValueToString( wxVariant& value, int argFlags ) const;
|
||||
virtual wxString GetValueAsString( int argFlags = 0 ) const;
|
||||
|
||||
protected:
|
||||
void SetTextColIndex( unsigned int colInd )
|
||||
|
@@ -207,7 +207,10 @@
|
||||
@subsection wxPropertyCategory
|
||||
|
||||
Not an actual property per se, but a header for a group of properties.
|
||||
Regardless inherits from wxPGProperty.
|
||||
Regardless inherits from wxPGProperty, and supports displaying 'labels'
|
||||
for columns other than the first one. Easiest way to set category's
|
||||
label for second column is to call wxPGProperty::SetValue() with string
|
||||
argument.
|
||||
|
||||
@subsection wxStringProperty
|
||||
|
||||
|
@@ -1868,6 +1868,10 @@ void FormMain::PopulateWithLibraryConfig ()
|
||||
pid = pg->Append( new wxPropertyCategory( wxT("wxWidgets Library Configuration") ) );
|
||||
pg->SetPropertyCell( pid, 0, wxPG_LABEL, bmp );
|
||||
|
||||
// Both of following lines would set a label for the second column
|
||||
pg->SetPropertyCell( pid, 1, "Is Enabled" );
|
||||
pid->SetValue("Is Enabled");
|
||||
|
||||
ADD_WX_LIB_CONF_GROUP(wxT("Global Settings"))
|
||||
ADD_WX_LIB_CONF( wxUSE_GUI )
|
||||
|
||||
|
@@ -186,10 +186,14 @@ void wxPGCellRenderer::PostDrawCell( wxDC& dc,
|
||||
// wxPGDefaultRenderer
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
||||
bool wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
||||
const wxPropertyGrid* propertyGrid, wxPGProperty* property,
|
||||
int column, int item, int flags ) const
|
||||
{
|
||||
const wxPGEditor* editor = NULL;
|
||||
const wxPGCell* cell = NULL;
|
||||
|
||||
wxString text;
|
||||
bool isUnspecified = property->IsValueUnspecified();
|
||||
|
||||
if ( column == 1 && item == -1 )
|
||||
@@ -199,17 +203,19 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
||||
{
|
||||
// Common Value
|
||||
if ( !isUnspecified )
|
||||
DrawText( dc, rect, 0, propertyGrid->GetCommonValueLabel(cmnVal) );
|
||||
return;
|
||||
{
|
||||
text = propertyGrid->GetCommonValueLabel(cmnVal);
|
||||
DrawText( dc, rect, 0, text );
|
||||
if ( text.length() )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const wxPGEditor* editor = NULL;
|
||||
const wxPGCell* cell = NULL;
|
||||
|
||||
wxString text;
|
||||
int imageWidth = 0;
|
||||
int preDrawFlags = flags;
|
||||
bool res = false;
|
||||
|
||||
property->GetDisplayInfo(column, item, flags, &text, &cell);
|
||||
|
||||
@@ -262,6 +268,8 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
||||
text = property->GetHintText();
|
||||
if ( text.length() > 0 )
|
||||
{
|
||||
res = true;
|
||||
|
||||
const wxColour& hCol =
|
||||
propertyGrid->GetCellDisabledTextColour();
|
||||
dc.SetTextForeground(hCol);
|
||||
@@ -271,6 +279,10 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
||||
editor = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
|
||||
int imageOffset = property->GetImageOffset(imageWidth);
|
||||
@@ -278,7 +290,7 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
||||
DrawEditorValue( dc, rect, imageOffset, text, property, editor );
|
||||
|
||||
// active caption gets nice dotted rectangle
|
||||
if ( property->IsCategory() /*&& column == 0*/ )
|
||||
if ( property->IsCategory() && column == 0 )
|
||||
{
|
||||
if ( flags & Selected )
|
||||
{
|
||||
@@ -299,6 +311,8 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
||||
}
|
||||
|
||||
PostDrawCell(dc, propertyGrid, *cell, preDrawFlags);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
wxSize wxPGDefaultRenderer::GetImageSize( const wxPGProperty* property,
|
||||
@@ -2629,9 +2643,31 @@ wxPropertyCategory::~wxPropertyCategory()
|
||||
wxString wxPropertyCategory::ValueToString( wxVariant& WXUNUSED(value),
|
||||
int WXUNUSED(argFlags) ) const
|
||||
{
|
||||
if ( m_value.GetType() == wxPG_VARIANT_TYPE_STRING )
|
||||
return m_value.GetString();
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
wxString wxPropertyCategory::GetValueAsString( int argFlags ) const
|
||||
{
|
||||
#if wxPG_COMPATIBILITY_1_4
|
||||
// This is backwards compatibility test
|
||||
// That is, to make sure this function is not overridden
|
||||
// (instead, ValueToString() should be).
|
||||
if ( argFlags == 0xFFFF )
|
||||
{
|
||||
// Do not override! (for backwards compliancy)
|
||||
return g_invalidStringContent;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Unspecified value is always empty string
|
||||
if ( IsValueUnspecified() )
|
||||
return wxEmptyString;
|
||||
|
||||
return wxPGProperty::GetValueAsString(argFlags);
|
||||
}
|
||||
|
||||
int wxPropertyCategory::GetTextExtent( const wxWindow* wnd, const wxFont& font ) const
|
||||
{
|
||||
if ( m_textExtent > 0 )
|
||||
|
@@ -2123,6 +2123,7 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc,
|
||||
|
||||
const wxPGProperty* firstSelected = GetSelection();
|
||||
const wxPropertyGridPageState* state = m_pState;
|
||||
const wxArrayInt& colWidths = state->m_colWidths;
|
||||
|
||||
#if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
|
||||
bool wasSelectedPainted = false;
|
||||
@@ -2222,9 +2223,9 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc,
|
||||
unsigned int si;
|
||||
int sx = x;
|
||||
|
||||
for ( si=0; si<state->m_colWidths.size(); si++ )
|
||||
for ( si=0; si<colWidths.size(); si++ )
|
||||
{
|
||||
sx += state->m_colWidths[si];
|
||||
sx += colWidths[si];
|
||||
dc.DrawLine( sx, y, sx, y2 );
|
||||
}
|
||||
|
||||
@@ -2320,12 +2321,16 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc,
|
||||
m_marginWidth,
|
||||
lh );
|
||||
|
||||
if ( p->IsCategory() )
|
||||
// Default cell rect fill the entire row
|
||||
wxRect cellRect(greyDepthX, y,
|
||||
gridWidth - greyDepth + 2, rowHeight-1 );
|
||||
|
||||
bool isCategory = p->IsCategory();
|
||||
|
||||
if ( isCategory )
|
||||
{
|
||||
// Captions have their cell areas merged as one
|
||||
dc.SetFont(m_captionFont);
|
||||
fontChanged = true;
|
||||
wxRect cellRect(greyDepthX, y, gridWidth - greyDepth + 2, rowHeight-1 );
|
||||
|
||||
if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol )
|
||||
{
|
||||
@@ -2337,13 +2342,6 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc,
|
||||
{
|
||||
dc.SetTextForeground(rowFgCol);
|
||||
}
|
||||
|
||||
wxPGCellRenderer* renderer = p->GetCellRenderer(0);
|
||||
renderer->Render( dc, cellRect, this, p, 0, -1, renderFlags );
|
||||
|
||||
// Tree Item Button
|
||||
if ( !HasFlag(wxPG_HIDE_MARGIN) && p->HasVisibleChildren() )
|
||||
DrawExpanderButton( dc, butRect, p );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2351,22 +2349,58 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc,
|
||||
if ( butRect.x > 0 )
|
||||
butRect.x += IN_CELL_EXPANDER_BUTTON_X_ADJUST;
|
||||
|
||||
if ( p->m_flags & wxPG_PROP_MODIFIED && (windowStyle & wxPG_BOLD_MODIFIED) )
|
||||
if ( p->m_flags & wxPG_PROP_MODIFIED &&
|
||||
(windowStyle & wxPG_BOLD_MODIFIED) )
|
||||
{
|
||||
dc.SetFont(m_captionFont);
|
||||
fontChanged = true;
|
||||
}
|
||||
|
||||
unsigned int ci;
|
||||
int cellX = x + 1;
|
||||
int nextCellWidth = state->m_colWidths[0] -
|
||||
(greyDepthX - m_marginWidth);
|
||||
wxRect cellRect(greyDepthX+1, y, 0, rowHeight-1);
|
||||
int textXAdd = textMarginHere - greyDepthX;
|
||||
// Magic fine-tuning for non-category rows
|
||||
cellRect.x += 1;
|
||||
}
|
||||
|
||||
for ( ci=0; ci<state->m_colWidths.size(); ci++ )
|
||||
int firstCellWidth = colWidths[0] - (greyDepthX - m_marginWidth);
|
||||
int firstCellX = cellRect.x;
|
||||
|
||||
// Calculate cellRect.x for the last cell
|
||||
unsigned int ci = 0;
|
||||
int cellX = x + 1;
|
||||
for ( ci=0; ci<colWidths.size(); ci++ )
|
||||
cellX += colWidths[ci];
|
||||
cellRect.x = cellX;
|
||||
|
||||
// Draw cells from back to front so that we can easily tell if the
|
||||
// cell on the right was empty from text
|
||||
bool prevFilled = true;
|
||||
ci = colWidths.size();
|
||||
do
|
||||
{
|
||||
cellRect.width = nextCellWidth - 1;
|
||||
ci--;
|
||||
|
||||
int textXAdd = 0;
|
||||
|
||||
if ( ci == 0 )
|
||||
{
|
||||
textXAdd = textMarginHere - greyDepthX;
|
||||
cellRect.width = firstCellWidth;
|
||||
cellRect.x = firstCellX;
|
||||
}
|
||||
else
|
||||
{
|
||||
int colWidth = colWidths[ci];
|
||||
cellRect.width = colWidth;
|
||||
cellRect.x -= colWidth;
|
||||
}
|
||||
|
||||
// Merge with column to the right?
|
||||
if ( !prevFilled && isCategory )
|
||||
{
|
||||
cellRect.width += colWidths[ci+1];
|
||||
}
|
||||
|
||||
if ( !isCategory )
|
||||
cellRect.width -= 1;
|
||||
|
||||
wxWindow* cellEditor = NULL;
|
||||
int cellRenderFlags = renderFlags;
|
||||
@@ -2437,25 +2471,26 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc,
|
||||
if ( cmnVal == -1 || ci != 1 )
|
||||
{
|
||||
renderer = p->GetCellRenderer(ci);
|
||||
renderer->Render( dc, cellRect, this, p, ci, -1,
|
||||
prevFilled = renderer->Render(dc, cellRect, this,
|
||||
p, ci, -1,
|
||||
cellRenderFlags );
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer = GetCommonValue(cmnVal)->GetRenderer();
|
||||
renderer->Render( dc, cellRect, this, p, ci, -1,
|
||||
prevFilled = renderer->Render(dc, cellRect, this,
|
||||
p, ci, -1,
|
||||
cellRenderFlags );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
prevFilled = true;
|
||||
}
|
||||
|
||||
cellX += state->m_colWidths[ci];
|
||||
if ( ci < (state->m_colWidths.size()-1) )
|
||||
nextCellWidth = state->m_colWidths[ci+1];
|
||||
cellRect.x = cellX;
|
||||
dc.DestroyClippingRegion(); // Is this really necessary?
|
||||
textXAdd = 0;
|
||||
}
|
||||
}
|
||||
while ( ci > 0 );
|
||||
|
||||
if ( fontChanged )
|
||||
dc.SetFont(normalFont);
|
||||
|
Reference in New Issue
Block a user