X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/39e4e221dd6e6baed4bc901c1aa78f91149ac984..8eca1205e2ddc9b24289c655b609ebdbd7bb853e:/src/propgrid/propgrid.cpp diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 92af9d017b..7e38cfb439 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -115,6 +115,11 @@ //#define wxPG_TOOLTIP_DELAY 1000 +// This is the number of pixels the expander button inside +// property cells (i.e. not in the grey margin area are +// adjusted. +#define IN_CELL_EXPANDER_BUTTON_X_ADJUST 2 + // ----------------------------------------------------------------------- #if wxUSE_INTL @@ -195,7 +200,10 @@ wxPGGlobalVarsClass::wxPGGlobalVarsClass() m_strMin = wxS("Min"); m_strMax = wxS("Max"); m_strUnits = wxS("Units"); + m_strHint = wxS("Hint"); +#if wxPG_COMPATIBILITY_1_4 m_strInlineHelp = wxS("InlineHelp"); +#endif m_warnings = 0; } @@ -340,6 +348,9 @@ void wxPropertyGrid::Init1() m_mouseSide = 16; m_editorFocused = 0; + // Set up default unspecified value 'colour' + m_unspecifiedAppearance.SetFgCol(*wxLIGHT_GREY); + // Set default keys AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RIGHT ); AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_DOWN ); @@ -406,7 +417,7 @@ void wxPropertyGrid::Init2() } if ( !(m_windowStyle & wxPG_SPLITTER_AUTO_CENTER) ) - m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER; + m_pState->m_dontCenterSplitter = true; if ( m_windowStyle & wxPG_HIDE_CATEGORIES ) { @@ -436,9 +447,9 @@ void wxPropertyGrid::Init2() CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING ); - // Allocate cell datas indirectly by calling setter - m_propertyDefaultCell.SetBgCol(*wxBLACK); - m_categoryDefaultCell.SetBgCol(*wxBLACK); + // Allocate cell datas + m_propertyDefaultCell.SetEmptyData(); + m_categoryDefaultCell.SetEmptyData(); RegainColours(); @@ -662,7 +673,7 @@ void wxPropertyGrid::Thaw() // Force property re-selection // NB: We must copy the selection. wxArrayPGProperty selection = m_pState->m_selection; - DoSetSelection(selection, wxPG_SEL_FORCE); + DoSetSelection(selection, wxPG_SEL_FORCE | wxPG_SEL_NONVISIBLE); } } @@ -774,9 +785,12 @@ bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty* prop, wxMouseEvent* mouseEvent, int selFlags ) { + const wxArrayPGProperty& selection = GetSelectedProperties(); bool alreadySelected = m_pState->DoIsPropertySelected(prop); bool res = true; - bool addToExistingSelection; + + // Set to 2 if also add all items in between + int addToExistingSelection = 0; if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION ) { @@ -794,21 +808,24 @@ bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty* prop, } else { - addToExistingSelection = mouseEvent->ShiftDown(); + if ( mouseEvent->ControlDown() ) + { + addToExistingSelection = 1; + } + else if ( mouseEvent->ShiftDown() ) + { + if ( selection.size() > 0 && !prop->IsCategory() ) + addToExistingSelection = 2; + else + addToExistingSelection = 1; + } } } - else - { - addToExistingSelection = false; - } - } - else - { - addToExistingSelection = false; } - if ( addToExistingSelection ) + if ( addToExistingSelection == 1 ) { + // Add/remove one if ( !alreadySelected ) { res = DoAddToSelection(prop, selFlags); @@ -818,6 +835,59 @@ bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty* prop, res = DoRemoveFromSelection(prop, selFlags); } } + else if ( addToExistingSelection == 2 ) + { + // Add this, and all in between + + // Find top selected property + wxPGProperty* topSelProp = selection[0]; + int topSelPropY = topSelProp->GetY(); + for ( unsigned int i=1; iGetY(); + if ( y < topSelPropY ) + { + topSelProp = p; + topSelPropY = y; + } + } + + wxPGProperty* startFrom; + wxPGProperty* stopAt; + + if ( prop->GetY() <= topSelPropY ) + { + // Property is above selection (or same) + startFrom = prop; + stopAt = topSelProp; + } + else + { + // Property is below selection + startFrom = topSelProp; + stopAt = prop; + } + + // Iterate through properties in-between, and select them + wxPropertyGridIterator it; + + for ( it = GetIterator(wxPG_ITERATE_VISIBLE, startFrom); + !it.AtEnd(); + it++ ) + { + wxPGProperty* p = *it; + + if ( !p->IsCategory() && + !m_pState->DoIsPropertySelected(p) ) + { + DoAddToSelection(p, selFlags); + } + + if ( p == stopAt ) + break; + } + } else { res = DoSelectAndEdit(prop, colIndex, selFlags); @@ -1320,6 +1390,8 @@ void wxPropertyGrid::RegainColours() wxColour bgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ); m_colPropBack = bgCol; m_propertyDefaultCell.GetData()->SetBgCol(bgCol); + if ( !m_unspecifiedAppearance.GetBgCol().IsOk() ) + m_unspecifiedAppearance.SetBgCol(bgCol); } if ( !(m_coloursCustomized & 0x0010) ) @@ -1327,6 +1399,8 @@ void wxPropertyGrid::RegainColours() wxColour fgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); m_colPropFore = fgCol; m_propertyDefaultCell.GetData()->SetFgCol(fgCol); + if ( !m_unspecifiedAppearance.GetFgCol().IsOk() ) + m_unspecifiedAppearance.SetFgCol(fgCol); } if ( !(m_coloursCustomized & 0x0020) ) @@ -1398,6 +1472,7 @@ void wxPropertyGrid::SetCellBackgroundColour( const wxColour& col ) m_coloursCustomized |= 0x08; m_propertyDefaultCell.GetData()->SetBgCol(col); + m_unspecifiedAppearance.SetBgCol(col); Refresh(); } @@ -1410,6 +1485,7 @@ void wxPropertyGrid::SetCellTextColour( const wxColour& col ) m_coloursCustomized |= 0x10; m_propertyDefaultCell.GetData()->SetFgCol(col); + m_unspecifiedAppearance.SetFgCol(col); Refresh(); } @@ -1488,6 +1564,9 @@ void wxPropertyGrid::PrepareAfterItemsAdded() Sort(wxPG_SORT_TOP_LEVEL_ONLY); RecalculateVirtualSize(); + + // Fix editor position + CorrectEditorWidgetPosY(); } // ----------------------------------------------------------------------- @@ -1740,9 +1819,8 @@ void wxPropertyGrid::OnPaint( wxPaintEvent& WXUNUSED(event) ) // FIXME: This is just a workaround for a bug that causes splitters not // to paint when other windows are being dragged over the grid. - wxRect fullRect = GetRect(); - r.x = fullRect.x; - r.width = fullRect.width; + r.x = 0; + r.width = GetClientSize().x; // Repaint this rectangle DrawItems( dc, r.y, r.y + r.height, &r ); @@ -1831,20 +1909,25 @@ void wxPropertyGrid::DrawExpanderButton( wxDC& dc, const wxRect& rect, // topy and bottomy are already unscrolled (ie. physical) // void wxPropertyGrid::DrawItems( wxDC& dc, - unsigned int topy, - unsigned int bottomy, - const wxRect* clipRect ) -{ - if ( m_frozen || m_height < 1 || bottomy < topy || !m_pState ) + unsigned int topItemY, + unsigned int bottomItemY, + const wxRect* drawRect ) +{ + if ( m_frozen || + m_height < 1 || + bottomItemY < topItemY || + !m_pState ) return; m_pState->EnsureVirtualHeight(); - wxRect tempClipRect; - if ( !clipRect ) + wxRect tempDrawRect; + if ( !drawRect ) { - tempClipRect = wxRect(0,topy,m_pState->m_width,bottomy); - clipRect = &tempClipRect; + tempDrawRect = wxRect(0, topItemY, + m_pState->m_width, + bottomItemY); + drawRect = &tempDrawRect; } // items added check @@ -1864,7 +1947,7 @@ void wxPropertyGrid::DrawItems( wxDC& dc, { if ( !m_doubleBuffer ) { - paintFinishY = clipRect->y; + paintFinishY = drawRect->y; dcPtr = NULL; } else @@ -1882,26 +1965,29 @@ void wxPropertyGrid::DrawItems( wxDC& dc, if ( dcPtr ) { - dc.SetClippingRegion( *clipRect ); - paintFinishY = DoDrawItems( *dcPtr, clipRect, isBuffered ); + dc.SetClippingRegion( *drawRect ); + paintFinishY = DoDrawItems( *dcPtr, drawRect, isBuffered ); + int drawBottomY = drawRect->y + drawRect->height; - // Clear area beyond bottomY? - if ( paintFinishY < (clipRect->y+clipRect->height) ) + // Clear area beyond last painted property + if ( paintFinishY < drawBottomY ) { dcPtr->SetPen(m_colEmptySpace); dcPtr->SetBrush(m_colEmptySpace); - dcPtr->DrawRectangle( 0, paintFinishY, m_width, - (clipRect->y+clipRect->height) ); + dcPtr->DrawRectangle(0, paintFinishY, + m_width, + drawBottomY ); } + + dc.DestroyClippingRegion(); } #if wxPG_DOUBLE_BUFFER if ( bufferDC ) { - dc.Blit( clipRect->x, clipRect->y, clipRect->width, - clipRect->height, + dc.Blit( drawRect->x, drawRect->y, drawRect->width, + drawRect->height, bufferDC, 0, 0, wxCOPY ); - dc.DestroyClippingRegion(); // Is this really necessary? delete bufferDC; } #endif @@ -1911,29 +1997,30 @@ void wxPropertyGrid::DrawItems( wxDC& dc, // Just clear the area dc.SetPen(m_colEmptySpace); dc.SetBrush(m_colEmptySpace); - dc.DrawRectangle(*clipRect); + dc.DrawRectangle(*drawRect); } } // ----------------------------------------------------------------------- int wxPropertyGrid::DoDrawItems( wxDC& dc, - const wxRect* clipRect, + const wxRect* drawRect, bool isBuffered ) const { const wxPGProperty* firstItem; const wxPGProperty* lastItem; - firstItem = DoGetItemAtY(clipRect->y); - lastItem = DoGetItemAtY(clipRect->y+clipRect->height-1); + firstItem = DoGetItemAtY(drawRect->y); + lastItem = DoGetItemAtY(drawRect->y+drawRect->height-1); if ( !lastItem ) lastItem = GetLastItem( wxPG_ITERATE_VISIBLE ); if ( m_frozen || m_height < 1 || firstItem == NULL ) - return clipRect->y; + return drawRect->y; - wxCHECK_MSG( !m_pState->m_itemsAdded, clipRect->y, wxT("no items added") ); + wxCHECK_MSG( !m_pState->m_itemsAdded, drawRect->y, + "no items added" ); wxASSERT( m_pState->m_properties->GetChildCount() ); int lh = m_lineHeight; @@ -1941,8 +2028,8 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc, int firstItemTopY; int lastItemBottomY; - firstItemTopY = clipRect->y; - lastItemBottomY = clipRect->y + clipRect->height; + firstItemTopY = drawRect->y; + lastItemBottomY = drawRect->y + drawRect->height; // Align y coordinates to item boundaries firstItemTopY -= firstItemTopY % lh; @@ -1950,19 +2037,22 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc, lastItemBottomY -= 1; // Entire range outside scrolled, visible area? - if ( firstItemTopY >= (int)m_pState->GetVirtualHeight() || lastItemBottomY <= 0 ) - return clipRect->y; - - wxCHECK_MSG( firstItemTopY < lastItemBottomY, clipRect->y, wxT("invalid y values") ); + if ( firstItemTopY >= (int)m_pState->GetVirtualHeight() || + lastItemBottomY <= 0 ) + return drawRect->y; + wxCHECK_MSG( firstItemTopY < lastItemBottomY, + drawRect->y, + "invalid y values" ); /* - wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"), + wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\" + "height=%i (ch=%i), drawRect = 0x%lX )", firstItem->GetLabel().c_str(), lastItem->GetLabel().c_str(), (int)(lastItemBottomY - firstItemTopY), (int)m_height, - (unsigned long)clipRect ); + (unsigned long)drawRect ); */ wxRect r; @@ -1970,27 +2060,27 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc, long windowStyle = m_windowStyle; int xRelMod = 0; - int yRelMod = 0; // // With wxPG_DOUBLE_BUFFER, do double buffering - // - buffer's y = 0, so align cliprect and coordinates to that + // - buffer's y = 0, so align drawRect and coordinates to that // #if wxPG_DOUBLE_BUFFER + int yRelMod = 0; wxRect cr2; if ( isBuffered ) { - xRelMod = clipRect->x; - yRelMod = clipRect->y; + xRelMod = drawRect->x; + yRelMod = drawRect->y; // - // clipRect conversion - cr2 = *clipRect; + // drawRect conversion + cr2 = *drawRect; cr2.x -= xRelMod; cr2.y -= yRelMod; - clipRect = &cr2; + drawRect = &cr2; firstItemTopY -= yRelMod; lastItemBottomY -= yRelMod; } @@ -2036,6 +2126,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; @@ -2135,9 +2226,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 ); } @@ -2233,12 +2324,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 ) { @@ -2250,121 +2345,154 @@ 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 { - if ( p->m_flags & wxPG_PROP_MODIFIED && (windowStyle & wxPG_BOLD_MODIFIED) ) + // Fine tune button rectangle to actually fit the cell + if ( butRect.x > 0 ) + butRect.x += IN_CELL_EXPANDER_BUTTON_X_ADJUST; + + 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; + } + + 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; cim_colWidths.size(); ci++ ) + // Merge with column to the right? + if ( !prevFilled && isCategory ) { - cellRect.width = nextCellWidth - 1; + cellRect.width += colWidths[ci+1]; + } + + if ( !isCategory ) + cellRect.width -= 1; - wxWindow* cellEditor = NULL; - int cellRenderFlags = renderFlags; + 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 ); + // 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) ) + // 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); + 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); + if ( p->IsEnabled() ) 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); - } } - else + } + else + { + if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol ) { - if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol ) - { - dc.SetBrush(rowBgBrush); - dc.SetPen(rowBgCol); - } + dc.SetBrush(rowBgBrush); + dc.SetPen(rowBgCol); + } - if ( renderFlags & wxPGCellRenderer::DontUseCellFgCol ) - { - dc.SetTextForeground(rowFgCol); - } + if ( renderFlags & wxPGCellRenderer::DontUseCellFgCol ) + { + dc.SetTextForeground(rowFgCol); } + } - dc.SetClippingRegion(cellRect); + dc.SetClippingRegion(cellRect); - cellRect.x += textXAdd; - cellRect.width -= textXAdd; + cellRect.x += textXAdd; + cellRect.width -= textXAdd; - // Foreground - if ( !cellEditor ) + // Foreground + if ( !cellEditor ) + { + wxPGCellRenderer* renderer; + int cmnVal = p->GetCommonValue(); + if ( cmnVal == -1 || ci != 1 ) { - 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 ); - } + renderer = p->GetCellRenderer(ci); + prevFilled = renderer->Render(dc, cellRect, this, + p, ci, -1, + cellRenderFlags ); } - - 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; + 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); @@ -2384,7 +2512,7 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc, } #endif - return y + yRelMod; + return y; } // ----------------------------------------------------------------------- @@ -2622,10 +2750,11 @@ void wxPropertyGrid::SwitchState( wxPropertyGridPageState* pNewState ) { // // Just in case, fully re-center splitter - if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) ) - pNewState->m_fSplitterX = -1.0; + //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) ) + // pNewState->m_fSplitterX = -1.0; - pNewState->OnClientWidthChange( pgWidth, pgWidth - pNewState->m_width ); + pNewState->OnClientWidthChange(pgWidth, + pgWidth - pNewState->m_width); } m_propHover = NULL; @@ -2656,31 +2785,50 @@ void wxPropertyGrid::SwitchState( wxPropertyGridPageState* pNewState ) // Call to SetSplitterPosition will always disable splitter auto-centering // if parent window is shown. -void wxPropertyGrid::DoSetSplitterPosition_( int newxpos, bool refresh, int splitterIndex, bool allPages ) +void wxPropertyGrid::DoSetSplitterPosition( int newxpos, + int splitterIndex, + int flags ) { if ( ( newxpos < wxPG_DRAG_MARGIN ) ) return; wxPropertyGridPageState* state = m_pState; - state->DoSetSplitterPosition( newxpos, splitterIndex, allPages ); + if ( flags & wxPG_SPLITTER_FROM_EVENT ) + state->m_dontCenterSplitter = true; + + state->DoSetSplitterPosition(newxpos, splitterIndex, flags); - if ( refresh ) + if ( flags & wxPG_SPLITTER_REFRESH ) { if ( GetSelection() ) CorrectEditorWidgetSizeX(); Refresh(); } + + return; +} + +// ----------------------------------------------------------------------- + +void wxPropertyGrid::ResetColumnSizes( bool enableAutoResizing ) +{ + wxPropertyGridPageState* state = m_pState; + if ( state ) + state->ResetColumnSizes(0); + + if ( enableAutoResizing && HasFlag(wxPG_SPLITTER_AUTO_CENTER) ) + m_pState->m_dontCenterSplitter = false; } // ----------------------------------------------------------------------- -void wxPropertyGrid::CenterSplitter( bool enableAutoCentering ) +void wxPropertyGrid::CenterSplitter( bool enableAutoResizing ) { - SetSplitterPosition( m_width/2, true ); - if ( enableAutoCentering && ( m_windowStyle & wxPG_SPLITTER_AUTO_CENTER ) ) - m_iFlags &= ~(wxPG_FL_DONT_CENTER_SPLITTER); + SetSplitterPosition( m_width/2 ); + if ( enableAutoResizing && HasFlag(wxPG_SPLITTER_AUTO_CENTER) ) + m_pState->m_dontCenterSplitter = false; } // ----------------------------------------------------------------------- @@ -3255,6 +3403,12 @@ bool wxPropertyGrid::DoEditorValidate() void wxPropertyGrid::HandleCustomEditorEvent( wxEvent &event ) { + // It is possible that this handler receives event even before + // the control has been properly initialized. Let's skip the + // event handling in that case. + if ( !m_pState ) + return; + wxPGProperty* selected = GetSelection(); // Somehow, event is handled after property has been deselected. @@ -3284,17 +3438,26 @@ void wxPropertyGrid::HandleCustomEditorEvent( wxEvent &event ) // // Filter out excess wxTextCtrl modified events - if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED && - wnd && - wnd->IsKindOf(CLASSINFO(wxTextCtrl)) ) + if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED && wnd ) { - wxTextCtrl* tc = (wxTextCtrl*) wnd; + if ( wnd->IsKindOf(CLASSINFO(wxTextCtrl)) ) + { + wxTextCtrl* tc = (wxTextCtrl*) wnd; - wxString newTcValue = tc->GetValue(); - if ( m_prevTcValue == newTcValue ) - return; + wxString newTcValue = tc->GetValue(); + if ( m_prevTcValue == newTcValue ) + return; + m_prevTcValue = newTcValue; + } + else if ( wnd->IsKindOf(CLASSINFO(wxComboCtrl)) ) + { + wxComboCtrl* cc = (wxComboCtrl*) wnd; - m_prevTcValue = newTcValue; + wxString newTcValue = cc->GetTextCtrl()->GetValue(); + if ( m_prevTcValue == newTcValue ) + return; + m_prevTcValue = newTcValue; + } } SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT); @@ -3527,6 +3690,21 @@ void wxPropertyGrid::CustomSetCursor( int type, bool override ) m_curcursor = type; } +// ----------------------------------------------------------------------- + +wxString +wxPropertyGrid::GetUnspecifiedValueText( int argFlags ) const +{ + const wxPGCell& ua = GetUnspecifiedValueAppearance(); + + if ( ua.HasText() && + !(argFlags & wxPG_FULL_VALUE) && + !(argFlags & wxPG_EDITABLE_VALUE) ) + return ua.GetText(); + + return wxEmptyString; +} + // ----------------------------------------------------------------------- // wxPropertyGrid property selection, editor creation // ----------------------------------------------------------------------- @@ -3553,6 +3731,13 @@ private: m_propGrid->HandleCustomEditorEvent(event); + // + // NB: On wxMSW, a wxTextCtrl with wxTE_PROCESS_ENTER + // may beep annoyingly if that event is skipped + // and passed to parent event handler. + if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER ) + return true; + return wxEvtHandler::ProcessEvent(event); } @@ -3808,6 +3993,9 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags ) wxRect grect = GetEditorWidgetRect(p, m_selColumn); wxPoint goodPos = grect.GetPosition(); + // Editor appearance can now be considered clear + m_editorAppearance.SetEmptyData(); + const wxPGEditor* editor = p->GetEditorClass(); wxCHECK_MSG(editor, false, wxT("NULL editor class not allowed")); @@ -3877,6 +4065,12 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags ) p->GetEditorClass()->OnFocus(p, primaryCtrl); } + else + { + if ( p->IsValueUnspecified() ) + SetEditorAppearance(m_unspecifiedAppearance, + true); + } } if ( m_wndEditor2 ) @@ -4043,7 +4237,7 @@ void wxPropertyGrid::RefreshEditor() editorClass->UpdateControl(p, wnd); if ( p->IsValueUnspecified() ) - editorClass ->SetValueToUnspecified(p, wnd); + SetEditorAppearance(m_unspecifiedAppearance, true); } // ----------------------------------------------------------------------- @@ -4075,8 +4269,8 @@ bool wxPropertyGrid::DoCollapse( wxPGProperty* p, bool sendEvents ) } // Store dont-center-splitter flag 'cause we need to temporarily set it - wxUint32 old_flag = m_iFlags & wxPG_FL_DONT_CENTER_SPLITTER; - m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER; + bool prevDontCenterSplitter = m_pState->m_dontCenterSplitter; + m_pState->m_dontCenterSplitter = true; bool res = m_pState->DoCollapse(pwc); @@ -4086,20 +4280,10 @@ bool wxPropertyGrid::DoCollapse( wxPGProperty* p, bool sendEvents ) SendEvent( wxEVT_PG_ITEM_COLLAPSED, p ); RecalculateVirtualSize(); - - // Redraw etc. only if collapsed was visible. - if (pwc->IsVisible() && - !m_frozen && - ( !pwc->IsCategory() || !(m_windowStyle & wxPG_HIDE_CATEGORIES) ) ) - { - // When item is collapsed so that scrollbar would move, - // graphics mess is about (unless we redraw everything). - Refresh(); - } + Refresh(); } - // Clear dont-center-splitter flag if it wasn't set - m_iFlags = (m_iFlags & ~wxPG_FL_DONT_CENTER_SPLITTER) | old_flag; + m_pState->m_dontCenterSplitter = prevDontCenterSplitter; return res; } @@ -4113,8 +4297,8 @@ bool wxPropertyGrid::DoExpand( wxPGProperty* p, bool sendEvents ) wxPGProperty* pwc = (wxPGProperty*)p; // Store dont-center-splitter flag 'cause we need to temporarily set it - wxUint32 old_flag = m_iFlags & wxPG_FL_DONT_CENTER_SPLITTER; - m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER; + bool prevDontCenterSplitter = m_pState->m_dontCenterSplitter; + m_pState->m_dontCenterSplitter = true; bool res = m_pState->DoExpand(pwc); @@ -4124,23 +4308,10 @@ bool wxPropertyGrid::DoExpand( wxPGProperty* p, bool sendEvents ) SendEvent( wxEVT_PG_ITEM_EXPANDED, p ); RecalculateVirtualSize(); - - // Redraw etc. only if expanded was visible. - if ( pwc->IsVisible() && !m_frozen && - ( !pwc->IsCategory() || !(m_windowStyle & wxPG_HIDE_CATEGORIES) ) - ) - { - // Redraw - #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT - Refresh(); - #else - DrawItems(pwc, NULL); - #endif - } + Refresh(); } - // Clear dont-center-splitter flag if it wasn't set - m_iFlags = (m_iFlags & ~wxPG_FL_DONT_CENTER_SPLITTER) | old_flag; + m_pState->m_dontCenterSplitter = prevDontCenterSplitter; return res; } @@ -4180,7 +4351,11 @@ bool wxPropertyGrid::DoHideProperty( wxPGProperty* p, bool hide, int flags ) void wxPropertyGrid::RecalculateVirtualSize( int forceXPos ) { - if ( (m_iFlags & wxPG_FL_RECALCULATING_VIRTUAL_SIZE) || m_frozen ) + // Don't check for !HasInternalFlag(wxPG_FL_INITIALIZED) here. Otherwise + // virtual size calculation may go wrong. + if ( HasInternalFlag(wxPG_FL_RECALCULATING_VIRTUAL_SIZE) || + m_frozen || + !m_pState ) return; // @@ -4342,6 +4517,9 @@ bool wxPropertyGrid::SendEvent( int eventType, wxPGProperty* p, unsigned int selFlags, unsigned int column ) { + // selFlags should have wxPG_SEL_NOVALIDATE if event is not + // vetoable. + // Send property grid event of specific type and with specific property wxPropertyGridEvent evt( eventType, m_eventObject->GetId() ); evt.SetPropertyGrid(this); @@ -4364,9 +4542,10 @@ bool wxPropertyGrid::SendEvent( int eventType, wxPGProperty* p, evt.SetCanVeto(true); } + wxPropertyGridEvent* prevProcessedEvent = m_processedEvent; m_processedEvent = &evt; m_eventObject->HandleWindowEvent(evt); - m_processedEvent = NULL; + m_processedEvent = prevProcessedEvent; return evt.WasVetoed(); } @@ -4465,7 +4644,16 @@ bool wxPropertyGrid::HandleMouseClick( int x, unsigned int y, wxMouseEvent &even if ( event.GetEventType() == wxEVT_LEFT_DCLICK ) { // Double-clicking the splitter causes auto-centering - CenterSplitter( true ); + if ( m_pState->GetColumnCount() <= 2 ) + { + ResetColumnSizes( true ); + + SendEvent(wxEVT_PG_COL_DRAGGING, + m_propHover, + NULL, + wxPG_SEL_NOVALIDATE, + (unsigned int)m_draggedSplitter); + } } else if ( m_dragStatus == 0 ) { @@ -4476,33 +4664,39 @@ bool wxPropertyGrid::HandleMouseClick( int x, unsigned int y, wxMouseEvent &even // send event DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE); - if ( m_wndEditor ) + // Allow application to veto dragging + if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG, + p, NULL, 0, + (unsigned int)splitterHit) ) { - // Changes must be committed here or the - // value won't be drawn correctly - if ( !CommitChangesFromEditor() ) - return res; + if ( m_wndEditor ) + { + // Changes must be committed here or the + // value won't be drawn correctly + if ( !CommitChangesFromEditor() ) + return res; - m_wndEditor->Show ( false ); - } + m_wndEditor->Show ( false ); + } - if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) ) - { - CaptureMouse(); - m_iFlags |= wxPG_FL_MOUSE_CAPTURED; - } + if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) ) + { + CaptureMouse(); + m_iFlags |= wxPG_FL_MOUSE_CAPTURED; + } - m_dragStatus = 1; - m_draggedSplitter = splitterHit; - m_dragOffset = splitterHitOffset; + m_dragStatus = 1; + m_draggedSplitter = splitterHit; + m_dragOffset = splitterHitOffset; - #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT - // Fixes button disappearance bug - if ( m_wndEditor2 ) - m_wndEditor2->Show ( false ); - #endif + #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT + // Fixes button disappearance bug + if ( m_wndEditor2 ) + m_wndEditor2->Show ( false ); + #endif - m_startingSplitterX = x - splitterHitOffset; + m_startingSplitterX = x - splitterHitOffset; + } } } } @@ -4514,6 +4708,10 @@ bool wxPropertyGrid::HandleMouseClick( int x, unsigned int y, wxMouseEvent &even { int nx = x + m_marginWidth - marginEnds; // Normalize x. + // Fine tune cell button x + if ( !p->IsCategory() ) + nx -= IN_CELL_EXPANDER_BUTTON_X_ADJUST; + if ( (nx >= m_gutterWidth && nx < (m_gutterWidth+m_iconWidth)) ) { int y2 = y % m_lineHeight; @@ -4629,17 +4827,16 @@ bool wxPropertyGrid::HandleMouseMove( int x, unsigned int y, if ( newSplitterX != splitterX ) { // Move everything - SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER); - state->DoSetSplitterPosition(newSplitterX, - m_draggedSplitter, - false); - state->m_fSplitterX = (float) newSplitterX; - - if ( GetSelection() ) - CorrectEditorWidgetSizeX(); - - Update(); - Refresh(); + DoSetSplitterPosition(newSplitterX, + m_draggedSplitter, + wxPG_SPLITTER_REFRESH | + wxPG_SPLITTER_FROM_EVENT); + + SendEvent(wxEVT_PG_COL_DRAGGING, + m_propHover, + NULL, + wxPG_SEL_NOVALIDATE, + (unsigned int)m_draggedSplitter); } m_dragStatus = 2; @@ -4857,8 +5054,20 @@ bool wxPropertyGrid::HandleMouseUp( int x, unsigned int WXUNUSED(y), // (it is only here as a reminder to not to do it) //splitterX = x; - // Disable splitter auto-centering - m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER; + SendEvent(wxEVT_PG_COL_END_DRAG, + m_propHover, + NULL, + wxPG_SEL_NOVALIDATE, + (unsigned int)m_draggedSplitter); + + // Disable splitter auto-centering (but only if moved any - + // otherwise we end up disabling auto-center even after a + // recentering double-click). + int posDiff = abs(m_startingSplitterX - + GetSplitterPosition(m_draggedSplitter)); + + if ( posDiff > 1 ) + state->m_dontCenterSplitter = true; // This is necessary to return cursor if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED ) @@ -5438,6 +5647,27 @@ void wxPropertyGrid::OnIdle( wxIdleEvent& WXUNUSED(event) ) if ( tlp != m_tlp ) OnTLPChanging(tlp); } + + // + // Resolve pending property removals + if ( m_deletedProperties.size() > 0 ) + { + wxArrayPGProperty& arr = m_deletedProperties; + for ( unsigned int i=0; i 0 ) + { + wxArrayPGProperty& arr = m_removedProperties; + for ( unsigned int i=0; iGetParent(); } + // Notify editor control when it receives a focus + if ( wasEditorFocused && m_curFocused != newFocused ) + { + wxPGProperty* p = GetSelection(); + if ( p ) + { + const wxPGEditor* editor = p->GetEditorClass(); + ResetEditorAppearance(); + editor->OnFocus(p, GetEditorControl()); + } + } + m_curFocused = newFocused; if ( (m_iFlags & wxPG_FL_FOCUSED) != @@ -5775,6 +6023,9 @@ wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED, wxPropertyGridEvent ); wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK, wxPropertyGridEvent ); wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN, wxPropertyGridEvent ); wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING, wxPropertyGridEvent ); +wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG, wxPropertyGridEvent ); +wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING, wxPropertyGridEvent ); +wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG, wxPropertyGridEvent ); // -----------------------------------------------------------------------