]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxPropertyGridInterface::RemoveProperty()
authorJaakko Salli <jaakko.salli@dnainternet.net>
Thu, 11 Dec 2008 17:11:35 +0000 (17:11 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Thu, 11 Dec 2008 17:11:35 +0000 (17:11 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57254 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/propgrid/propgridiface.h
include/wx/propgrid/propgridpagestate.h
interface/wx/propgrid/propgridiface.h
samples/propgrid/tests.cpp
src/propgrid/propgridiface.cpp
src/propgrid/propgridpagestate.cpp

index a2139e45e945eb05e04f432309e9d441d2865844..8d8c010f4106da64a5b9f121d47ae4504808b079 100644 (file)
@@ -245,6 +245,16 @@ public:
      */
     void DeleteProperty( wxPGPropArg id );
 
+    /**
+        Removes and returns a property.
+
+        @param id
+            Pointer or name of a property.
+
+        @remarks Removed property cannot have any children.
+    */
+    wxPGProperty* RemoveProperty( wxPGPropArg id );
+
     /** Disables property. */
     bool DisableProperty( wxPGPropArg id ) { return EnableProperty(id,false); }
 
index f8953663895c8ecb28f5c468308c89f953587791..65c45f2d29e732c19bf0e9609a7f36f5f1af1aa3 100644 (file)
@@ -421,7 +421,7 @@ public:
         Override this member function to add custom behavior on property
         deletion.
     */
-    virtual void DoDelete( wxPGProperty* item );
+    virtual void DoDelete( wxPGProperty* item, bool doDelete = true );
 
     wxSize DoFitColumns( bool allowGridResize = false );
 
index 36f1bfc1a9a74bb6c61abcb46e251f0a3b3379d1..021954c63d600028c6cad3eb87bed4184bb0398a 100644 (file)
@@ -547,6 +547,16 @@ public:
     */
     static void RegisterAdditionalEditors();
 
+    /**
+        Removes and returns a property.
+
+        @param id
+            Pointer or name of a property.
+
+        @remarks Removed property cannot have any children.
+    */
+    wxPGProperty* RemoveProperty( wxPGPropArg id );
+
     /**
         Replaces property with id with newly created one. For example,
         this code replaces existing property named "Flags" with one that
index eb22e52437fd54fbdcb29d5b68fc137dfa36fe5c..1c066ca0d9431561d16ba99af2e1a643fe02204c 100644 (file)
@@ -918,6 +918,23 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
         pgman->EnsureVisible(wxT("Cell Colour"));
     }
 
+    {
+        RT_START_TEST(RemoveProperty)
+
+        wxPGProperty* p;
+
+        wxPGProperty* origParent =
+            pgman->GetProperty(wxT("Window Styles"))->GetParent();
+
+        p = pgman->RemoveProperty(wxT("Window Styles"));
+        pgman->Refresh();
+        pgman->Update();
+
+        pgman->AppendIn(origParent, p);
+        pgman->Refresh();
+        pgman->Update();
+    }
+
     {
         RT_START_TEST(SetPropertyBackgroundColour)
         wxCommandEvent evt;
index 13b09fc78d0481c3bec77d5c4e5ffd28b144c045..f762133260cf0fa54bc596752e7063a57c67db6e 100644 (file)
@@ -317,13 +317,42 @@ void wxPropertyGridInterface::DeleteProperty( wxPGPropArg id )
     if ( grid->GetState() == state )
         grid->DoSelectProperty(NULL, wxPG_SEL_DELETING|wxPG_SEL_NOVALIDATE);
 
-    state->DoDelete( p );
+    state->DoDelete( p, true );
 
     RefreshGrid(state);
 }
 
 // -----------------------------------------------------------------------
 
+wxPGProperty* wxPropertyGridInterface::RemoveProperty( wxPGPropArg id )
+{
+    wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty)
+
+    wxCHECK( !p->GetChildCount() || p->HasFlag(wxPG_PROP_AGGREGATE),
+             wxNullProperty);
+
+    wxPropertyGridPageState* state = p->GetParentState();
+    wxPropertyGrid* grid = state->GetGrid();
+
+    if ( grid->GetState() == state )
+    {
+        grid->DoSelectProperty(NULL,
+            wxPG_SEL_DELETING|wxPG_SEL_NOVALIDATE);
+    }
+
+    state->DoDelete( p, false );
+
+    // Mark the property as 'unattached'
+    p->m_parentState = NULL;
+    p->m_parent = NULL;
+
+    RefreshGrid(state);
+
+    return p;
+}
+
+// -----------------------------------------------------------------------
+
 wxPGProperty* wxPropertyGridInterface::ReplaceProperty( wxPGPropArg id, wxPGProperty* property )
 {
     wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty)
index aa5b0244f8f6165ba5183a63ffd124766db2db08..705baa516adafc44a82dffac78f540bfd79b106e 100644 (file)
@@ -1690,7 +1690,7 @@ wxPGProperty* wxPropertyGridPageState::DoInsert( wxPGProperty* parent, int index
 
 // -----------------------------------------------------------------------
 
-void wxPropertyGridPageState::DoDelete( wxPGProperty* item )
+void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete )
 {
     wxCHECK_RET( item->GetParent(),
         wxT("this property was already deleted") );
@@ -1790,7 +1790,8 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item )
     if ( item->GetBaseName().Len() ) m_dictName.erase(item->GetBaseName());
 
     // We can actually delete it now
-    delete item;
+    if ( doDelete )
+        delete item;
 
     m_itemsAdded = 1; // Not a logical assignment (but required nonetheless).