From ee1377e1fa364f364b9a896c786c95ef177164cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Tue, 17 Jan 2012 14:05:07 +0000 Subject: [PATCH] Add wxDataViewCtrl::GetCurrentColumn(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70375 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dataview.h | 3 +++ include/wx/generic/dataview.h | 2 ++ include/wx/gtk/dataview.h | 2 ++ include/wx/osx/carbon/dataview.h | 1 + include/wx/osx/cocoa/dataview.h | 1 + include/wx/osx/core/dataview.h | 2 ++ include/wx/osx/dataview.h | 2 ++ interface/wx/dataview.h | 17 ++++++++++++++++- samples/dataview/dataview.cpp | 11 +++++++++++ src/generic/datavgen.cpp | 5 +++++ src/gtk/dataview.cpp | 13 +++++++++++++ src/osx/carbon/dataview.cpp | 6 ++++++ src/osx/cocoa/dataview.mm | 8 ++++++++ src/osx/dataview_osx.cpp | 5 +++++ 14 files changed, 77 insertions(+), 1 deletion(-) diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 85d628841e..0575611829 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -668,6 +668,9 @@ public: wxDataViewItem GetCurrentItem() const; void SetCurrentItem(const wxDataViewItem& item); + // Currently focused column of the current item or NULL if no column has focus + virtual wxDataViewColumn *GetCurrentColumn() const = 0; + // Selection: both GetSelection() and GetSelections() can be used for the // controls both with and without wxDV_MULTIPLE style. For single selection // controls GetSelections() is not very useful however. And for multi diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index ed3d11eb69..b6f643055f 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -222,6 +222,8 @@ public: // utility functions not part of the API // return the column displayed at the given position in the control wxDataViewColumn *GetColumnAt(unsigned int pos) const; + virtual wxDataViewColumn *GetCurrentColumn() const; + virtual void OnInternalIdle(); private: diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index 134e422b97..a10d89495a 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -169,6 +169,8 @@ public: virtual bool EnableDragSource( const wxDataFormat &format ); virtual bool EnableDropTarget( const wxDataFormat &format ); + virtual wxDataViewColumn *GetCurrentColumn() const; + static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); diff --git a/include/wx/osx/carbon/dataview.h b/include/wx/osx/carbon/dataview.h index ca6a5e5ea4..e4dfeb2940 100644 --- a/include/wx/osx/carbon/dataview.h +++ b/include/wx/osx/carbon/dataview.h @@ -406,6 +406,7 @@ public: // virtual wxDataViewItem GetCurrentItem() const; virtual void SetCurrentItem(const wxDataViewItem& item); + virtual wxDataViewColumn *GetCurrentColumn() const; virtual int GetSelectedItemsCount() const; virtual int GetSelections(wxDataViewItemArray& sel) const; virtual bool IsSelected (wxDataViewItem const& item) const; diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index e4c5ef65d4..0859b2dbae 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -474,6 +474,7 @@ public: // virtual wxDataViewItem GetCurrentItem() const; virtual void SetCurrentItem(const wxDataViewItem& item); + virtual wxDataViewColumn *GetCurrentColumn() const; virtual int GetSelectedItemsCount() const; virtual int GetSelections(wxDataViewItemArray& sel) const; virtual bool IsSelected(const wxDataViewItem& item) const; diff --git a/include/wx/osx/core/dataview.h b/include/wx/osx/core/dataview.h index 20b0fe9bdd..f02d328eea 100644 --- a/include/wx/osx/core/dataview.h +++ b/include/wx/osx/core/dataview.h @@ -89,6 +89,8 @@ public: virtual wxDataViewItem GetCurrentItem() const = 0; virtual void SetCurrentItem(const wxDataViewItem& item) = 0; + virtual wxDataViewColumn *GetCurrentColumn() const = 0; + virtual int GetSelectedItemsCount() const = 0; virtual int GetSelections(wxDataViewItemArray& sel) const = 0; // returns all selected items in the native control virtual bool IsSelected (wxDataViewItem const& item) const = 0; // checks if the passed item is selected in the native control diff --git a/include/wx/osx/dataview.h b/include/wx/osx/dataview.h index 5c9a9b7507..752939765c 100644 --- a/include/wx/osx/dataview.h +++ b/include/wx/osx/dataview.h @@ -256,6 +256,8 @@ public: m_Deleting = deleting; } + virtual wxDataViewColumn *GetCurrentColumn() const; + virtual wxVisualAttributes GetDefaultAttributes() const { return GetClassDefaultAttributes(GetWindowVariant()); diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index 026fecb853..f7bf4a2afc 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -1060,12 +1060,27 @@ public: item may be selected or not but under OS X the current item is always selected. - @see SetCurrentItem() + @see SetCurrentItem(), GetCurrentColumn() @since 2.9.2 */ wxDataViewItem GetCurrentItem() const; + /** + Returns the column that currently has focus. + + If the focus is set to individual cell within the currently focused + item (as opposed to being on the item as a whole), then this is the + column that the focus is on. + + Returns NULL if no column currently has focus. + + @see GetCurrentItem() + + @since 2.9.4 + */ + wxDataViewColumn *GetCurrentColumn() const; + /** Returns indentation. */ diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index 7f872bb6d9..df816643c9 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -943,6 +943,17 @@ void MyFrame::OnShowCurrent(wxCommandEvent& WXUNUSED(event)) { wxLogMessage("There is no current item."); } + + wxDataViewColumn *col = m_ctrl[0]->GetCurrentColumn(); + if ( col ) + { + wxLogMessage("Current column: %d", + m_ctrl[0]->GetColumnPosition(col)); + } + else + { + wxLogMessage("There is no current column."); + } } void MyFrame::OnSetNinthCurrent(wxCommandEvent& WXUNUSED(event)) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 852a50815e..6373be271e 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -4858,6 +4858,11 @@ void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item) } } +wxDataViewColumn *wxDataViewCtrl::GetCurrentColumn() const +{ + return m_clientArea->GetCurrentColumn(); +} + int wxDataViewCtrl::GetSelectedItemsCount() const { return m_clientArea->GetSelections().size(); diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index cda0c529a5..dd11509d67 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -4840,6 +4840,19 @@ void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item) gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview), path, NULL, FALSE); } +wxDataViewColumn *wxDataViewCtrl::GetCurrentColumn() const +{ + // The tree doesn't have any current item if it hadn't been created yet but + // it's arguably not an error to call this function in this case so just + // return NULL without asserting. + if ( !m_treeview ) + return NULL; + + GtkTreeViewColumn *col; + gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview), NULL, &col); + return FromGTKColumn(col); +} + void wxDataViewCtrl::StartEditor(const wxDataViewItem& item, unsigned int column) { wxCHECK_RET( m_treeview, diff --git a/src/osx/carbon/dataview.cpp b/src/osx/carbon/dataview.cpp index 13765f900d..b629161a5b 100644 --- a/src/osx/carbon/dataview.cpp +++ b/src/osx/carbon/dataview.cpp @@ -1102,6 +1102,12 @@ wxDataViewItem wxMacDataViewDataBrowserListViewControl::GetCurrentItem() const return wxDataViewItem(); } +wxDataViewColumn *wxMacDataViewDataBrowserListViewControl::GetCurrentColumn() const +{ + wxFAIL_MSG( "unimplemented for Carbon" ); + return NULL; +} + void wxMacDataViewDataBrowserListViewControl::SetCurrentItem(const wxDataViewItem& WXUNUSED(item)) { wxFAIL_MSG( "unimplemented for Carbon" ); diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 873f621ffa..ad8dfe54ec 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2287,6 +2287,14 @@ wxDataViewItem wxCocoaDataViewControl::GetCurrentItem() const return wxDataViewItem([[m_OutlineView itemAtRow:[m_OutlineView selectedRow]] pointer]); } +wxDataViewColumn *wxCocoaDataViewControl::GetCurrentColumn() const +{ + int col = [m_OutlineView selectedColumn]; + if ( col == -1 ) + return NULL; + return GetColumn(col); +} + void wxCocoaDataViewControl::SetCurrentItem(const wxDataViewItem& item) { // We can't have unselected current item in a NSTableView, as the diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index 2886e17934..ecbf403f6b 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -530,6 +530,11 @@ void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item) GetDataViewPeer()->SetCurrentItem(item); } +wxDataViewColumn *wxDataViewCtrl::GetCurrentColumn() const +{ + return GetDataViewPeer()->GetCurrentColumn(); +} + wxRect wxDataViewCtrl::GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const { if (item.IsOk() && (columnPtr != NULL)) -- 2.45.2