]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/datavgen.cpp
remove old libpng 1.2.7
[wxWidgets.git] / src / generic / datavgen.cpp
index 3dac619d2433929054a116b956ba83a851faeb1c..6d28209443430c5a23d28c1f5e411b98feb93efd 100644 (file)
@@ -270,14 +270,14 @@ class wxDataViewTreeNode
 {
 public:
     wxDataViewTreeNode( wxDataViewTreeNode * parent = NULL )
-       { 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()
     {
@@ -313,13 +313,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()
@@ -489,6 +489,7 @@ public:
     void SelectRows( unsigned int from, unsigned int to, bool on );
     void ReverseRowSelection( unsigned int row );
     bool IsRowSelected( unsigned int row );
+    void SendSelectionChangedEvent( const wxDataViewItem& item);
 
     void RefreshRow( unsigned int row );
     void RefreshRows( unsigned int from, unsigned int to );
@@ -587,7 +588,7 @@ public:
     virtual bool Cleared()
         { return m_mainWindow->Cleared(); }
     virtual void Resort()
-        { m_mainWindow->Resort(); }
+         { m_mainWindow->Resort(); }
 
     wxDataViewMainWindow    *m_mainWindow;
 };
@@ -2392,11 +2393,11 @@ 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());
@@ -2660,6 +2661,18 @@ bool wxDataViewMainWindow::IsRowSelected( unsigned int row )
     return (m_selection.Index( row ) != wxNOT_FOUND);
 }
 
+void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem& item)
+{
+    wxWindow *parent = GetParent();
+    wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, parent->GetId());
+
+    le.SetEventObject(parent);
+    le.SetModel(GetOwner()->GetModel());
+    le.SetItem( item );
+
+    parent->GetEventHandler()->ProcessEvent(le);
+}
+
 void wxDataViewMainWindow::RefreshRow( unsigned int row )
 {
     wxRect rect( 0, row*m_lineHeight, GetEndOfLastCol(), m_lineHeight );
@@ -2734,6 +2747,8 @@ void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent, const wxKeyEvent
         }
 
         SelectRows( oldCurrent, newCurrent, true );
+        if (oldCurrent!=newCurrent)
+            SendSelectionChangedEvent(GetItemByRow(m_selection[0]));
     }
     else // !shift
     {
@@ -2746,7 +2761,10 @@ void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent, const wxKeyEvent
         ChangeCurrentRow( newCurrent );
 
         if ( !event.ControlDown() )
+        {
             SelectRow( m_currentRow, true );
+            SendSelectionChangedEvent(GetItemByRow(m_currentRow));
+        }
         else
             RefreshRow( m_currentRow );
     }
