]> git.saurik.com Git - wxWidgets.git/commitdiff
Closes #10495: wxDataViewCtrl needs a way to start the label editor programmatically...
authorRobert Roebling <robert@roebling.de>
Mon, 1 Jun 2009 13:57:38 +0000 (13:57 +0000)
committerRobert Roebling <robert@roebling.de>
Mon, 1 Jun 2009 13:57:38 +0000 (13:57 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60857 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dataview.h
samples/dataview/dataview.cpp
src/common/datavcmn.cpp
src/generic/datavgen.cpp

index b9b1f37218f2717b8e782e827384e594cfa20790..aa2ec3025b424c737cbdce1fe4b4b1a2b12acd75 100644 (file)
@@ -28,7 +28,7 @@
 class WXDLLIMPEXP_FWD_CORE wxImageList;
 
 #if !(defined(__WXGTK20__) || defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
 class WXDLLIMPEXP_FWD_CORE wxImageList;
 
 #if !(defined(__WXGTK20__) || defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
-// #if !(defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
+// #if !(defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
     #define wxHAS_GENERIC_DATAVIEWCTRL
 #endif
 
     #define wxHAS_GENERIC_DATAVIEWCTRL
 #endif
 
index cf7f30e41c6aaa503e3dc419902e48b06dd81e20..77d5875e55a70ddbb2781172ec70c141f6fb7ec4 100644 (file)
@@ -854,8 +854,11 @@ void MyFrame::OnStartEditing( wxDataViewEvent &event )
         if (!m_log)
            return;
            
         if (!m_log)
            return;
            
-        wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING vetoed, Item: %s", artist );
+        wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING vetoed. Artist: %s", artist );
     }
     }
+    else
+        wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING not vetoed. Artist: %s", artist );
+    
 }
 
 void MyFrame::OnEditingStarted( wxDataViewEvent &event )
 }
 
 void MyFrame::OnEditingStarted( wxDataViewEvent &event )
index 8aa0657ce583851d122e50e994b89e2480b10831..72475e06b21b0b86e807bbc1ce5f9045fa5f0b22 100644 (file)
@@ -681,13 +681,30 @@ public:
 
 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
 {
 
 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
 {
+    wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner();
+
+    // Before doing anything we send an event asking if editing of this item is really wanted.
+    wxDataViewEvent start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, dv_ctrl->GetId() );
+    start_event.SetDataViewColumn( GetOwner() );
+    start_event.SetModel( dv_ctrl->GetModel() );
+    start_event.SetItem( item );
+    start_event.SetEventObject( dv_ctrl );
+    dv_ctrl->GetEventHandler()->ProcessEvent( start_event );
+    if( !start_event.IsAllowed() )
+        return false;
+
     m_item = item; // remember for later
 
     unsigned int col = GetOwner()->GetModelColumn();
     wxVariant value;
     m_item = item; // remember for later
 
     unsigned int col = GetOwner()->GetModelColumn();
     wxVariant value;
-    GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col );
+    dv_ctrl->GetModel()->GetValue( value, item, col );
+
+    m_editorCtrl = CreateEditorCtrl( dv_ctrl->GetMainWindow(), labelRect, value );
+
+       // there might be no editor control for the given item
+    if(!m_editorCtrl)
+        return false;
 
 
-    m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value );
     (void) new wxKillRef( m_editorCtrl.get() );
 
     wxDataViewEditorCtrlEvtHandler *handler =
     (void) new wxKillRef( m_editorCtrl.get() );
 
     wxDataViewEditorCtrlEvtHandler *handler =
@@ -695,10 +712,6 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la
 
     m_editorCtrl->PushEventHandler( handler );
 
 
     m_editorCtrl->PushEventHandler( handler );
 
-    // there might be no editor control for the given item
-    if (!m_editorCtrl)
-        return false;
-        
 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
     handler->SetFocusOnIdle();
 #else
 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
     handler->SetFocusOnIdle();
 #else
@@ -706,18 +719,20 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la
 #endif
 
     // Now we should send Editing Started event
 #endif
 
     // Now we should send Editing Started event
-    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, GetOwner()->GetOwner()->GetId() );
+    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, dv_ctrl->GetId() );
     event.SetDataViewColumn( GetOwner() );
     event.SetDataViewColumn( GetOwner() );
-    event.SetModel( GetOwner()->GetOwner()->GetModel() );
+    event.SetModel( dv_ctrl->GetModel() );
     event.SetItem( item );
     event.SetItem( item );
