]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/datavgen.cpp
Fix a number of problems with tracking rectangles by avoiding rebuilding them when...
[wxWidgets.git] / src / generic / datavgen.cpp
index 13ebc80740b870c6bd47edfe00b536e68b535eac..535fc5433f9fae8b541260dc0d17f10d1a3443c0 100644 (file)
@@ -266,14 +266,14 @@ public:
     wxDataViewTreeNode( wxDataViewTreeNode * parent )
         :leaves( wxGenericTreeModelItemCmp ),
          nodes(wxGenericTreeModelNodeCmp)
-       { this->parent = parent;
+        { this->parent = parent;
           if( parent == NULL )
               open = true;
-          else
-               open = false;
+       else
+        open = false;
           hasChildren = false;
           subTreeCount  = 0;
-       }
+    }
     //I don't know what I need to do in the destructure
     ~wxDataViewTreeNode()
     {
@@ -300,13 +300,13 @@ public:
     int GetIndentLevel()
     {
         int ret = 0 ;
-        wxDataViewTreeNode * node = this;
-        while( node->GetParent()->GetParent() != NULL )
-        {
-            node = node->GetParent();
-            ret ++;
-        }
-        return ret;
+     wxDataViewTreeNode * node = this;
+     while( node->GetParent()->GetParent() != NULL )
+     {
+         node = node->GetParent();
+         ret ++;
+     }
+     return ret;
     }
 
     bool IsOpen()
@@ -347,6 +347,31 @@ public:
             parent->ChangeSubTreeCount(num);
     }
 
+    void Resort()
+    {
+        wxDataViewTreeNodes nds = nodes;
+        wxDataViewTreeLeaves lvs = leaves;
+        nodes.Empty();
+        leaves.Empty();
+
+        int len = nds.GetCount();
+        if(len > 0)
+        {
+            int i;
+            for(i = 0; i < len; i ++)
+                nodes.Add(nds[i]);
+            for(i = 0; i < len; i ++)
+                nodes[i]->Resort();
+        }
+
+        len = lvs.GetCount();
+        if(len > 0)
+        {
+            for(int i = 0; i < len; i++)
+                leaves.Add(lvs[i]);
+        }
+    }
+
 private:
     wxDataViewTreeNode * parent;
     wxDataViewTreeNodes  nodes;
@@ -398,6 +423,8 @@ public:
     bool ItemChanged( const wxDataViewItem &item );
     bool ValueChanged( const wxDataViewItem &item, unsigned int col );
     bool Cleared();
+    void Resort()
+        { g_model = GetOwner()->GetModel(); m_root->Resort(); UpdateDisplay(); }
 
     void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
     wxDataViewCtrl *GetOwner() { return m_owner; }
@@ -528,6 +555,8 @@ public:
         { return m_mainWindow->ValueChanged( item, col ); }
     virtual bool Cleared()
         { return m_mainWindow->Cleared(); }
+    virtual void Resort()
+         { m_mainWindow->Resort(); }
 
     wxDataViewMainWindow    *m_mainWindow;
 };
@@ -1149,6 +1178,7 @@ void wxDataViewHeaderWindowMSW::UpdateDisplay()
     // add the updated array of columns to the header control
     unsigned int cols = GetOwner()->GetColumnCount();
     unsigned int added = 0;
