X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b0996c3da00677389854e5afbcef499e7aa1654b..12b5f4b4d2d8a07962da7ba3b78c8c1ec2634a67:/src/propgrid/propgrid.cpp?ds=inline diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index cbc0bd7ad6..56738c1635 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -154,7 +154,7 @@ public: IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager, wxModule) -wxPGGlobalVarsClass* wxPGGlobalVars = (wxPGGlobalVarsClass*) NULL; +wxPGGlobalVarsClass* wxPGGlobalVars = NULL; wxPGGlobalVarsClass::wxPGGlobalVarsClass() @@ -164,7 +164,7 @@ wxPGGlobalVarsClass::wxPGGlobalVarsClass() m_boolChoices.Add(_("False")); m_boolChoices.Add(_("True")); - m_fontFamilyChoices = (wxPGChoices*) NULL; + m_fontFamilyChoices = NULL; m_defaultRenderer = new wxPGDefaultRenderer(); @@ -454,14 +454,15 @@ void wxPropertyGrid::Init1() wxPropertyGrid::RegisterDefaultEditors(); m_iFlags = 0; - m_pState = (wxPropertyGridPageState*) NULL; - m_wndEditor = m_wndEditor2 = (wxWindow*) NULL; - m_selected = (wxPGProperty*) NULL; + m_pState = NULL; + m_wndEditor = m_wndEditor2 = NULL; + m_selected = NULL; m_selColumn = -1; - m_propHover = (wxPGProperty*) NULL; + m_propHover = NULL; m_eventObject = this; - m_curFocused = (wxWindow*) NULL; + m_curFocused = NULL; m_tlwHandler = NULL; + m_sortFunction = NULL; m_inDoPropertyChanged = 0; m_inCommitChangesFromEditor = 0; m_inDoSelectProperty = 0; @@ -487,7 +488,7 @@ void wxPropertyGrid::Init1() m_canvas = NULL; #if wxPG_DOUBLE_BUFFER - m_doubleBuffer = (wxBitmap*) NULL; + m_doubleBuffer = NULL; #endif #ifndef wxPG_ICON_WIDTH @@ -642,7 +643,7 @@ wxPropertyGrid::~wxPropertyGrid() delete m_doubleBuffer; #endif - //m_selected = (wxPGProperty*) NULL; + //m_selected = NULL; if ( m_iFlags & wxPG_FL_CREATEDSTATE ) delete m_pState; @@ -727,7 +728,7 @@ void wxPropertyGrid::SetWindowStyleFlag( long style ) // // Tooltips disabled // - m_canvas->SetToolTip( (wxToolTip*) NULL ); + m_canvas->SetToolTip( NULL ); } #endif } @@ -1179,29 +1180,11 @@ void wxPropertyGrid::PrepareAfterItemsAdded() m_pState->m_itemsAdded = 0; if ( m_windowStyle & wxPG_AUTO_SORT ) - Sort(); + Sort(wxPG_SORT_TOP_LEVEL_ONLY); RecalculateVirtualSize(); } -// ----------------------------------------------------------------------- -// wxPropertyGrid property value setting and getting -// ----------------------------------------------------------------------- - -void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty* p ) -{ - m_pState->DoSetPropertyValueUnspecified(p); - DrawItemAndChildren(p); - - wxPGProperty* parent = p->GetParent(); - while ( parent && - (parent->GetFlags() & wxPG_PROP_PARENTAL_FLAGS) == wxPG_PROP_MISC_PARENT ) - { - DrawItem(parent); - parent = parent->GetParent(); - } -} - // ----------------------------------------------------------------------- // wxPropertyGrid property operations // ----------------------------------------------------------------------- @@ -1421,7 +1404,7 @@ wxPGProperty* wxPropertyGrid::DoGetItemAtY( int y ) const { // Outside? if ( y < 0 ) - return (wxPGProperty*) NULL; + return NULL; unsigned int a = 0; return m_pState->m_properties->GetItemAtY(y, m_lineHeight, &a); @@ -1931,7 +1914,8 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc, unsigned int ci; int cellX = x + 1; - int nextCellWidth = state->m_colWidths[0]; + int nextCellWidth = state->m_colWidths[0] - + (greyDepthX - m_marginWidth); wxRect cellRect(greyDepthX+1, y, 0, rowHeight-1); int textXAdd = textMarginHere - greyDepthX; @@ -2034,7 +2018,7 @@ wxRect wxPropertyGrid::GetPropertyRect( const wxPGProperty* p1, const wxPGProper if ( m_width < 10 || m_height < 10 || !m_pState->m_properties->GetChildCount() || - p1 == (wxPGProperty*) NULL ) + p1 == NULL ) return wxRect(0,0,0,0); int vy = 0; @@ -2130,11 +2114,9 @@ void wxPropertyGrid::DrawItemAndChildren( wxPGProperty* p ) if ( m_pState->m_itemsAdded || m_frozen ) return; - wxWindow* wndPrimary = GetEditorControl(); - // Update child control. if ( m_selected && m_selected->GetParent() == p ) - m_selected->UpdateControl(wndPrimary); + RefreshEditor(); const wxPGProperty* lastDrawn = p->GetLastVisibleSubItem(); @@ -2267,7 +2249,7 @@ void wxPropertyGrid::SwitchState( wxPropertyGridPageState* pNewState ) pNewState->OnClientWidthChange( pgWidth, pgWidth - pNewState->m_width ); } - m_propHover = (wxPGProperty*) NULL; + m_propHover = NULL; // If necessary, convert state to correct mode. if ( orig_mode != new_state_mode ) @@ -2278,8 +2260,7 @@ void wxPropertyGrid::SwitchState( wxPropertyGridPageState* pNewState ) else if ( !m_frozen ) { // Refresh, if not frozen. - if ( m_pState->m_itemsAdded ) - PrepareAfterItemsAdded(); + m_pState->PrepareAfterItemsAdded(); // Reselect if ( m_pState->m_selected ) @@ -2294,24 +2275,6 @@ void wxPropertyGrid::SwitchState( wxPropertyGridPageState* pNewState ) // ----------------------------------------------------------------------- -void wxPropertyGrid::SortChildren( wxPGPropArg id ) -{ - wxPG_PROP_ARG_CALL_PROLOG() - - m_pState->SortChildren( p ); -} - -// ----------------------------------------------------------------------- - -void wxPropertyGrid::Sort() -{ - ClearSelection(false); // This must be before state clear - - m_pState->Sort(); -} - -// ----------------------------------------------------------------------- - // 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 ) @@ -2640,6 +2603,29 @@ void wxPropertyGrid::DoShowPropertyError( wxPGProperty* WXUNUSED(property), cons // ----------------------------------------------------------------------- +bool wxPropertyGrid::OnValidationFailure( wxPGProperty* property, + wxVariant& invalidValue ) +{ + wxWindow* editor = GetEditorControl(); + + // First call property's handler + property->OnValidationFailure(invalidValue); + + bool res = DoOnValidationFailure(property, invalidValue); + + // + // For non-wxTextCtrl editors, we do need to revert the value + if ( !editor->IsKindOf(CLASSINFO(wxTextCtrl)) && + property == m_selected ) + { + property->GetEditorClass()->UpdateControl(property, editor); + } + + property->SetFlag(wxPG_PROP_INVALID_VALUE); + + return res; +} + bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty* property, wxVariant& WXUNUSED(invalidValue) ) { int vfb = m_validationInfo.m_failureBehavior; @@ -2790,8 +2776,7 @@ bool wxPropertyGrid::DoPropertyChanged( wxPGProperty* p, unsigned int selFlags ) // control. if ( selFlags & wxPG_SEL_DIALOGVAL ) { - if ( editor ) - p->GetEditorClass()->UpdateControl(p, editor); + RefreshEditor(); } else { @@ -3234,18 +3219,20 @@ void wxPropertyGrid::FreeEditors() // Do not free editors immediately if processing events if ( m_wndEditor2 ) { - m_wndEditor2->PopEventHandler(true); + wxEvtHandler* handler = m_wndEditor2->PopEventHandler(false); m_wndEditor2->Hide(); + wxPendingDelete.Append( handler ); wxPendingDelete.Append( m_wndEditor2 ); - m_wndEditor2 = (wxWindow*) NULL; + m_wndEditor2 = NULL; } if ( m_wndEditor ) { - m_wndEditor->PopEventHandler(true); + wxEvtHandler* handler = m_wndEditor->PopEventHandler(false); m_wndEditor->Hide(); + wxPendingDelete.Append( handler ); wxPendingDelete.Append( m_wndEditor ); - m_wndEditor = (wxWindow*) NULL; + m_wndEditor = NULL; } } @@ -3299,7 +3286,7 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags ) FreeEditors(); // Prevent any further selection measures in this call - p = (wxPGProperty*) NULL; + p = NULL; } else { @@ -3350,8 +3337,8 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags ) FreeEditors(); m_selColumn = -1; - m_selected = (wxPGProperty*) NULL; - m_pState->m_selected = (wxPGProperty*) NULL; + m_selected = NULL; + m_pState->m_selected = NULL; // We need to always fully refresh the grid here Refresh(false); @@ -3376,7 +3363,7 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags ) if ( p != prev ) m_iFlags &= ~(wxPG_FL_VALIDATION_FAILED); - wxASSERT( m_wndEditor == (wxWindow*) NULL ); + wxASSERT( m_wndEditor == NULL ); // // Only create editor for non-disabled non-caption @@ -3575,7 +3562,7 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags ) if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS) ) { - wxStatusBar* statusbar = (wxStatusBar*) NULL; + wxStatusBar* statusbar = NULL; if ( !(m_iFlags & wxPG_FL_NOSTATUSBARHELP) ) { wxFrame* frame = wxDynamicCast(::wxGetTopLevelParent(this),wxFrame); @@ -3636,11 +3623,41 @@ bool wxPropertyGrid::UnfocusEditor() // ----------------------------------------------------------------------- +void wxPropertyGrid::RefreshEditor() +{ + wxPGProperty* p = m_selected; + if ( !p ) + return; + + wxWindow* wnd = GetEditorControl(); + if ( !wnd ) + return; + + // Set editor font boldness - must do this before + // calling UpdateControl(). + if ( HasFlag(wxPG_BOLD_MODIFIED) ) + { + if ( p->HasFlag(wxPG_PROP_MODIFIED) ) + wnd->SetFont(GetCaptionFont()); + else + wnd->SetFont(GetFont()); + } + + const wxPGEditor* editorClass = p->GetEditorClass(); + + editorClass->UpdateControl(p, wnd); + + if ( p->IsValueUnspecified() ) + editorClass ->SetValueToUnspecified(p, wnd); +} + +// ----------------------------------------------------------------------- + // This method is not inline because it called dozens of times // (i.e. two-arg function calls create smaller code size). bool wxPropertyGrid::DoClearSelection() { - return DoSelectProperty((wxPGProperty*)NULL); + return DoSelectProperty(NULL); } // ----------------------------------------------------------------------- @@ -4446,7 +4463,7 @@ bool wxPropertyGrid::OnMouseCommon( wxMouseEvent& event, int* px, int* py ) wxRect r; if ( wnd ) r = wnd->GetRect(); - if ( wnd == (wxWindow*) NULL || m_dragStatus || + if ( wnd == NULL || m_dragStatus || ( ux <= (splitterX + wxPG_SPLITTERX_DETECTMARGIN2) || ux >= (r.x+r.width) || @@ -5093,7 +5110,7 @@ wxPGEditor* wxPropertyGrid::RegisterEditorClass( wxPGEditor* editorClass, // Use this in RegisterDefaultEditors. #define wxPGRegisterDefaultEditorClass(EDITOR) \ - if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \ + if ( wxPGEditor_##EDITOR == NULL ) \ { \ wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \ new wxPG##EDITOR##Editor, true ); \ @@ -5494,15 +5511,15 @@ void wxPGChoices::Free() IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent, wxCommandEvent) -DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED ) -DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING ) -DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED ) -DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED ) -DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK ) -DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED ) -DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED ) -DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED ) -DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK ) +wxDEFINE_EVENT( wxEVT_PG_SELECTED, wxPropertyGridEvent ) +wxDEFINE_EVENT( wxEVT_PG_CHANGING, wxPropertyGridEvent ) +wxDEFINE_EVENT( wxEVT_PG_CHANGED, wxPropertyGridEvent ) +wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED, wxPropertyGridEvent ) +wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK, wxPropertyGridEvent ) +wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED, wxPropertyGridEvent ) +wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED, wxPropertyGridEvent ) +wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED, wxPropertyGridEvent ) +wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK, wxPropertyGridEvent ) // -----------------------------------------------------------------------