-    GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
+    event.SetEventObject( dv_ctrl );
+    dv_ctrl->GetEventHandler()->ProcessEvent( event );
 
     return true;
 }
 
 void wxDataViewRendererBase::CancelEditing()
 {
 
     return true;
 }
 
 void wxDataViewRendererBase::CancelEditing()
 {
-    if (!m_editorCtrl) return;
+    if (!m_editorCtrl)
+        return;
 
     GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
 
 
     GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
 
@@ -727,12 +742,15 @@ void wxDataViewRendererBase::CancelEditing()
 
 bool wxDataViewRendererBase::FinishEditing()
 {
 
 bool wxDataViewRendererBase::FinishEditing()
 {
-    if (!m_editorCtrl) return true;
+    if (!m_editorCtrl)
+        return true;
 
     wxVariant value;
     GetValueFromEditorCtrl( m_editorCtrl, value );
 
 
     wxVariant value;
     GetValueFromEditorCtrl( m_editorCtrl, value );
 
-    GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
+    wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner();
+
+    dv_ctrl->GetMainWindow()->SetFocus();
 
     m_editorCtrl->Hide();
     wxPendingDelete.Append( m_editorCtrl );
 
     m_editorCtrl->Hide();
     wxPendingDelete.Append( m_editorCtrl );
@@ -741,15 +759,16 @@ bool wxDataViewRendererBase::FinishEditing()
         return false;
 
     unsigned int col = GetOwner()->GetModelColumn();
         return false;
 
     unsigned int col = GetOwner()->GetModelColumn();
-    GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col );
-    GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col );
+    dv_ctrl->GetModel()->SetValue( value, m_item, col );
+    dv_ctrl->GetModel()->ValueChanged( m_item, col );
 
     // Now we should send Editing Done event
 
     // Now we should send Editing Done event
-    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() );
+    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, dv_ctrl->GetId() );
     event.SetDataViewColumn( GetOwner() );
     event.SetDataViewColumn( GetOwner() );
-    event.SetModel( GetOwner()->GetOwner()->GetModel() );
+    event.SetModel( dv_ctrl->GetModel() );
     event.SetItem( m_item );
     event.SetItem( m_item );
-    GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
+    event.SetEventObject( dv_ctrl );
+    dv_ctrl->GetEventHandler()->ProcessEvent( event );
 
     return true;
 }
 
     return true;
 }
index afe948e080c3b983d31a686f16ea4f15a3bb177c..17cb936bc38123ff5dc28c590168b33d29d78d0f 100644 (file)
@@ -716,9 +716,15 @@ bool wxDataViewTextRenderer::HasEditorCtrl() const
 wxControl* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent,
         wxRect labelRect, const wxVariant &value )
 {
 wxControl* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent,
         wxRect labelRect, const wxVariant &value )
 {
-    return new wxTextCtrl( parent, wxID_ANY, value,
-                        wxPoint(labelRect.x,labelRect.y),
-                        wxSize(labelRect.width,labelRect.height) );
+    wxTextCtrl* ctrl = new wxTextCtrl( parent, wxID_ANY, value,
+                                       wxPoint(labelRect.x,labelRect.y),
+                                       wxSize(labelRect.width,labelRect.height) );
+
+    // select the text in the control an place the cursor at the end
+    ctrl->SetInsertionPointEnd();
+    ctrl->SelectAll();
+
+    return ctrl;
 }
 
 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant &value )
 }
 
 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant &value )
@@ -1145,9 +1151,15 @@ wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect
         labelRect.width -= w;
     }
 
         labelRect.width -= w;
     }
 
-    return new wxTextCtrl( parent, wxID_ANY, text,
-                           wxPoint(labelRect.x,labelRect.y),
-                           wxSize(labelRect.width,labelRect.height) );
+    wxTextCtrl* ctrl = new wxTextCtrl( parent, wxID_ANY, text,
+                                       wxPoint(labelRect.x,labelRect.y),
+                                       wxSize(labelRect.width,labelRect.height) );
+
+    // select the text in the control an place the cursor at the end
+    ctrl->SetInsertionPointEnd();
+    ctrl->SelectAll();
+
+    return ctrl;
 }
 
 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant& value )
 }
 
 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant& value )
@@ -1939,42 +1951,10 @@ void wxDataViewMainWindow::OnRenameTimer()
         wxSafeYield();
     }
 
         wxSafeYield();
     }
 