+    wxDataViewModel * model = GetOwner()->GetModel();
     for (unsigned int i = 0; i < cols; i++)
     {
         wxDataViewColumn *col = GetColumn( i );
@@ -1282,6 +1312,30 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA
         case HDN_ITEMCLICK:
             {
                 unsigned int idx = GetColumnIdxFromHeader(nmHDR);
+                wxDataViewModel * model = GetOwner()->GetModel();
+
+                if(nmHDR->iButton == 0)
+                {
+                    wxDataViewColumn *col = GetColumn(idx);
+                    if(col->IsSortable())
+                    {
+                        if(model && model->GetSortingColumn() == idx)
+                        {
+                            bool order = col->IsSortOrderAscending();
+                            col->SetSortOrder(!order);
+                            // model->SetSortOrderAscending(!order);
+                        }
+                        else if(model)
+                        {
+                            model->SetSortingColumn(idx);
+                            // model->SetSortOrderAscending(true);
+                        }
+                    }
+                    UpdateDisplay();
+                    if(model)
+                        model->Resort();
+                }
+
                 wxEventType evt = nmHDR->iButton == 0 ?
                         wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK :
                         wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK;
@@ -1791,7 +1845,7 @@ class ItemAddJob: public DoJob
 {
 public:
     ItemAddJob( const wxDataViewItem & parent, const wxDataViewItem & item, int * count )
-       { this->parent = parent ; this->item = item ; m_count = count; }
+        { this->parent = parent ; this->item = item ; m_count = count; }
     virtual ~ItemAddJob(){};
 
     virtual int operator() ( wxDataViewTreeNode * node )
@@ -1923,8 +1977,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
     g_model = GetOwner()->GetModel();
 
     wxDataViewTreeNode * node;
-    wxDataViewItem parent_item = g_model->GetParent( item );
-    node = FindNode(parent_item);
+    node = FindNode(parent);
 
     if( node == NULL || node->GetChildren().Index( item.GetID() ) == wxNOT_FOUND )
     {
@@ -1935,7 +1988,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
     node->GetChildren().Remove( item.GetID() );
     if( GetOwner()->GetModel()->IsContainer( item ) )
     {
-        wxDataViewTreeNode * n ;
+        wxDataViewTreeNode * n = NULL;
         wxDataViewTreeNodes nodes = node->GetNodes();
         int len = nodes.GetCount();
         for( int i = 0 ; i < len; i ++)
@@ -1946,6 +1999,10 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
                 break;
             }
         }
+
+        if (!n)
+            return false;
+
         node->GetNodes().Remove( n );
         sub -= n->GetSubTreeCount();
         DestroyTreeHelper(n);
@@ -2172,14 +2229,14 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
         {
             // get the cell value and set it into the renderer
             wxVariant value;
-            wxDataViewTreeNode * node = GetTreeNodeByRow(item);
-            if( node == NULL )
-            {
-                continue;
-            }
+         wxDataViewTreeNode * node = GetTreeNodeByRow(item);
+         if( node == NULL )
+         {
+             continue;
+         }
 
             wxDataViewItem dataitem = node->GetItem();
-            model->GetValue( value, dataitem, col->GetModelColumn());
+         model->GetValue( value, dataitem, col->GetModelColumn());
             cell->SetValue( value );
 
             // update the y offset
@@ -2547,7 +2604,7 @@ public:
     {
         current ++;
         if( current == static_cast<int>(row))
-        {
+         {
             ret = node->GetItem() ;
             return DoJob::OK;
         }
@@ -2565,7 +2622,7 @@ public:
     {
         current ++;
         if( current == static_cast<int>(row))
-        {
+         {
             ret = wxDataViewItem( n ) ;
             return DoJob::OK;
         }
@@ -2601,7 +2658,7 @@ public:
     {
         current ++;
         if( current == static_cast<int>(row))
-        {
+         {
             ret = node ;
             return DoJob::OK;
         }
@@ -2623,7 +2680,7 @@ public:
     {
         current ++;
         if( current == static_cast<int>(row))
-        {
+         {
             ret = new wxDataViewTreeNode( parent ) ;
             ret->SetItem( wxDataViewItem( n ));
             ret->SetHasChildren(false);
@@ -2763,7 +2820,7 @@ wxDataViewTreeNode * wxDataViewMainWindow::FindNode( const wxDataViewItem & item
             for( ; j < len; j ++)
             {
                 if( nodes[j]->GetItem() == *(n->GetData()))
-                 {
+          {
                     node = nodes[j];
                     break;
                 }
@@ -2950,11 +3007,11 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
             break;
         //Add the process for tree expanding/collapsing
         case WXK_LEFT:
-            OnCollapsing(m_currentRow);
-            break;
-        case WXK_RIGHT:
-            OnExpanding( m_currentRow);
-            break;
+         OnCollapsing(m_currentRow);
+         break;
+     case WXK_RIGHT:
+         OnExpanding( m_currentRow);
+         break;
         case WXK_END:
             if (!IsEmpty())
                 OnArrowChar( GetRowCount() - 1, event );