]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/datavgen.cpp
Check for decimal separator inconsistency in wxLocale::GetInfo().
[wxWidgets.git] / src / generic / datavgen.cpp
index d2f8fe01bf5269793f54fe3e3d9a08925212f74f..7cebed518a7dffea5a019ab1c4b2740e9804d1e0 100644 (file)
@@ -518,7 +518,6 @@ public:
     unsigned int GetLastVisibleRow();
     unsigned int GetRowCount();
 
-    wxDataViewItem GetSelection() const;
     const wxDataViewSelection& GetSelections() const { return m_selection; }
     void SetSelections( const wxDataViewSelection & sel )
         { m_selection = sel; UpdateDisplay(); }
@@ -1969,40 +1968,41 @@ bool Walker( wxDataViewTreeNode * node, DoJob & func )
 
 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item)
 {
-    GetOwner()->InvalidateColBestWidths();
 
     if (IsVirtualList())
     {
         wxDataViewVirtualListModel *list_model =
             (wxDataViewVirtualListModel*) GetOwner()->GetModel();
         m_count = list_model->GetCount();
-        UpdateDisplay();
-        return true;
     }
+    else
+    {
+        SortPrepare();
 
-    SortPrepare();
+        wxDataViewTreeNode * node;
+        node = FindNode(parent);
+
+        if( node == NULL )
+            return false;
 
-    wxDataViewTreeNode * node;
-    node = FindNode(parent);
+        node->SetHasChildren( true );
 
-    if( node == NULL )
-        return false;
+        if( g_model->IsContainer( item ) )
+        {
+            wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
+            newnode->SetItem(item);
+            newnode->SetHasChildren( true );
+            node->AddNode( newnode);
+        }
+        else
+            node->AddLeaf( item.GetID() );
 
-    node->SetHasChildren( true );
+        node->ChangeSubTreeCount(1);
 
-    if( g_model->IsContainer( item ) )
-    {
-        wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
-        newnode->SetItem(item);
-        newnode->SetHasChildren( true );
-        node->AddNode( newnode);
+        m_count = -1;
     }
-    else
-        node->AddLeaf( item.GetID() );
 
-    node->ChangeSubTreeCount(1);
-
-    m_count = -1;
+    GetOwner()->UpdateColBestWidths();
     UpdateDisplay();
 
     return true;
@@ -2013,8 +2013,6 @@ static void DestroyTreeHelper( wxDataViewTreeNode * node);
 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
                                        const wxDataViewItem& item)
 {
-    GetOwner()->InvalidateColBestWidths();
-
     if (IsVirtualList())
     {
         wxDataViewVirtualListModel *list_model =
@@ -2025,29 +2023,35 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
         {
             const int row = GetRowByItem(item);
 
+            int rowIndexInSelection = wxNOT_FOUND;
+
             const size_t selCount = m_selection.size();
             for ( size_t i = 0; i < selCount; i++ )
             {
-                if ( m_selection[i] > (unsigned)row )
+                if ( m_selection[i] == (unsigned)row )
+                    rowIndexInSelection = i;
+                else if ( m_selection[i] > (unsigned)row )
                     m_selection[i]--;
             }
 
-            int itemRow = m_selection.Index(row);
-            if ( itemRow != wxNOT_FOUND )
-                m_selection.RemoveAt(itemRow);
+            if ( rowIndexInSelection != wxNOT_FOUND )
+                m_selection.RemoveAt(rowIndexInSelection);
         }
 
     }
     else // general case
     {
         wxDataViewTreeNode * node = FindNode(parent);
-        int itemPosInNode = node ? node->GetChildren().Index(item.GetID()) : wxNOT_FOUND;
 
         // Notice that it is possible that the item being deleted is not in the
         // tree at all, for example we could be deleting a never shown (because
         // collapsed) item in a tree model. So it's not an error if we don't know
         // about this item, just return without doing anything then.
-        if ( !node || itemPosInNode == wxNOT_FOUND )
+        if ( !node )
+            return false;
+
+        int itemPosInNode = node->GetChildren().Index(item.GetID());
+        if ( itemPosInNode == wxNOT_FOUND )
             return false;
 
         bool isContainer = false;
@@ -2127,6 +2131,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
     if( m_currentRow > GetRowCount() )
         ChangeCurrentRow(m_count - 1);
 
+    GetOwner()->UpdateColBestWidths();
     UpdateDisplay();
 
     return true;
@@ -2134,11 +2139,11 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
 
 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item)
 {
-    GetOwner()->InvalidateColBestWidths();
-
     SortPrepare();
     g_model->Resort();
 
+    GetOwner()->UpdateColBestWidths();
+
     // Send event
     wxWindow *parent = GetParent();
     wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
@@ -2166,8 +2171,6 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
     if (view_column == -1)
         return false;
 
-    GetOwner()->InvalidateColBestWidth(view_column);
-
     // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
 /*#define MAX_VIRTUAL_WIDTH       100000
 
@@ -2180,6 +2183,8 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
     SortPrepare();
     g_model->Resort();
 
+    GetOwner()->UpdateColBestWidth(view_column);
+
     // Send event
     wxWindow *parent = GetParent();
     wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
@@ -2195,14 +2200,13 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
 
 bool wxDataViewMainWindow::Cleared()
 {
-    GetOwner()->InvalidateColBestWidths();
-
     DestroyTree();
     m_selection.Clear();
 
     SortPrepare();
     BuildTree( GetOwner()->GetModel() );
 
+    GetOwner()->UpdateColBestWidths();
     UpdateDisplay();
 
     return true;
@@ -3585,8 +3589,11 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
         return;
     }
 
-    // Test whether the mouse is hovered on the tree item button
+    // Test whether the mouse is hovering over the expander (a.k.a tree "+"
+    // button) and also determine the offset of the real cell start, skipping
+    // the indentation and the expander itself.
     bool hoverOverExpander = false;
+    int expanderOffset = 0;
     if ((!IsList()) && (GetOwner()->GetExpanderColumn() == col))
     {
         wxDataViewTreeNode * node = GetTreeNodeByRow(current);
@@ -3600,6 +3607,9 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
             wxRect rect( xpos + indent,
                         GetLineStart( current ) + (GetLineHeight(current) - m_lineHeight)/2,
                         m_lineHeight, m_lineHeight);
+
+            expanderOffset = indent + m_lineHeight;
+
             if( rect.Contains(x, y) )
             {
                 // So the mouse is over the expander
@@ -3890,8 +3900,10 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
             // notify cell about click
             cell->PrepareForItem(model, item, col->GetModelColumn());
 
-            wxRect cell_rect( xpos, GetLineStart( current ),
-                              col->GetWidth(), GetLineHeight( current ) );
+            wxRect cell_rect( xpos + expanderOffset,
+                              GetLineStart( current ),
+                              col->GetWidth() - expanderOffset,
+                              GetLineHeight( current ) );
 
             // Report position relative to the cell's custom area, i.e.
             // no the entire space as given by the control but the one
@@ -3955,14 +3967,6 @@ void wxDataViewMainWindow::OnKillFocus( wxFocusEvent &event )
     event.Skip();
 }
 
-wxDataViewItem wxDataViewMainWindow::GetSelection() const
-{
-    if( m_selection.GetCount() != 1 )
-        return wxDataViewItem();
-
-    return GetItemByRow( m_selection.Item(0));
-}
-
 //-----------------------------------------------------------------------------
 // wxDataViewCtrl
 //-----------------------------------------------------------------------------
@@ -4401,7 +4405,7 @@ bool wxDataViewCtrl::ClearColumns()
     return true;
 }
 
-void wxDataViewCtrl::InvalidateColBestWidth(int idx)
+void wxDataViewCtrl::UpdateColBestWidth(int idx)
 {
     m_colsBestWidths[idx] = 0;
 
@@ -4409,7 +4413,7 @@ void wxDataViewCtrl::InvalidateColBestWidth(int idx)
         m_headerArea->UpdateColumn(idx);
 }
 
-void wxDataViewCtrl::InvalidateColBestWidths()
+void wxDataViewCtrl::UpdateColBestWidths()
 {
     m_colsBestWidths.clear();
     m_colsBestWidths.resize(m_cols.size());
@@ -4479,10 +4483,9 @@ void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item)
     }
 }
 
-// Selection code with wxDataViewItem as parameters
-wxDataViewItem wxDataViewCtrl::GetSelection() const
+int wxDataViewCtrl::GetSelectedItemsCount() const
 {
-    return m_clientArea->GetSelection();
+    return m_clientArea->GetSelections().size();
 }
 
 int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const