diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index 75ed5a4ba7..088f442b7c 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -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 ) diff --git a/interface/wx/propgrid/property.h b/interface/wx/propgrid/property.h index a260a079ed..3f2fb7b985 100644 --- a/interface/wx/propgrid/property.h +++ b/interface/wx/propgrid/property.h @@ -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 diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index a818fa9cab..16dc91e8ab 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -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 ) diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 0d4046307e..1dd2855431 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -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 ) diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 05a4fdb65c..3fc4e31251 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -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; sim_colWidths.size(); si++ ) + for ( si=0; sim_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,111 +2349,148 @@ 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; cim_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; ciHasVisibleChildren() ) - DrawExpanderButton( dc, butRect, p ); + if ( !isCategory ) + cellRect.width -= 1; - // Background - if ( isSelected && (ci == 1 || ci == m_selColumn) ) + wxWindow* cellEditor = NULL; + int cellRenderFlags = renderFlags; + + // Tree Item Button (must be drawn before clipping is set up) + if ( ci == 0 && !HasFlag(wxPG_HIDE_MARGIN) && p->HasVisibleChildren() ) + DrawExpanderButton( dc, butRect, p ); + + // Background + if ( isSelected && (ci == 1 || ci == m_selColumn) ) + { + if ( p == firstSelected ) { - if ( p == firstSelected ) - { - if ( ci == 1 && m_wndEditor ) - cellEditor = m_wndEditor; - else if ( ci == m_selColumn && m_labelEditor ) - cellEditor = m_labelEditor; - } + if ( ci == 1 && m_wndEditor ) + cellEditor = m_wndEditor; + else if ( ci == m_selColumn && m_labelEditor ) + cellEditor = m_labelEditor; + } - if ( cellEditor ) - { - wxColour editorBgCol = - cellEditor->GetBackgroundColour(); - dc.SetBrush(editorBgCol); - dc.SetPen(editorBgCol); - dc.SetTextForeground(m_colPropFore); - dc.DrawRectangle(cellRect); + if ( cellEditor ) + { + wxColour editorBgCol = + cellEditor->GetBackgroundColour(); + dc.SetBrush(editorBgCol); + dc.SetPen(editorBgCol); + dc.SetTextForeground(m_colPropFore); + dc.DrawRectangle(cellRect); - if ( m_dragStatus != 0 || - (m_iFlags & wxPG_FL_CUR_USES_CUSTOM_IMAGE) ) - cellEditor = NULL; - } - else - { - dc.SetBrush(m_colPropBack); - dc.SetPen(m_colPropBack); - dc.SetTextForeground(m_colDisPropFore); - if ( p->IsEnabled() ) - dc.SetTextForeground(rowFgCol); - else - dc.SetTextForeground(m_colDisPropFore); - } + if ( m_dragStatus != 0 || + (m_iFlags & wxPG_FL_CUR_USES_CUSTOM_IMAGE) ) + cellEditor = NULL; } else { - if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol ) - { - dc.SetBrush(rowBgBrush); - dc.SetPen(rowBgCol); - } - - if ( renderFlags & wxPGCellRenderer::DontUseCellFgCol ) - { + dc.SetBrush(m_colPropBack); + dc.SetPen(m_colPropBack); + dc.SetTextForeground(m_colDisPropFore); + if ( p->IsEnabled() ) dc.SetTextForeground(rowFgCol); - } - } - - dc.SetClippingRegion(cellRect); - - cellRect.x += textXAdd; - cellRect.width -= textXAdd; - - // Foreground - if ( !cellEditor ) - { - wxPGCellRenderer* renderer; - int cmnVal = p->GetCommonValue(); - if ( cmnVal == -1 || ci != 1 ) - { - renderer = p->GetCellRenderer(ci); - renderer->Render( dc, cellRect, this, p, ci, -1, - cellRenderFlags ); - } else - { - renderer = GetCommonValue(cmnVal)->GetRenderer(); - renderer->Render( dc, cellRect, this, p, ci, -1, - cellRenderFlags ); - } + dc.SetTextForeground(m_colDisPropFore); + } + } + else + { + if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol ) + { + dc.SetBrush(rowBgBrush); + dc.SetPen(rowBgCol); } - 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; + if ( renderFlags & wxPGCellRenderer::DontUseCellFgCol ) + { + dc.SetTextForeground(rowFgCol); + } } + + dc.SetClippingRegion(cellRect); + + cellRect.x += textXAdd; + cellRect.width -= textXAdd; + + // Foreground + if ( !cellEditor ) + { + wxPGCellRenderer* renderer; + int cmnVal = p->GetCommonValue(); + if ( cmnVal == -1 || ci != 1 ) + { + renderer = p->GetCellRenderer(ci); + prevFilled = renderer->Render(dc, cellRect, this, + p, ci, -1, + cellRenderFlags ); + } + else + { + renderer = GetCommonValue(cmnVal)->GetRenderer(); + prevFilled = renderer->Render(dc, cellRect, this, + p, ci, -1, + cellRenderFlags ); + } + } + else + { + prevFilled = true; + } + + dc.DestroyClippingRegion(); // Is this really necessary? } + while ( ci > 0 ); if ( fontChanged ) dc.SetFont(normalFont);