X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8d5b63cc449702f54cd62f430abfdc74cc5a6408..4cd4a9ff70cdfdfc054747d7dae6101da3f94c03:/src/propgrid/propgrid.cpp diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index f33e2c7119..62459e6476 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -152,6 +152,15 @@ public: IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager, wxModule) +// When wxPG is loaded dynamically after the application is already running +// then the built-in module system won't pick this one up. Add it manually. +void wxPGInitResourceModule() +{ + wxModule* module = new wxPGGlobalVarsClassManager; + module->Init(); + wxModule::RegisterModule(module); +} + wxPGGlobalVarsClass* wxPGGlobalVars = NULL; @@ -186,6 +195,7 @@ wxPGGlobalVarsClass::wxPGGlobalVarsClass() m_strlong = wxS("long"); m_strbool = wxS("bool"); m_strlist = wxS("list"); + m_strDefaultValue = wxS("DefaultValue"); m_strMin = wxS("Min"); m_strMax = wxS("Max"); m_strUnits = wxS("Units"); @@ -227,46 +237,6 @@ void wxPropertyGridInitGlobalsIfNeeded() { } -// ----------------------------------------------------------------------- -// wxPGTLWHandler -// Intercepts Close-events sent to wxPropertyGrid's top-level parent, -// and tries to commit property value. -// ----------------------------------------------------------------------- - -class wxPGTLWHandler : public wxEvtHandler -{ -public: - - wxPGTLWHandler( wxPropertyGrid* pg ) - : wxEvtHandler() - { - m_pg = pg; - } - -protected: - - void OnClose( wxCloseEvent& event ) - { - // ClearSelection forces value validation/commit. - if ( event.CanVeto() && !m_pg->ClearSelection() ) - { - event.Veto(); - return; - } - - event.Skip(); - } - -private: - wxPropertyGrid* m_pg; - - DECLARE_EVENT_TABLE() -}; - -BEGIN_EVENT_TABLE(wxPGTLWHandler, wxEvtHandler) - EVT_CLOSE(wxPGTLWHandler::OnClose) -END_EVENT_TABLE() - // ----------------------------------------------------------------------- // wxPGCanvas // ----------------------------------------------------------------------- @@ -463,7 +433,6 @@ void wxPropertyGrid::Init1() m_propHover = NULL; m_eventObject = this; m_curFocused = NULL; - m_tlwHandler = NULL; m_sortFunction = NULL; m_inDoPropertyChanged = 0; m_inCommitChangesFromEditor = 0; @@ -580,11 +549,11 @@ void wxPropertyGrid::Init2() // This helps with flicker SetBackgroundStyle( wxBG_STYLE_CUSTOM ); - // Hook the TLW - wxPGTLWHandler* handler = new wxPGTLWHandler(this); - m_tlp = ::wxGetTopLevelParent(this); - m_tlwHandler = handler; - m_tlp->PushEventHandler(handler); + // Hook the top-level parent + m_tlp = NULL; + m_tlpClosed = NULL; + m_tlpClosedTime = 0; + OnTLPChanging(::wxGetTopLevelParent(this)); // set virtual size to this window size wxSize wndsize = GetSize(); @@ -621,9 +590,8 @@ wxPropertyGrid::~wxPropertyGrid() if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED ) m_canvas->ReleaseMouse(); - wxPGTLWHandler* handler = (wxPGTLWHandler*) m_tlwHandler; - m_tlp->RemoveEventHandler(handler); - delete handler; + // Call with NULL to disconnect event handling + OnTLPChanging(NULL); wxASSERT_MSG( !IsEditorsValueModified(), wxS("Most recent change in property editor was lost!!! ") @@ -838,6 +806,74 @@ wxSize wxPropertyGrid::DoGetBestSize() const return sz; } +// ----------------------------------------------------------------------- + +void wxPropertyGrid::OnTLPChanging( wxWindow* newTLP ) +{ + wxLongLong currentTime = ::wxGetLocalTimeMillis(); + + // + // Parent changed so let's redetermine and re-hook the + // correct top-level window. + if ( m_tlp ) + { + m_tlp->Disconnect( wxEVT_CLOSE_WINDOW, + wxCloseEventHandler(wxPropertyGrid::OnTLPClose), + NULL, this ); + m_tlpClosed = m_tlp; + m_tlpClosedTime = currentTime; + } + + if ( newTLP ) + { + // Only accept new tlp if same one was not just dismissed. + if ( newTLP != m_tlpClosed || + m_tlpClosedTime+250 < currentTime ) + { + newTLP->Connect( wxEVT_CLOSE_WINDOW, + wxCloseEventHandler(wxPropertyGrid::OnTLPClose), + NULL, this ); + m_tlpClosed = NULL; + } + else + { + newTLP = NULL; + } + } + + m_tlp = newTLP; +} + +// ----------------------------------------------------------------------- + +void wxPropertyGrid::OnTLPClose( wxCloseEvent& event ) +{ + // ClearSelection forces value validation/commit. + if ( event.CanVeto() && !ClearSelection() ) + { + event.Veto(); + return; + } + + // Ok, it can close, set tlp pointer to NULL. Some other event + // handler can of course veto the close, but our OnIdle() should + // then be able to regain the tlp pointer. + OnTLPChanging(NULL); + + event.Skip(); +} + +// ----------------------------------------------------------------------- + +bool wxPropertyGrid::Reparent( wxWindowBase *newParent ) +{ + OnTLPChanging((wxWindow*)newParent); + + bool res = wxScrolledWindow::Reparent(newParent); + + return res; +} + // ----------------------------------------------------------------------- // wxPropertyGrid Font and Colour Methods // ----------------------------------------------------------------------- @@ -2563,7 +2599,7 @@ void wxPropertyGrid::DoShowPropertyError( wxPGProperty* WXUNUSED(property), cons } #endif - ::wxMessageBox(msg, _T("Property Error")); + ::wxMessageBox(msg, wxT("Property Error")); } // ----------------------------------------------------------------------- @@ -2638,7 +2674,7 @@ bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty* property, wxVariant& W wxString msg = m_validationInfo.m_failureMessage; if ( !msg.length() ) - msg = _T("You have entered invalid value. Press ESC to cancel editing."); + msg = wxT("You have entered invalid value. Press ESC to cancel editing."); DoShowPropertyError(property, msg); } @@ -3209,10 +3245,14 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags ) { /* if (p) + { wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(), p->m_parent->m_label.c_str(),p->GetIndexInParent()); + } else + { wxLogDebug(wxT("SelectProperty( NULL, -1 )")); + } */ if ( m_inDoSelectProperty ) @@ -4927,6 +4967,14 @@ void wxPropertyGrid::OnIdle( wxIdleEvent& WXUNUSED(event) ) if ( newFocused != m_curFocused ) HandleFocusChange( newFocused ); + + // + // Check if top-level parent has changed + wxWindow* tlp = ::wxGetTopLevelParent(this); + if ( tlp != m_tlp ) + { + OnTLPChanging(tlp); + } } bool wxPropertyGrid::IsEditorFocused() const @@ -5053,15 +5101,18 @@ void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent& WXUNUSED(event // ----------------------------------------------------------------------- // noDefCheck = true prevents infinite recursion. -wxPGEditor* wxPropertyGrid::RegisterEditorClass( wxPGEditor* editorClass, - bool noDefCheck ) +wxPGEditor* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor* editorClass, + const wxString& editorName, + bool noDefCheck ) { wxASSERT( editorClass ); if ( !noDefCheck && wxPGGlobalVars->m_mapEditorClasses.empty() ) RegisterDefaultEditors(); - wxString name = editorClass->GetName(); + wxString name = editorName; + if ( name.length() == 0 ) + name = editorClass->GetName(); // Existing editor under this name? wxPGHashMapS2P::iterator vt_it = wxPGGlobalVars->m_mapEditorClasses.find(name); @@ -5198,7 +5249,6 @@ wxPGChoiceEntry::wxPGChoiceEntry() wxPGChoicesData::wxPGChoicesData() { - m_refCount = 1; } wxPGChoicesData::~wxPGChoicesData()