@@ -2775,7 +2793,7 @@ public:
     {
         current ++;
         if( current == static_cast<int>(row))
-        {
+         {
             ret = node->GetItem() ;
             return DoJob::OK;
         }
@@ -2803,7 +2821,7 @@ public:
     {
         current ++;
         if( current == static_cast<int>(row))
-        {
+         {
             ret = wxDataViewItem( n ) ;
             return DoJob::OK;
         }
@@ -2839,7 +2857,7 @@ public:
     {
         current ++;
         if( current == static_cast<int>(row))
-        {
+         {
             ret = node ;
             return DoJob::OK;
         }
@@ -2873,7 +2891,7 @@ public:
     {
         current ++;
         if( current == static_cast<int>(row))
-        {
+         {
             ret = new wxDataViewTreeNode( parent ) ;
             ret->SetItem( wxDataViewItem( n ));
             ret->SetHasChildren(false);
@@ -2942,6 +2960,7 @@ void wxDataViewMainWindow::OnExpanding( unsigned int row )
                 SelectRow( row, false );
                 SelectRow( row + 1, true );
                 ChangeCurrentRow( row + 1 );
+                SendSelectionChangedEvent( GetItemByRow(row+1));
             }
         }
         else
@@ -2977,6 +2996,7 @@ void wxDataViewMainWindow::OnCollapsing(unsigned int row)
                     SelectRow( row, false);
                     SelectRow(parent , true );
                     ChangeCurrentRow( parent );
+                    SendSelectionChangedEvent( node->GetItem() );
                 }
             }
         }
@@ -3254,11 +3274,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 );
@@ -3365,14 +3385,14 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
                 m_underMouse = node;
             }
         }
-        if (node!=NULL && !node->HasChildren())
+     if (node!=NULL && !node->HasChildren())
             delete node;
     }
     if (!hover)
     {
         if (m_underMouse != NULL)
         {
-            wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
+            //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
             Refresh(GetRowByItem(m_underMouse->GetItem()));
             m_underMouse = NULL;
         }
@@ -3461,21 +3481,21 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
         bool expander = false;
         if (GetOwner()->GetExpanderColumn() == col)
         {
-               wxDataViewTreeNode * node = GetTreeNodeByRow(current);
-               if( node!=NULL && node->HasChildren() )
-               {
-                   int indent = node->GetIndentLevel();
-                   indent = GetOwner()->GetIndent()*indent;
-                   wxRect rect( xpos + indent + EXPANDER_MARGIN, current * m_lineHeight + EXPANDER_MARGIN, m_lineHeight-2*EXPANDER_MARGIN,m_lineHeight-2*EXPANDER_MARGIN);
-                   if( rect.Contains( x, y) )
-                   {
-                       expander = true;
-                       if( node->IsOpen() )
-                           OnCollapsing(current);
-                       else
-                           OnExpanding( current );
-                   }
-               }
+            wxDataViewTreeNode * node = GetTreeNodeByRow(current);
+            if( node!=NULL && node->HasChildren() )
+            {
+                int indent = node->GetIndentLevel();
+                indent = GetOwner()->GetIndent()*indent;
+                wxRect rect( xpos + indent + EXPANDER_MARGIN, current * m_lineHeight + EXPANDER_MARGIN, m_lineHeight-2*EXPANDER_MARGIN,m_lineHeight-2*EXPANDER_MARGIN);
+                if( rect.Contains( x, y) )
+                {
+                    expander = true;
+                    if( node->IsOpen() )
+                        OnCollapsing(current);
+                    else
+                        OnExpanding( current );
+                }
+            }
         }
         //If the user click the expander, we do not do editing even if the column with expander are editable
         if (m_lastOnSame && !expander )
@@ -3511,6 +3531,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
             SelectAllRows(false);
             ChangeCurrentRow(current);
             SelectRow(m_currentRow,true);
+            SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
         }
 
         // notify cell about right click
@@ -3540,10 +3561,9 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
             if ( IsSingleSel() || !IsRowSelected(current) )
             {
                 SelectAllRows( false );
-
                 ChangeCurrentRow(current);
-
                 SelectRow(m_currentRow,true);
+                SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
             }
             else // multi sel & current is highlighted & no mod keys
             {
@@ -3556,8 +3576,8 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
             if (cmdModifierDown)
             {
                 ChangeCurrentRow(current);
-
                 ReverseRowSelection(m_currentRow);
+                SendSelectionChangedEvent(GetItemByRow(m_selection[0]) );
             }
             else if (event.ShiftDown())
             {
@@ -3573,6 +3593,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
                 }
 
                 SelectRows(lineFrom, lineTo, true);
+                SendSelectionChangedEvent(GetItemByRow(m_selection[0]) );
             }
             else // !ctrl, !shift
             {
@@ -3796,7 +3817,21 @@ bool wxDataViewCtrl::ClearColumns()
 
 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
 {
-    return -1;
+    int ret = 0, dead = 0;
+    int len = GetColumnCount();
+    for (int i=0; i<len; i++)
+    {
+        wxDataViewColumn * col = GetColumn(i);
+        if (col->IsHidden())
+            continue;
+        ret += col->GetWidth();
+        if (column==col)
+        {
+            CalcScrolledPosition( ret, dead, &ret, &dead );
+            break;
+        }
+    }
+    return ret;
 }
 
 wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
@@ -3965,7 +4000,7 @@ void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, const wxDataVie
     if( row >= 0 )
     {
         if( column == NULL )
-            return EnsureVisible(row, -1);
+            EnsureVisible(row, -1);
         else
         {
             int col = 0;