]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/datavgen.cpp
Add backend descriptions for all backends to the documentation.
[wxWidgets.git] / src / generic / datavgen.cpp
index 2531bad861c8f47a64ca1f18dd6e4e86f52edf6e..bdc389ad666390c374662c5c18d328f1bc55b2cc 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();
@@ -215,6 +214,8 @@ private:
             model->Resort();
 
         owner->OnColumnChange(idx);
+
+        SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, idx);
     }
 
     void OnRClick(wxHeaderCtrlEvent& event)
@@ -533,6 +534,8 @@ public:
     int GetLineHeight( unsigned int row ) const; // m_lineHeight in fixed mode
     int GetLineAt( unsigned int y ) const;       // y / m_lineHeight in fixed mode
 
+    void SetRowHeight( int lineHeight ) { m_lineHeight = lineHeight; }
+
     // Some useful functions for row and item mapping
     wxDataViewItem GetItemByRow( unsigned int row ) const;
     int GetRowByItem( const wxDataViewItem & item ) const;
@@ -733,7 +736,7 @@ bool wxDataViewTextRenderer::HasEditorCtrl() const
     return true;
 }
 
-wxControl* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent,
+wxWindow* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent,
         wxRect labelRect, const wxVariant &value )
 {
     wxTextCtrl* ctrl = new wxTextCtrl( parent, wxID_ANY, value,
@@ -747,7 +750,7 @@ wxControl* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent,
     return ctrl;
 }
 
-bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant &value )
+bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxWindow *editor, wxVariant &value )
 {
     wxTextCtrl *text = (wxTextCtrl*) editor;
     value = text->GetValue();
@@ -797,9 +800,9 @@ bool wxDataViewBitmapRenderer::GetValue( wxVariant& WXUNUSED(value) ) const
 
 bool wxDataViewBitmapRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
 {
-    if (m_bitmap.Ok())
+    if (m_bitmap.IsOk())
         dc->DrawBitmap( m_bitmap, cell.x, cell.y );
-    else if (m_icon.Ok())
+    else if (m_icon.IsOk())
         dc->DrawIcon( m_icon, cell.x, cell.y );
 
     return true;
@@ -807,9 +810,9 @@ bool wxDataViewBitmapRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state
 
 wxSize wxDataViewBitmapRenderer::GetSize() const
 {
-    if (m_bitmap.Ok())
+    if (m_bitmap.IsOk())
         return wxSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() );
-    else if (m_icon.Ok())
+    else if (m_icon.IsOk())
         return wxSize( m_icon.GetWidth(), m_icon.GetHeight() );
 
     return wxSize(wxDVC_DEFAULT_RENDERER_SIZE,wxDVC_DEFAULT_RENDERER_SIZE);
@@ -864,15 +867,23 @@ bool wxDataViewToggleRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state
     return true;
 }
 
-void wxDataViewToggleRenderer::WXOnActivate(wxDataViewModel *model,
-                                            const wxVariant& valueOld,
-                                            const wxDataViewItem & item,
-                                            unsigned int col)
+bool wxDataViewToggleRenderer::WXOnLeftClick(const wxPoint& cursor,
+                                             const wxRect& WXUNUSED(cell),
+                                             wxDataViewModel *model,
+                                             const wxDataViewItem& item,
+                                             unsigned int col)
 {
+    // only react to clicks directly on the checkbox, not elsewhere in the same cell:
+    if (!wxRect(GetSize()).Contains(cursor))
+        return false;
+
     if (model->IsEnabled(item, col))
     {
-        model->ChangeValue(!valueOld.GetBool(), item, col);
+        model->ChangeValue(!m_toggle, item, col);
+        return true;
     }
+
+    return false;
 }
 
 wxSize wxDataViewToggleRenderer::GetSize() const
@@ -1024,12 +1035,12 @@ wxSize wxDataViewDateRenderer::GetSize() const
     return GetTextExtent(m_date.FormatDate());
 }
 
-void wxDataViewDateRenderer::WXOnActivate(wxDataViewModel *model,
-                                          const wxVariant& valueOld,
-                                          const wxDataViewItem & item,
-                                          unsigned int col )
+bool wxDataViewDateRenderer::WXOnActivate(const wxRect& WXUNUSED(cell),
+                                          wxDataViewModel *model,
+                                          const wxDataViewItem& item,
+                                          unsigned int col)
 {
-    wxDateTime dtOld = valueOld.GetDateTime();
+    wxDateTime dtOld = m_date;
 
 #if wxUSE_DATE_RENDERER_POPUP
     wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient(
@@ -1041,6 +1052,8 @@ void wxDataViewDateRenderer::WXOnActivate(wxDataViewModel *model,
 #else // !wxUSE_DATE_RENDERER_POPUP
     wxMessageBox(dtOld.Format());
 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
+
+    return true;
 }
 
 // ---------------------------------------------------------
@@ -1097,7 +1110,7 @@ wxSize wxDataViewIconTextRenderer::GetSize() const
     return wxSize(80,20);
 }
 
-wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant& value)
+wxWindow* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant& value)
 {
     wxDataViewIconText iconText;
     iconText << value;
@@ -1123,7 +1136,7 @@ wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect
     return ctrl;
 }
 
-bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant& value )
+bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxWindow *editor, wxVariant& value )
 {
     wxTextCtrl *text = (wxTextCtrl*) editor;
 
@@ -1588,6 +1601,12 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
     dc.DrawRectangle(GetClientSize());
 #endif
 
+    if ( IsEmpty() )
+    {
+        // No items to draw.
+        return;
+    }
+
     // prepare the DC
     GetOwner()->PrepareDC( dc );
     dc.SetFont( GetFont() );
@@ -1601,10 +1620,11 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
         wxMin( (int)(  GetLineAt( wxMax(0,update.y+update.height) ) - item_start + 1),
             (int)(GetRowCount( ) - item_start));
     unsigned int item_last = item_start + item_count;
-    // Get the parent of DataViewCtrl
-    wxWindow *parent = GetParent()->GetParent();
+
+    // Send the event to wxDataViewCtrl itself.
+    wxWindow * const parent = GetParent();
     wxDataViewEvent cache_event(wxEVT_COMMAND_DATAVIEW_CACHE_HINT, parent->GetId());
-    cache_event.SetEventObject(GetParent());
+    cache_event.SetEventObject(parent);
     cache_event.SetCache(item_start, item_last - 1);
     parent->ProcessWindowEvent(cache_event);
 
@@ -1665,22 +1685,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
@@ -1752,8 +1773,11 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
 
                 dataitem = node->GetItem();
 
-                if ((i > 0) && model->IsContainer(dataitem) &&
-                    !model->HasContainerColumns(dataitem))
+                // Skip all columns of "container" rows except the expander
+                // column itself unless HasContainerColumns() overrides this.
+                if ( col != GetOwner()->GetExpanderColumn() &&
+                        model->IsContainer(dataitem) &&
+                            !model->HasContainerColumns(dataitem) )
                     continue;
             }
             else
