From eeea3b039ef9bf03c17f80ab911cf65f084731bd Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 31 May 2011 19:36:47 +0000 Subject: [PATCH] Virtualize StartEditor and add implementations for the ports that can do it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67817 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dataview.h | 2 ++ include/wx/generic/dataview.h | 2 +- include/wx/gtk/dataview.h | 2 ++ include/wx/osx/carbon/dataview.h | 2 ++ include/wx/osx/cocoa/dataview.h | 2 ++ include/wx/osx/core/dataview.h | 1 + include/wx/osx/dataview.h | 2 ++ interface/wx/dataview.h | 8 ++++++++ samples/dataview/dataview.cpp | 7 +++++-- src/gtk/dataview.cpp | 27 +++++++++++++++++++++++++++ src/osx/carbon/dataview.cpp | 5 +++++ src/osx/cocoa/dataview.mm | 5 +++++ src/osx/dataview_osx.cpp | 5 +++++ 13 files changed, 67 insertions(+), 3 deletions(-) diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 7fcc15873f..f7add4c6d5 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -700,6 +700,8 @@ public: const wxDataViewColumn *column = NULL ) = 0; virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0; virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0; + + virtual void StartEditor( const wxDataViewItem & item, unsigned int column ) { } #if wxUSE_DRAG_AND_DROP virtual bool EnableDragSource(const wxDataFormat& WXUNUSED(format)) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index d47b028b04..16117adb45 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -185,7 +185,7 @@ public: virtual wxBorder GetDefaultBorder() const; - void StartEditor( const wxDataViewItem & item, unsigned int column ); + virtual void StartEditor( const wxDataViewItem & item, unsigned int column ); protected: virtual int GetSelections( wxArrayInt & sel ) const; diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index 03bcbdf1c3..73254d4892 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -158,6 +158,8 @@ public: wxDataViewColumn *&column ) const; virtual wxRect GetItemRect( const wxDataViewItem &item, const wxDataViewColumn *column = NULL ) const; + + virtual void StartEditor( const wxDataViewItem & item, unsigned int column ); virtual void Expand( const wxDataViewItem & item ); virtual void Collapse( const wxDataViewItem & item ); diff --git a/include/wx/osx/carbon/dataview.h b/include/wx/osx/carbon/dataview.h index 056a2a895c..b6d88a2661 100644 --- a/include/wx/osx/carbon/dataview.h +++ b/include/wx/osx/carbon/dataview.h @@ -427,6 +427,8 @@ public: virtual void SetRowHeight(wxDataViewItem const& item, unsigned int height); virtual void OnSize (); + virtual void StartEditor( const wxDataViewItem & item, unsigned int column ); + // // other methods // diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index 335bce5ad7..624c2cb3f7 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -496,6 +496,8 @@ public: wxDataViewColumn*& columnPtr) const; virtual void SetRowHeight(const wxDataViewItem& item, unsigned int height); virtual void OnSize(); + + virtual void StartEditor( const wxDataViewItem & item, unsigned int column ); // drag & drop helper methods wxDataFormat GetDnDDataFormat(wxDataObjectComposite* dataObjects); diff --git a/include/wx/osx/core/dataview.h b/include/wx/osx/core/dataview.h index 8a24aaefd3..1a554d704b 100644 --- a/include/wx/osx/core/dataview.h +++ b/include/wx/osx/core/dataview.h @@ -109,6 +109,7 @@ public: virtual void HitTest (wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const = 0; // return the item and column pointer that contains with the passed point virtual void SetRowHeight(wxDataViewItem const& item, unsigned int height) = 0; // sets the height of the row containg the passed item in the native control virtual void OnSize (void) = 0; // updates the layout of the native control after a size event + virtual void StartEditor( const wxDataViewItem & item, unsigned int column ) = 0; // starts editing the passed in item and column }; #endif // _WX_DATAVIEWCTRL_CORE_H_ diff --git a/include/wx/osx/dataview.h b/include/wx/osx/dataview.h index e2ca2a2405..e585fa01d3 100644 --- a/include/wx/osx/dataview.h +++ b/include/wx/osx/dataview.h @@ -201,6 +201,8 @@ public: // finishes editing of custom items; if no custom item is currently edited the method does nothing void FinishCustomItemEditing(); + + virtual void StartEditor( const wxDataViewItem & item, unsigned int column ); // returns the n-th pointer to a column; // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index aebeef76e3..1d2ab0a8a5 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -1095,6 +1095,14 @@ public: */ virtual void SetSelections(const wxDataViewItemArray& sel); + /** + Programmatically starts editing the given item on the given column. + Currently not implemented on wxOSX Carbon. + @since 2.9.2 + */ + + virtual void StartEditor(const wxDataViewItem & item, unsigned int column); + /** Unselect the given item. */ diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index b9d424622a..ce215ffaaf 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -1160,8 +1160,11 @@ void MyFrame::OnAddTreeItem(wxCommandEvent& WXUNUSED(event)) { wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3]; wxDataViewItem selected = ctrl->GetSelection(); - if (ctrl->IsContainer(selected)) - ctrl->AppendItem( selected, "Item", 0 ); + if (ctrl->IsContainer(selected)) { + wxDataViewItem newitem = ctrl->AppendItem( selected, "Item", 0 ); + ctrl->Select(newitem); + ctrl->StartEditor(newitem, 0); + } } void MyFrame::OnAddTreeContainerItem(wxCommandEvent& WXUNUSED(event)) diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 19ddb6a8d8..c268ff4682 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -4836,6 +4836,33 @@ void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item) gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview), path, NULL, FALSE); } +void wxDataViewCtrl::StartEditor(const wxDataViewItem& item, unsigned int column) +{ + wxCHECK_RET( m_treeview, + "Current item can't be set before creating the control." ); + + // We need to make sure the model knows about this item or the path would + // be invalid and gtk_tree_view_set_cursor() would silently do nothing. + ExpandAncestors(item); + + wxDataViewColumn *dvcolumn = GetColumn(column); + wxASSERT_MSG(dvcolumn, "Could not retrieve column"); + GtkTreeViewColumn *gcolumn = GTK_TREE_VIEW_COLUMN(dvcolumn->GetGtkHandle()); + + // We also need to preserve the existing selection from changing. + // Unfortunately the only way to do it seems to use our own selection + // function and forbid any selection changes during set cursor call. + wxGtkTreeSelectionLock + lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview))); + + // Do move the cursor now. + GtkTreeIter iter; + iter.user_data = item.GetID(); + wxGtkTreePath path(m_internal->get_path( &iter )); + + gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview), path, gcolumn, TRUE); +} + wxDataViewItem wxDataViewCtrl::GetSelection() const { GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); diff --git a/src/osx/carbon/dataview.cpp b/src/osx/carbon/dataview.cpp index ee91559350..ff748471c2 100644 --- a/src/osx/carbon/dataview.cpp +++ b/src/osx/carbon/dataview.cpp @@ -1236,6 +1236,11 @@ void wxMacDataViewDataBrowserListViewControl::OnSize() SetHasScrollBars(true,true); } +void wxMacDataViewDataBrowserListViewControl::StartEditor( const wxDataViewItem & item, unsigned int column ) +{ + // implement me +} + // // callback functions (inherited from wxMacDataBrowserTableViewControl) // diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 2aeac7950d..ac10280f6c 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2314,6 +2314,11 @@ void wxCocoaDataViewControl::Resort() [m_OutlineView reloadData]; } +void wxCocoaDataViewControl::StartEditor( const wxDataViewItem & item, unsigned int column ) +{ + [m_OutlineView editColumn:column row:[m_OutlineView rowForItem:[m_DataSource getDataViewItemFromBuffer:item]] withEvent:nil select:YES]; +} + // // other methods (inherited from wxDataViewWidgetImpl) // diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index 08c094bd86..c239ca35ff 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -633,6 +633,11 @@ void wxDataViewCtrl::AddChildren(wxDataViewItem const& parentItem) (void) GetModel()->ItemsAdded(parentItem,items); } +void wxDataViewCtrl::StartEditor( const wxDataViewItem & item, unsigned int column ) +{ + GetDataViewPeer()->StartEditor(item, column); +} + void wxDataViewCtrl::FinishCustomItemEditing() { if (GetCustomRendererItem().IsOk()) -- 2.45.2