-    int xpos = 0;
-    unsigned int cols = GetOwner()->GetColumnCount();
-    unsigned int i;
-    for (i = 0; i < cols; i++)
-    {
-        wxDataViewColumn *c = GetOwner()->GetColumnAt( i );
-        if (c->IsHidden())
-            continue;      // skip it!
-
-        if (c == m_currentCol)
-            break;
-        xpos += c->GetWidth();
-    }
-
-    // we have to take an expander column into account and compute its indentation
-    // to get the editor at the correct x position where the actual text is
-    int indent = 0;
-    if (!IsVirtualList() && GetOwner()->GetExpanderColumn() == m_currentCol)
-    {
-        wxDataViewTreeNode* node = GetTreeNodeByRow(m_currentRow);
-        indent = GetOwner()->GetIndent() * node->GetIndentLevel();
-        indent = indent + m_lineHeight;
-
-        if(!node->HasChildren())
-            delete node;
-    }
-
-    wxRect labelRect( xpos + indent,
-                    GetLineStart( m_currentRow ),
-                    m_currentCol->GetWidth() - indent,
-                    GetLineHeight( m_currentRow ) );
+    wxDataViewItem item = GetItemByRow( m_currentRow );
 
 
-    GetOwner()->CalcScrolledPosition( labelRect.x, labelRect.y,
-                                    &labelRect.x, &labelRect.y);
+    wxRect labelRect = GetItemRect(item, m_currentCol);
 
 
-    wxDataViewItem item = GetItemByRow( m_currentRow );
     m_currentCol->GetRenderer()->StartEditing( item, labelRect );
 }
 
     m_currentCol->GetRenderer()->StartEditing( item, labelRect );
 }
 
@@ -3445,14 +3425,17 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
             if (!node)
                 break;
 
             if (!node)
                 break;
 
-            if (node->HasChildren())
+            if (node->HasChildren() && node->IsOpen())
             {
                 Collapse(m_currentRow);
             }
             {
                 Collapse(m_currentRow);
             }
-            else
+            else    // if the node is already closed we move the selection to its parent
             {
                 wxDataViewTreeNode *parent_node = node->GetParent();
             {
                 wxDataViewTreeNode *parent_node = node->GetParent();
-                delete node;
+
+                if(!node->HasChildren())
+                    delete node;
+
                 if (parent_node)
                 {
                     int parent = GetRowByItem( parent_node->GetItem() );
                 if (parent_node)
                 {
                     int parent = GetRowByItem( parent_node->GetItem() );
@@ -3462,6 +3445,7 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
                         SelectRow( row, false);
                         SelectRow( parent, true );
                         ChangeCurrentRow( parent );
                         SelectRow( row, false);
                         SelectRow( parent, true );
                         ChangeCurrentRow( parent );
+                        GetOwner()->EnsureVisible( parent, -1 );
                         SendSelectionChangedEvent( parent_node->GetItem() );
                     }
                 }
                         SendSelectionChangedEvent( parent_node->GetItem() );
                     }
                 }
@@ -3478,6 +3462,7 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
                 SelectRow( row, false );
                 SelectRow( row + 1, true );
                 ChangeCurrentRow( row + 1 );
                 SelectRow( row, false );
                 SelectRow( row + 1, true );
                 ChangeCurrentRow( row + 1 );
+                GetOwner()->EnsureVisible( row + 1, -1 );
                 SendSelectionChangedEvent( GetItemByRow(row+1) );
             }
             break;
                 SendSelectionChangedEvent( GetItemByRow(row+1) );
             }
             break;
@@ -3516,6 +3501,16 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
             }
             break;
 
             }
             break;
 
+        case WXK_F2:
+            {
+                if(m_selection.size() == 1)
+                {
+                    // TODO: we need to revise that when we have a concept for a 'current column'
+                    GetOwner()->StartEditor(GetItemByRow(m_selection[0]), 0);
+                }
+            }
+            break;
+
         default:
             event.Skip();
     }
         default:
             event.Skip();
     }
@@ -3759,7 +3754,9 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
             SelectRow(m_currentRow,true);
             SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
         }
             SelectRow(m_currentRow,true);
             SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
         }
-
+    }
+    else if (event.RightUp())
+    {
         wxVariant value;
         model->GetValue( value, item, col->GetModelColumn() );
         wxWindow *parent = GetParent();
         wxVariant value;
         model->GetValue( value, item, col->GetModelColumn() );
         wxWindow *parent = GetParent();