@@ -3010,7 +3034,7 @@ wxDataViewTreeNode * wxDataViewMainWindow::FindNode( const wxDataViewItem & item
     // Find the item along the parent-chain.
     // This algorithm is designed to speed up the node-finding method
     wxDataViewTreeNode* node = m_root;
-    for( unsigned iter = parentChain.size()-1; iter>=0; --iter )
+    for( unsigned iter = parentChain.size()-1; ; --iter )
     {
         if( node->HasChildren() )
         {
@@ -3041,6 +3065,9 @@ wxDataViewTreeNode * wxDataViewMainWindow::FindNode( const wxDataViewItem & item
         }
         else
             return NULL;
+
+        if ( !iter )
+            break;
     }
     return NULL;
 }
@@ -3352,7 +3379,7 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
             break;
 
         case WXK_DOWN:
-            if ( m_currentRow < GetRowCount() - 1 )
+            if ( m_currentRow + 1 < GetRowCount() )
                 OnArrowChar( m_currentRow + 1, event );
             break;
         // Add the process for tree expanding/collapsing
@@ -3630,19 +3657,11 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
             {
                 const unsigned colIdx = col->GetModelColumn();
 
-                wxVariant value;
-                model->GetValue( value, item, colIdx );
-
-                cell->WXOnActivate(model, value, item, colIdx);
-
-                if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
-                {
-                    cell->SetValue( value );
+                cell->PrepareForItem(model, item, colIdx);
 
-                    wxRect cell_rect( xpos, GetLineStart( current ),
-                                    col->GetWidth(), GetLineHeight( current ) );
-                    custom->Activate( cell_rect, model, item, colIdx );
-                }
+                wxRect cell_rect( xpos, GetLineStart( current ),
+                                col->GetWidth(), GetLineHeight( current ) );
+                cell->WXOnActivate( cell_rect, model, item, colIdx );
             }
             else
             {
@@ -3709,8 +3728,10 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
         if (!IsRowSelected(current))
         {
             SelectAllRows(false);
+            const unsigned oldCurrent = m_currentRow;
             ChangeCurrentRow(current);
             SelectRow(m_currentRow,true);
+            RefreshRow(oldCurrent);
             SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
         }
     }
@@ -3813,53 +3834,50 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
         // Call LeftClick after everything else as under GTK+
         if (cell->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE)
         {
-            if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
-            {
-                // notify cell about click
-                custom->PrepareForItem(model, item, col->GetModelColumn());
+            // notify cell about click
+            cell->PrepareForItem(model, item, col->GetModelColumn());
 
-                wxRect cell_rect( xpos, GetLineStart( current ),
-                                  col->GetWidth(), GetLineHeight( current ) );
+            wxRect cell_rect( xpos, GetLineStart( current ),
+                              col->GetWidth(), 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
-                // used by the renderer after calculation of alignment etc.
+            // Report position relative to the cell's custom area, i.e.
+            // no the entire space as given by the control but the one
+            // used by the renderer after calculation of alignment etc.
 
-                // adjust the rectangle ourselves to account for the alignment
-                wxRect rectItem = cell_rect;
-                const int align = custom->GetAlignment();
-                if ( align != wxDVR_DEFAULT_ALIGNMENT )
-                {
-                    const wxSize size = custom->GetSize();
+            // adjust the rectangle ourselves to account for the alignment
+            wxRect rectItem = cell_rect;
+            const int align = cell->GetAlignment();
+            if ( align != wxDVR_DEFAULT_ALIGNMENT )
+            {
+                const wxSize size = cell->GetSize();
 
-                    if ( size.x >= 0 && size.x < cell_rect.width )
-                    {
-                        if ( align & wxALIGN_CENTER_HORIZONTAL )
-                            rectItem.x += (cell_rect.width - size.x)/2;
-                        else if ( align & wxALIGN_RIGHT )
-                            rectItem.x += cell_rect.width - size.x;
-                        // else: wxALIGN_LEFT is the default
-                    }
+                if ( size.x >= 0 && size.x < cell_rect.width )
+                {
+                    if ( align & wxALIGN_CENTER_HORIZONTAL )
+                        rectItem.x += (cell_rect.width - size.x)/2;
+                    else if ( align & wxALIGN_RIGHT )
+                        rectItem.x += cell_rect.width - size.x;
+                    // else: wxALIGN_LEFT is the default
+                }
 
-                    if ( size.y >= 0 && size.y < cell_rect.height )
-                    {
-                        if ( align & wxALIGN_CENTER_VERTICAL )
-                            rectItem.y += (cell_rect.height - size.y)/2;
-                        else if ( align & wxALIGN_BOTTOM )
-                            rectItem.y += cell_rect.height - size.y;
-                        // else: wxALIGN_TOP is the default
-                    }
+                if ( size.y >= 0 && size.y < cell_rect.height )
+                {
+                    if ( align & wxALIGN_CENTER_VERTICAL )
+                        rectItem.y += (cell_rect.height - size.y)/2;
+                    else if ( align & wxALIGN_BOTTOM )
+                        rectItem.y += cell_rect.height - size.y;
+                    // else: wxALIGN_TOP is the default
                 }
+            }
 
-                wxPoint pos( event.GetPosition() );
-                pos.x -= rectItem.x;
-                pos.y -= rectItem.y;
+            wxPoint pos( event.GetPosition() );
+            pos.x -= rectItem.x;
+            pos.y -= rectItem.y;
 
-                m_owner->CalcUnscrolledPosition( pos.x, pos.y, &pos.x, &pos.y );
+            m_owner->CalcUnscrolledPosition( pos.x, pos.y, &pos.x, &pos.y );
 
-                 /* ignore ret */ custom->LeftClick( pos, cell_rect,
-                                  model, item, col->GetModelColumn());
-            }
+             /* ignore ret */ cell->WXOnLeftClick( pos, cell_rect,
+                              model, item, col->GetModelColumn());
         }
     }
 }
@@ -4014,6 +4032,16 @@ void wxDataViewCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
     Layout();
 
     AdjustScrollbars();
+
+    // We must redraw the headers if their height changed. Normally this
+    // shouldn't happen as the control shouldn't let itself be resized beneath
+    // its minimal height but avoid the display artefacts that appear if it
+    // does happen, e.g. because there is really not enough vertical space.
+    if ( !HasFlag(wxDV_NO_HEADER) && m_headerArea &&
+            m_headerArea->GetSize().y <= m_headerArea->GetBestSize(). y )
+    {
+        m_headerArea->Refresh();
+    }
 }
 
 void wxDataViewCtrl::SetFocus()
@@ -4118,6 +4146,16 @@ unsigned int wxDataViewCtrl::GetColumnCount() const
     return m_cols.GetCount();
 }
 
+bool wxDataViewCtrl::SetRowHeight( int lineHeight )
+{
+    if ( !m_clientArea )
+        return false;
+
+    m_clientArea->SetRowHeight(lineHeight);
+
+    return true;
+}
+
 wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int idx ) const
 {
     return m_cols[idx];
@@ -4325,8 +4363,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);
     }
 }