]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/datavgen.cpp
Make hack for button creation in wxOSX more robust.
[wxWidgets.git] / src / generic / datavgen.cpp
index 7fef06b83bfdfaaa1c5eb3d1a1d4d5c8105f7d1d..18602bcbe2f61c4f5cb04eb6f5759d4a3baff281 100644 (file)
@@ -2465,8 +2465,15 @@ bool wxDataViewMainWindow::Cleared()
     DestroyTree();
     m_selection.Clear();
 
     DestroyTree();
     m_selection.Clear();
 
-    SortPrepare();
-    BuildTree( GetModel() );
+    if (GetModel())
+    {
+        SortPrepare();
+        BuildTree( GetModel() );
+    }
+    else
+    {
+        m_count = 0;
+    }
 
     GetOwner()->InvalidateColBestWidths();
     UpdateDisplay();
 
     GetOwner()->InvalidateColBestWidths();
     UpdateDisplay();
@@ -3932,9 +3939,12 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
         return;
     }
 
         return;
     }
 
-    // set the focus to ourself if any of the mouse buttons are pressed
-    if(event.ButtonDown() && !HasFocus())
-        SetFocus();
+    if(event.LeftDown())
+    {
+        // Not skipping this event would prevent the system from setting focus
+        // to this window.
+        event.Skip();
+    }
 
     int x = event.GetX();
     int y = event.GetY();
 
     int x = event.GetX();
     int y = event.GetY();
@@ -4279,8 +4289,15 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
         m_currentCol = col;
         m_currentColSetByKeyboard = false;
 
         m_currentCol = col;
         m_currentColSetByKeyboard = false;
 
+        // This flag is used to decide whether we should start editing the item
+        // label. We do it if the user clicks twice (but not double clicks,
+        // i.e. simulateClick is false) on the same item but not if the click
+        // was used for something else already, e.g. selecting the item (so it
+        // must have been already selected) or giving the focus to the control
+        // (so it must have had focus already).
         m_lastOnSame = !simulateClick && ((col == oldCurrentCol) &&
         m_lastOnSame = !simulateClick && ((col == oldCurrentCol) &&
-                        (current == oldCurrentRow)) && oldWasSelected;
+                        (current == oldCurrentRow)) && oldWasSelected &&
+                        HasFocus();
 
         // Call ActivateCell() after everything else as under GTK+
         if ( IsCellEditableInMode(item, col, wxDATAVIEW_CELL_ACTIVATABLE) )
 
         // Call ActivateCell() after everything else as under GTK+
         if ( IsCellEditableInMode(item, col, wxDATAVIEW_CELL_ACTIVATABLE) )
@@ -4526,13 +4543,23 @@ bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
     if (!wxDataViewCtrlBase::AssociateModel( model ))
         return false;
 
     if (!wxDataViewCtrlBase::AssociateModel( model ))
         return false;
 
-    m_notifier = new wxGenericDataViewModelNotifier( m_clientArea );
-
-    model->AddNotifier( m_notifier );
+    if (model)
+    {
+        m_notifier = new wxGenericDataViewModelNotifier( m_clientArea );
+        model->AddNotifier( m_notifier );
+    }
+    else if (m_notifier)
+    {
+        m_notifier->Cleared();
+        m_notifier = NULL;
+    }
 
     m_clientArea->DestroyTree();
 
 
     m_clientArea->DestroyTree();
 
-    m_clientArea->BuildTree(model);
+    if (model)
+    {
+        m_clientArea->BuildTree(model);
+    }
 
     m_clientArea->UpdateDisplay();
 
 
     m_clientArea->UpdateDisplay();