]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/datavgen.cpp
support for file-type popup, compatible for 10.4+, solves #12429
[wxWidgets.git] / src / generic / datavgen.cpp
index babb972b29d50421a7cf69fabf7e64ddf36fedb3..ca7dc0a9bd50219f3b9dd4b98f6505a7070f4f36 100644 (file)
@@ -145,7 +145,6 @@ protected:
         return *(GetOwner()->GetColumn(idx));
     }
 
-    // FIXME: currently unused
     virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle)
     {
         wxDataViewCtrl * const owner = GetOwner();
@@ -435,7 +434,7 @@ public:
     bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
     bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
     bool ItemChanged( const wxDataViewItem &item );
-    bool ValueChanged( const wxDataViewItem &item, unsigned int col );
+    bool ValueChanged( const wxDataViewItem &item, unsigned int model_column );
     bool Cleared();
     void Resort()
     {
@@ -845,7 +844,8 @@ bool wxDataViewToggleRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state
     int flags = 0;
     if (m_toggle)
         flags |= wxCONTROL_CHECKED;
-    if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE)
+    if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE ||
+        GetEnabled() == false)
         flags |= wxCONTROL_DISABLED;
 
     // check boxes we draw must always have the same, standard size (if it's
@@ -868,7 +868,10 @@ void wxDataViewToggleRenderer::WXOnActivate(wxDataViewModel *model,
                                             const wxDataViewItem & item,
                                             unsigned int col)
 {
-    model->ChangeValue(!valueOld.GetBool(), item, col);
+    if (model->IsEnabled(item, col))
+    {
+        model->ChangeValue(!valueOld.GetBool(), item, col);
+    }
 }
 
 wxSize wxDataViewToggleRenderer::GetSize() const
@@ -1661,22 +1664,23 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
         dc.SetPen(m_penRule);
         dc.SetBrush(*wxTRANSPARENT_BRUSH);
 
-        int x = x_start;
+        // NB: Vertical rules are drawn in the last pixel of a column so that
+        //     they align perfectly with native MSW wxHeaderCtrl as well as for
+        //     consistency with MSW native list control. There's no vertical
+        //     rule at the most-left side of the control.
+
+        int x = x_start - 1;
         for (unsigned int i = col_start; i < col_last; i++)
         {
             wxDataViewColumn *col = GetOwner()->GetColumnAt(i);
             if (col->IsHidden())
                 continue;       // skip it
 
+            x += col->GetWidth();
+
             dc.DrawLine(x, GetLineStart( item_start ),
                         x, GetLineStart( item_last ) );
-
-            x += col->GetWidth();
         }
-
-        // Draw last vertical rule
-        dc.DrawLine(x, GetLineStart( item_start ),
-                    x, GetLineStart( item_last ) );
     }
 
     // redraw the background for the items which are selected/current
@@ -2069,9 +2073,23 @@ bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item)
     return true;
 }
 
-bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned int col )
+bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned int model_column )
 {
-    GetOwner()->InvalidateColBestWidth(col);
+    int view_column = -1;
+    unsigned int n_col = m_owner->GetColumnCount();
+    for (unsigned i = 0; i < n_col; i++)
+    {
+        wxDataViewColumn *column = m_owner->GetColumn( i );
+        if (column->GetModelColumn() == model_column)
+        {
+            view_column = (int) i;
+            break;
+        }
+    }
+    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
@@ -2091,8 +2109,8 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
     le.SetEventObject(parent);
     le.SetModel(GetOwner()->GetModel());
     le.SetItem(item);
-    le.SetColumn(col);
-    le.SetDataViewColumn(GetOwner()->GetColumn(col));
+    le.SetColumn(view_column);
+    le.SetDataViewColumn(GetOwner()->GetColumn(view_column));
     parent->GetEventHandler()->ProcessEvent(le);
 
     return true;
@@ -2150,6 +2168,8 @@ void wxDataViewMainWindow::RecalculateDisplay()
 
 void wxDataViewMainWindow::ScrollWindow( int dx, int dy, const wxRect *rect )
 {
+    m_underMouse = NULL;
+
     wxWindow::ScrollWindow( dx, dy, rect );
 
     if (GetOwner()->m_headerArea)
@@ -2158,6 +2178,8 @@ void wxDataViewMainWindow::ScrollWindow( int dx, int dy, const wxRect *rect )
 
 void wxDataViewMainWindow::ScrollTo( int rows, int column )
 {
+    m_underMouse = NULL;
+
     int x, y;
     m_owner->GetScrollPixelsPerUnit( &x, &y );
     int sy = GetLineStart( rows )/y;
@@ -3469,13 +3491,17 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
         xpos += c->GetWidth();
     }
     if (!col)
+    {
+        event.Skip();
         return;
+    }
 
     wxDataViewRenderer *cell = col->GetRenderer();
     unsigned int current = GetLineAt( y );
     if ((current >= GetRowCount()) || (x > GetEndOfLastCol()))
     {
         // Unselect all if below the last row ?
+        event.Skip();
         return;
     }
 
@@ -3623,6 +3649,8 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
                 wxWindow *parent = GetParent();
                 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, parent->GetId());
                 le.SetItem( item );
+                le.SetColumn( col->GetModelColumn() );
+                le.SetDataViewColumn( col );
                 le.SetEventObject(parent);
                 le.SetModel(GetOwner()->GetModel());
 
@@ -3693,6 +3721,8 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
         wxWindow *parent = GetParent();
         wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, parent->GetId());
         le.SetItem( item );
+        le.SetColumn( col->GetModelColumn() );
+        le.SetDataViewColumn( col );
         le.SetEventObject(parent);
         le.SetModel(GetOwner()->GetModel());
         le.SetValue(value);
@@ -4208,7 +4238,7 @@ unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx) const
         calculator.UpdateWithRow(row);
     }
 
-    // row is the first unmeasured item now; that's out value of N/2
+    // row is the first unmeasured item now; that's our value of N/2
 
     if ( row < count )
     {
@@ -4248,8 +4278,6 @@ unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx) const
 
     const_cast<wxDataViewCtrl*>(this)->m_colsBestWidths[idx] = max_width;
     return max_width;
-
-    #undef MEASURE_ITEM
 }
 
 void wxDataViewCtrl::ColumnMoved(wxDataViewColumn * WXUNUSED(col),
@@ -4297,8 +4325,9 @@ void wxDataViewCtrl::InvalidateColBestWidths()
 
     if ( m_headerArea )
     {
-        // this updates visual appearance of columns 0 and up, not just 0
-        m_headerArea->UpdateColumn(0);
+        const unsigned cols = m_headerArea->GetColumnCount();
+        for ( unsigned i = 0; i < cols; i++ )
+            m_headerArea->UpdateColumn(i);
     }
 }
 
@@ -4604,7 +4633,8 @@ void wxDataViewCtrl::StartEditor( const wxDataViewItem & item, unsigned int colu
 
     wxRect itemRect = GetItemRect(item, col);
     wxDataViewRenderer* renderer = col->GetRenderer();
-    renderer->StartEditing(item, itemRect);
+    if (renderer->GetMode() == wxDATAVIEW_CELL_EDITABLE)
+        renderer->StartEditing(item, itemRect);
 }
 
 #endif // !wxUSE_GENERICDATAVIEWCTRL