From e7c8349d9bb583103d3f3d3d17257ab9e6ff5a55 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 5 Mar 2016 18:17:19 +0100 Subject: [PATCH 01/19] Avoid MSVC 14 warning about variable hiding in dataview sample The warning is harmless but it was indeed confusing to call "parent" both a local variable and a function parameter, so don't do it. --- samples/dataview/dataview.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index 70a543f6a9..a51a3146e6 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -739,14 +739,14 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l ilist->Add( wxIcon(wx_small_xpm) ); tc->AssignImageList( ilist ); - wxDataViewItem parent = + const wxDataViewItem root = tc->AppendContainer( wxDataViewItem(0), "The Root", 0 ); - tc->AppendItem( parent, "Child 1", 0 ); - tc->AppendItem( parent, "Child 2", 0 ); - tc->AppendItem( parent, "Child 3, very long, long, long, long", 0 ); + tc->AppendItem( root, "Child 1", 0 ); + tc->AppendItem( root, "Child 2", 0 ); + tc->AppendItem( root, "Child 3, very long, long, long, long", 0 ); wxDataViewItem cont = - tc->AppendContainer( parent, "Container child", 0 ); + tc->AppendContainer( root, "Container child", 0 ); tc->AppendItem( cont, "Child 4", 0 ); tc->AppendItem( cont, "Child 5", 0 ); From a3fa628669599c8c11ab4ee7b5d201f4bfbb6536 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 5 Mar 2016 18:31:12 +0100 Subject: [PATCH 02/19] No changes, just add wxOVERRIDE to wx/generic/dataview.h Mark the overridden virtual functions as being overridden. Also reformat some methods to put them on several lines to prevent the lines from becoming way too long. --- include/wx/generic/dataview.h | 156 +++++++++++++++++++++------------- 1 file changed, 99 insertions(+), 57 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index c4ec501229..bb064e3d0b 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -52,30 +52,72 @@ public: } // implement wxHeaderColumnBase methods - virtual void SetTitle(const wxString& title) { m_title = title; UpdateDisplay(); } - virtual wxString GetTitle() const { return m_title; } + virtual void SetTitle(const wxString& title) wxOVERRIDE + { + m_title = title; + UpdateDisplay(); + } + virtual wxString GetTitle() const wxOVERRIDE + { + return m_title; + } - virtual void SetWidth(int width) { m_width = width; UpdateDisplay(); } - virtual int GetWidth() const; + virtual void SetWidth(int width) wxOVERRIDE + { + m_width = width; + UpdateDisplay(); + } + virtual int GetWidth() const wxOVERRIDE; - virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; UpdateDisplay(); } - virtual int GetMinWidth() const { return m_minWidth; } + virtual void SetMinWidth(int minWidth) wxOVERRIDE + { + m_minWidth = minWidth; + UpdateDisplay(); + } + virtual int GetMinWidth() const wxOVERRIDE + { + return m_minWidth; + } - virtual void SetAlignment(wxAlignment align) { m_align = align; UpdateDisplay(); } - virtual wxAlignment GetAlignment() const { return m_align; } + virtual void SetAlignment(wxAlignment align) wxOVERRIDE + { + m_align = align; + UpdateDisplay(); + } + virtual wxAlignment GetAlignment() const wxOVERRIDE + { + return m_align; + } - virtual void SetFlags(int flags) { m_flags = flags; UpdateDisplay(); } - virtual int GetFlags() const { return m_flags; } + virtual void SetFlags(int flags) wxOVERRIDE + { + m_flags = flags; + UpdateDisplay(); + } + virtual int GetFlags() const wxOVERRIDE + { + return m_flags; + } - virtual bool IsSortKey() const { return m_sort; } + virtual bool IsSortKey() const wxOVERRIDE + { + return m_sort; + } - virtual void UnsetAsSortKey(); + virtual void UnsetAsSortKey() wxOVERRIDE; - virtual void SetSortOrder(bool ascending); + virtual void SetSortOrder(bool ascending) wxOVERRIDE; - virtual bool IsSortOrderAscending() const { return m_sortAscending; } + virtual bool IsSortOrderAscending() const wxOVERRIDE + { + return m_sortAscending; + } - virtual void SetBitmap( const wxBitmap& bitmap ) { wxDataViewColumnBase::SetBitmap(bitmap); UpdateDisplay(); } + virtual void SetBitmap( const wxBitmap& bitmap ) wxOVERRIDE + { + wxDataViewColumnBase::SetBitmap(bitmap); + UpdateDisplay(); + } private: @@ -139,63 +181,63 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxDataViewCtrlNameStr); - virtual bool AssociateModel( wxDataViewModel *model ); + virtual bool AssociateModel( wxDataViewModel *model ) wxOVERRIDE; - virtual bool AppendColumn( wxDataViewColumn *col ); - virtual bool PrependColumn( wxDataViewColumn *col ); - virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col ); + virtual bool AppendColumn( wxDataViewColumn *col ) wxOVERRIDE; + virtual bool PrependColumn( wxDataViewColumn *col ) wxOVERRIDE; + virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col ) wxOVERRIDE; - virtual void DoSetExpanderColumn(); - virtual void DoSetIndent(); + virtual void DoSetExpanderColumn() wxOVERRIDE; + virtual void DoSetIndent() wxOVERRIDE; - virtual unsigned int GetColumnCount() const; - virtual wxDataViewColumn* GetColumn( unsigned int pos ) const; - virtual bool DeleteColumn( wxDataViewColumn *column ); - virtual bool ClearColumns(); - virtual int GetColumnPosition( const wxDataViewColumn *column ) const; + virtual unsigned int GetColumnCount() const wxOVERRIDE; + virtual wxDataViewColumn* GetColumn( unsigned int pos ) const wxOVERRIDE; + virtual bool DeleteColumn( wxDataViewColumn *column ) wxOVERRIDE; + virtual bool ClearColumns() wxOVERRIDE; + virtual int GetColumnPosition( const wxDataViewColumn *column ) const wxOVERRIDE; - virtual wxDataViewColumn *GetSortingColumn() const; - virtual wxVector GetSortingColumns() const; + virtual wxDataViewColumn *GetSortingColumn() const wxOVERRIDE; + virtual wxVector GetSortingColumns() const wxOVERRIDE; - virtual int GetSelectedItemsCount() const; - virtual int GetSelections( wxDataViewItemArray & sel ) const; - virtual void SetSelections( const wxDataViewItemArray & sel ); - virtual void Select( const wxDataViewItem & item ); - virtual void Unselect( const wxDataViewItem & item ); - virtual bool IsSelected( const wxDataViewItem & item ) const; + virtual int GetSelectedItemsCount() const wxOVERRIDE; + virtual int GetSelections( wxDataViewItemArray & sel ) const wxOVERRIDE; + virtual void SetSelections( const wxDataViewItemArray & sel ) wxOVERRIDE; + virtual void Select( const wxDataViewItem & item ) wxOVERRIDE; + virtual void Unselect( const wxDataViewItem & item ) wxOVERRIDE; + virtual bool IsSelected( const wxDataViewItem & item ) const wxOVERRIDE; - virtual void SelectAll(); - virtual void UnselectAll(); + virtual void SelectAll() wxOVERRIDE; + virtual void UnselectAll() wxOVERRIDE; virtual void EnsureVisible( const wxDataViewItem & item, - const wxDataViewColumn *column = NULL ); + const wxDataViewColumn *column = NULL ) wxOVERRIDE; virtual void HitTest( const wxPoint & point, wxDataViewItem & item, - wxDataViewColumn* &column ) const; + wxDataViewColumn* &column ) const wxOVERRIDE; virtual wxRect GetItemRect( const wxDataViewItem & item, - const wxDataViewColumn *column = NULL ) const; + const wxDataViewColumn *column = NULL ) const wxOVERRIDE; - virtual bool SetRowHeight( int rowHeight ); + virtual bool SetRowHeight( int rowHeight ) wxOVERRIDE; - virtual void Expand( const wxDataViewItem & item ); - virtual void Collapse( const wxDataViewItem & item ); - virtual bool IsExpanded( const wxDataViewItem & item ) const; + virtual void Expand( const wxDataViewItem & item ) wxOVERRIDE; + virtual void Collapse( const wxDataViewItem & item ) wxOVERRIDE; + virtual bool IsExpanded( const wxDataViewItem & item ) const wxOVERRIDE; - virtual void SetFocus(); + virtual void SetFocus() wxOVERRIDE; - virtual bool SetFont(const wxFont & font); + virtual bool SetFont(const wxFont & font) wxOVERRIDE; - virtual bool AllowMultiColumnSort(bool allow); + virtual bool AllowMultiColumnSort(bool allow) wxOVERRIDE; virtual bool IsMultiColumnSortAllowed() { return m_allowMultiColumnSort; } - virtual void ToggleSortByColumn(int column); + virtual void ToggleSortByColumn(int column) wxOVERRIDE; #if wxUSE_DRAG_AND_DROP - virtual bool EnableDragSource( const wxDataFormat &format ); - virtual bool EnableDropTarget( const wxDataFormat &format ); + virtual bool EnableDragSource( const wxDataFormat &format ) wxOVERRIDE; + virtual bool EnableDropTarget( const wxDataFormat &format ) wxOVERRIDE; #endif // wxUSE_DRAG_AND_DROP - virtual wxBorder GetDefaultBorder() const; + virtual wxBorder GetDefaultBorder() const wxOVERRIDE; - virtual void EditItem(const wxDataViewItem& item, const wxDataViewColumn *column); + virtual void EditItem(const wxDataViewItem& item, const wxDataViewColumn *column) wxOVERRIDE; // These methods are specific to generic wxDataViewCtrl implementation and // should not be used in portable code. @@ -247,13 +289,13 @@ 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 wxDataViewColumn *GetCurrentColumn() const wxOVERRIDE; - virtual void OnInternalIdle(); + virtual void OnInternalIdle() wxOVERRIDE; private: - virtual wxDataViewItem DoGetCurrentItem() const; - virtual void DoSetCurrentItem(const wxDataViewItem& item); + virtual wxDataViewItem DoGetCurrentItem() const wxOVERRIDE; + virtual void DoSetCurrentItem(const wxDataViewItem& item) wxOVERRIDE; void InvalidateColBestWidths(); void InvalidateColBestWidth(int idx); @@ -289,12 +331,12 @@ private: private: void OnSize( wxSizeEvent &event ); - virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size); + virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size) wxOVERRIDE; // we need to return a special WM_GETDLGCODE value to process just the // arrows but let the other navigation characters through #ifdef __WXMSW__ - virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); + virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE; #endif // __WXMSW__ WX_FORWARD_TO_SCROLL_HELPER() From b70109ee7a2fd3569df8ab4eb81af9e1acd0ac71 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 5 Mar 2016 18:39:22 +0100 Subject: [PATCH 03/19] Don't make some generic wxDataViewCtrl unnecessarily virtual These methods are not supposed to be overridden and don't override any base class methods neither. --- include/wx/generic/dataview.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index bb064e3d0b..68e8ef2c86 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -249,8 +249,8 @@ protected: // Notice that row here may be invalid (i.e. >= GetRowCount()), this is not // an error and this function simply returns an invalid item in this case. - virtual wxDataViewItem GetItemByRow( unsigned int row ) const; - virtual int GetRowByItem( const wxDataViewItem & item ) const; + wxDataViewItem GetItemByRow( unsigned int row ) const; + int GetRowByItem( const wxDataViewItem & item ) const; // Mark the column as being used or not for sorting. void UseColumnForSorting(int idx); From 062444ee5072acf91f1410e4f6fc24051e31e484 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 5 Mar 2016 18:40:06 +0100 Subject: [PATCH 04/19] Make generic wxDataViewCtrl EnsureVisible() overload non-virtual There doesn't seem to be any reason for this method to be virtual other than preventing "virtual function hiding" warnings from gcc, so just rename it to have a different name than the virtual EnsureVisible() inherited from the base class instead. --- include/wx/generic/dataview.h | 2 +- src/generic/datavgen.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 68e8ef2c86..4f7ca80c76 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -245,7 +245,7 @@ public: void SetAlternateRowColour(const wxColour& colour); protected: - virtual void EnsureVisible( int row, int column ); + void EnsureVisibleRowCol( int row, int column ); // Notice that row here may be invalid (i.e. >= GetRowCount()), this is not // an error and this function simply returns an invalid item in this case. diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index d116af19fb..706efcb90f 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -3884,7 +3884,7 @@ void wxDataViewMainWindow::OnVerticalNavigation(const wxKeyEvent& event, int del RefreshRow( m_currentRow ); } - GetOwner()->EnsureVisible( m_currentRow, -1 ); + GetOwner()->EnsureVisibleRowCol( m_currentRow, -1 ); } void wxDataViewMainWindow::OnLeftKey(wxKeyEvent& event) @@ -3932,7 +3932,7 @@ void wxDataViewMainWindow::OnLeftKey(wxKeyEvent& event) SelectRow( row, false); SelectRow( parent, true ); ChangeCurrentRow( parent ); - GetOwner()->EnsureVisible( parent, -1 ); + GetOwner()->EnsureVisibleRowCol( parent, -1 ); SendSelectionChangedEvent( parent_node->GetItem() ); } } @@ -3965,7 +3965,7 @@ void wxDataViewMainWindow::OnRightKey(wxKeyEvent& event) SelectRow( row, false ); SelectRow( row + 1, true ); ChangeCurrentRow( row + 1 ); - GetOwner()->EnsureVisible( row + 1, -1 ); + GetOwner()->EnsureVisibleRowCol( row + 1, -1 ); SendSelectionChangedEvent( GetItemByRow(row+1) ); } } @@ -4046,7 +4046,7 @@ bool wxDataViewMainWindow::TryAdvanceCurrentColumn(wxDataViewTreeNode *node, wxK } } - GetOwner()->EnsureVisible(m_currentRow, idx); + GetOwner()->EnsureVisibleRowCol(m_currentRow, idx); if ( idx < 1 ) { @@ -5266,7 +5266,7 @@ void wxDataViewCtrl::UnselectAll() m_clientArea->UnselectAllRows(); } -void wxDataViewCtrl::EnsureVisible( int row, int column ) +void wxDataViewCtrl::EnsureVisibleRowCol( int row, int column ) { if( row < 0 ) row = 0; @@ -5293,9 +5293,9 @@ void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, const wxDataVie if( row >= 0 ) { if( column == NULL ) - EnsureVisible(row, -1); + EnsureVisibleRowCol(row, -1); else - EnsureVisible( row, GetColumnIndex(column) ); + EnsureVisibleRowCol( row, GetColumnIndex(column) ); } } From 34b0e534f82e5347383c4760d33506a0260ceed4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 5 Mar 2016 18:42:02 +0100 Subject: [PATCH 05/19] Make wxDataViewCtrl::IsMultiColumnSortAllowed() exist in all ports Contrary to the documentation, this method only existed in the generic control, add it to the base class now so that the code using it could compile when using the native ports too. --- include/wx/dataview.h | 3 +++ include/wx/generic/dataview.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 8364cdbd78..b709434aba 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -662,6 +662,9 @@ public: return !allow; } + // Return true if multi column sort is currently allowed. + virtual bool IsMultiColumnSortAllowed() const { return false; } + // This should also be overridden to actually use the specified column for // sorting if using multiple columns is supported. virtual void ToggleSortByColumn(int WXUNUSED(column)) { } diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 4f7ca80c76..6f89ee6165 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -227,7 +227,7 @@ public: virtual bool SetFont(const wxFont & font) wxOVERRIDE; virtual bool AllowMultiColumnSort(bool allow) wxOVERRIDE; - virtual bool IsMultiColumnSortAllowed() { return m_allowMultiColumnSort; } + virtual bool IsMultiColumnSortAllowed() const wxOVERRIDE { return m_allowMultiColumnSort; } virtual void ToggleSortByColumn(int column) wxOVERRIDE; #if wxUSE_DRAG_AND_DROP From d613fb75f6250351555c1e62dee96540bf1c73c3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 5 Mar 2016 18:43:55 +0100 Subject: [PATCH 06/19] Don't update if column width didn't change in generic wxDataViewCtrl Avoid calling UpdateDisplay() unnecessarily if the column width didn't really change. This doesn't result in anything really bad happening right now, but it could easily result in an infinite stream of updates if the code were only slightly different and it just seems useless to do it. --- include/wx/generic/dataview.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 6f89ee6165..27bdf1dc90 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -64,8 +64,11 @@ public: virtual void SetWidth(int width) wxOVERRIDE { - m_width = width; - UpdateDisplay(); + if ( width != m_width ) + { + m_width = width; + UpdateDisplay(); + } } virtual int GetWidth() const wxOVERRIDE; From a9be974d5bbb4f98cd3ce7a8e9797e5adb370469 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 5 Mar 2016 19:51:06 +0100 Subject: [PATCH 07/19] Avoid unnecessarily refreshing last column in generic wxDataViewCtrl UpdateColumnSizes() was called whenever the control was modified in any way since 4156e1a5c94283cb037132518dfb80dbc1403e12 and it refreshed the entire last column even if absolutely nothing changed. Don't do this unless the last column width has really changed. --- include/wx/generic/dataview.h | 21 ++++++++++++++++----- src/generic/datavgen.cpp | 6 +++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 27bdf1dc90..fee9e14020 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -64,11 +64,10 @@ public: virtual void SetWidth(int width) wxOVERRIDE { - if ( width != m_width ) - { - m_width = width; - UpdateDisplay(); - } + // As a small optimization, use this method to avoid calling + // UpdateDisplay() if the width didn't really change, even if we don't + // care about its return value. + (void)WXUpdateWidth(width); } virtual int GetWidth() const wxOVERRIDE; @@ -122,6 +121,18 @@ public: UpdateDisplay(); } + // This method is specific to the generic implementation and is used only + // by wxWidgets itself. + bool WXUpdateWidth(int width) + { + if ( width == m_width ) + return false; + + m_width = width; + UpdateDisplay(); + + return true; + } private: // common part of all ctors diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 706efcb90f..3192e483e4 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -4577,7 +4577,11 @@ void wxDataViewMainWindow::UpdateColumnSizes() if ( lastColX < fullWinWidth ) { int desiredWidth = wxMax(fullWinWidth - lastColX, lastCol->GetMinWidth()); - lastCol->SetWidth(desiredWidth); + if ( !lastCol->WXUpdateWidth(desiredWidth) ) + { + // The column width didn't change, no need to do anything else. + return; + } // All columns fit on screen, so we don't need horizontal scrolling. // To prevent flickering scrollbar when resizing the window to be From db6e1c5b3838cb1614d6f3d30c40145ef4211b96 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 17 Mar 2016 22:34:14 +0100 Subject: [PATCH 08/19] Make wxCOL_WIDTH_AUTOSIZE work dynamically in generic wxDataViewCtrl Caching the best column widths broke autosizing behaviour if the column title was updated after setting the width to wxCOL_WIDTH_AUTOSIZE. Fix this by invaliding the column cached width if its text changes. --- include/wx/generic/dataview.h | 17 ++++++++++++----- src/generic/datavgen.cpp | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index fee9e14020..591ba2fadf 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -55,7 +55,7 @@ public: virtual void SetTitle(const wxString& title) wxOVERRIDE { m_title = title; - UpdateDisplay(); + UpdateWidth(); } virtual wxString GetTitle() const wxOVERRIDE { @@ -65,7 +65,7 @@ public: virtual void SetWidth(int width) wxOVERRIDE { // As a small optimization, use this method to avoid calling - // UpdateDisplay() if the width didn't really change, even if we don't + // UpdateWidth() if the width didn't really change, even if we don't // care about its return value. (void)WXUpdateWidth(width); } @@ -74,7 +74,7 @@ public: virtual void SetMinWidth(int minWidth) wxOVERRIDE { m_minWidth = minWidth; - UpdateDisplay(); + UpdateWidth(); } virtual int GetMinWidth() const wxOVERRIDE { @@ -118,7 +118,7 @@ public: virtual void SetBitmap( const wxBitmap& bitmap ) wxOVERRIDE { wxDataViewColumnBase::SetBitmap(bitmap); - UpdateDisplay(); + UpdateWidth(); } // This method is specific to the generic implementation and is used only @@ -129,7 +129,7 @@ public: return false; m_width = width; - UpdateDisplay(); + UpdateWidth(); return true; } @@ -138,7 +138,11 @@ private: // common part of all ctors void Init(int width, wxAlignment align, int flags); + // These methods forward to wxDataViewCtrl::OnColumnChange() and + // OnColumnWidthChange() respectively, i.e. the latter is stronger than the + // former. void UpdateDisplay(); + void UpdateWidth(); wxString m_title; int m_width, @@ -289,6 +293,9 @@ public: // utility functions not part of the API // update the display after a change to an individual column void OnColumnChange(unsigned int idx); + // update after the column width changes, also calls OnColumnChange() + void OnColumnWidthChange(unsigned int idx); + // update after a change to the number of columns void OnColumnsCountChanged(); diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 3192e483e4..a9273594e6 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -186,6 +186,15 @@ void wxDataViewColumn::UpdateDisplay() } } +void wxDataViewColumn::UpdateWidth() +{ + if (m_owner) + { + int idx = m_owner->GetColumnIndex( this ); + m_owner->OnColumnWidthChange( idx ); + } +} + void wxDataViewColumn::UnsetAsSortKey() { m_sort = false; @@ -4846,6 +4855,13 @@ bool wxDataViewCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col ) return true; } +void wxDataViewCtrl::OnColumnWidthChange(unsigned int idx) +{ + InvalidateColBestWidth(idx); + + OnColumnChange(idx); +} + void wxDataViewCtrl::OnColumnChange(unsigned int idx) { if ( m_headerArea ) From e2e7d3d3911795153337417a0c5a54ea12be99eb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 18 Mar 2016 22:33:31 +0100 Subject: [PATCH 09/19] Fix wxELLIPSIZE_END with wxALIGN_RIGHT in wxMSW wxDataViewCtrl Using wxELLIPSIZE_END together with wxALIGN_RIGHT resulted in unnecessarily ellipsizing or truncating the column contents in generic wxDataViewCtrl under MSW due to the combination of b642747fd25b79c20bafc6cd978914ee6f745fd0 and the native API behaviour. Fix this by not using alignment in RenderText(): it is unnecessary anyhow and not doing it avoids the problem as a side effect. Closes #17363. --- src/common/datavcmn.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 6775d5fc53..7fa71bab38 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -1002,12 +1002,17 @@ wxDataViewCustomRendererBase::RenderText(const wxString& text, if ( !GetOwner()->GetOwner()->IsEnabled() ) flags |= wxCONTROL_DISABLED; + // Notice that we intentionally don't use any alignment here: it is not + // necessary because the cell rectangle had been already adjusted to + // account for the alignment in WXCallRender() and using the alignment here + // results in problems with ellipsization when using native MSW renderer, + // see http://trac.wxwidgets.org/ticket/17363, so just don't do it. wxRendererNative::Get().DrawItemText( GetOwner()->GetOwner(), *dc, text, rectText, - GetEffectiveAlignment(), + wxALIGN_NOT, flags, GetEllipsizeMode()); } From 98294467553fe4dd766419c4e5aa6bc9502d65c7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 18 Mar 2016 23:33:27 +0100 Subject: [PATCH 10/19] Refactor wxDataViewEvent constructors Take care of all the common stuff such as setting the event object and the model, which is used for all events, in the ctor. Also set both the column pointer and the column index at once instead of having two separate setters for them which could result in inconsistent event objects (and did, as sometimes only one or only the other field was set). This makes the code shorter (we save 160 lines) and more clear and ensures that everything is always initialized. Closes #12649. --- include/wx/dataview.h | 70 +++++++++++++------- src/common/datavcmn.cpp | 52 +++++++++------ src/generic/datavgen.cpp | 113 +++++++------------------------- src/gtk/dataview.cpp | 97 ++++++++------------------- src/osx/cocoa/dataview.mm | 133 ++++++++++---------------------------- src/osx/dataview_osx.cpp | 26 ++------ 6 files changed, 166 insertions(+), 325 deletions(-) diff --git a/include/wx/dataview.h b/include/wx/dataview.h index b709434aba..5cebecc126 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -769,25 +769,32 @@ protected: class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent { public: - wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) - : wxNotifyEvent(commandType, winid), - m_item(0), - m_col(-1), - m_model(NULL), - m_value(wxNullVariant), - m_column(NULL), - m_pos(-1,-1), - m_cacheFrom(0), - m_cacheTo(0), - m_editCancelled(false) -#if wxUSE_DRAG_AND_DROP - , m_dataObject(NULL), - m_dataBuffer(NULL), - m_dataSize(0), - m_dragFlags(0), - m_dropEffect(wxDragNone) -#endif - { } + // Default ctor, normally shouldn't be used and mostly exists only for + // backwards compatibility. + wxDataViewEvent() + : wxNotifyEvent() + { + Init(NULL, NULL, wxDataViewItem()); + } + + // Constructor for the events affecting columns (and possibly also items). + wxDataViewEvent(wxEventType evtType, + wxDataViewCtrlBase* dvc, + wxDataViewColumn* column, + const wxDataViewItem& item = wxDataViewItem()) + : wxNotifyEvent(evtType, dvc->GetId()) + { + Init(dvc, column, item); + } + + // Constructor for the events affecting only the items. + wxDataViewEvent(wxEventType evtType, + wxDataViewCtrlBase* dvc, + const wxDataViewItem& item) + : wxNotifyEvent(evtType, dvc->GetId()) + { + Init(dvc, NULL, item); + } wxDataViewEvent(const wxDataViewEvent& event) : wxNotifyEvent(event), @@ -811,13 +818,8 @@ public: { } wxDataViewItem GetItem() const { return m_item; } - void SetItem( const wxDataViewItem &item ) { m_item = item; } - int GetColumn() const { return m_col; } - void SetColumn( int col ) { m_col = col; } - wxDataViewModel* GetModel() const { return m_model; } - void SetModel( wxDataViewModel *model ) { m_model = model; } const wxVariant &GetValue() const { return m_value; } void SetValue( const wxVariant &value ) { m_value = value; } @@ -827,7 +829,6 @@ public: void SetEditCanceled(bool editCancelled) { m_editCancelled = editCancelled; } // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only - void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; } wxDataViewColumn *GetDataViewColumn() const { return m_column; } // for wxEVT_DATAVIEW_CONTEXT_MENU only @@ -860,6 +861,20 @@ public: virtual wxEvent *Clone() const wxOVERRIDE { return new wxDataViewEvent(*this); } + // These methods shouldn't be used outside of wxWidgets and wxWidgets + // itself doesn't use them any longer neither as it constructs the events + // with the appropriate ctors directly. +#if WXWIN_COMPATIBILITY_3_0 + wxDEPRECATED_MSG("Pass the argument to the ctor instead") + void SetModel( wxDataViewModel *model ) { m_model = model; } + wxDEPRECATED_MSG("Pass the argument to the ctor instead") + void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; } + wxDEPRECATED_MSG("Pass the argument to the ctor instead") + void SetColumn( int col ) { m_col = col; } + wxDEPRECATED_MSG("Pass the argument to the ctor instead") + void SetItem( const wxDataViewItem &item ) { m_item = item; } +#endif // WXWIN_COMPATIBILITY_3_0 + protected: wxDataViewItem m_item; int m_col; @@ -883,6 +898,11 @@ protected: #endif // wxUSE_DRAG_AND_DROP private: + // Common part of non-copy ctors. + void Init(wxDataViewCtrlBase* dvc, + wxDataViewColumn* column, + const wxDataViewItem& item); + wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent); }; diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 7fa71bab38..1d9ee90af5 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -669,16 +669,13 @@ wxDataViewCtrl* wxDataViewRendererBase::GetView() const bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect ) { - wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner(); + wxDataViewColumn* const column = GetOwner(); + wxDataViewCtrl* const dv_ctrl = column->GetOwner(); // Before doing anything we send an event asking if editing of this item is really wanted. - wxDataViewEvent start_event( wxEVT_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() ) + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_START_EDITING, dv_ctrl, column, item); + dv_ctrl->GetEventHandler()->ProcessEvent( event ); + if( !event.IsAllowed() ) return false; unsigned int col = GetOwner()->GetModelColumn(); @@ -712,11 +709,7 @@ void wxDataViewRendererBase::NotifyEditingStarted(const wxDataViewItem& item) wxDataViewColumn* const column = GetOwner(); wxDataViewCtrl* const dv_ctrl = column->GetOwner(); - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_EDITING_STARTED, dv_ctrl->GetId() ); - event.SetDataViewColumn( column ); - event.SetModel( dv_ctrl->GetModel() ); - event.SetItem( item ); - event.SetEventObject( dv_ctrl ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EDITING_STARTED, dv_ctrl, column, item); dv_ctrl->GetEventHandler()->ProcessEvent( event ); } @@ -756,7 +749,8 @@ bool wxDataViewRendererBase::FinishEditing() wxVariant value; const bool gotValue = GetValueFromEditorCtrl(m_editorCtrl, value); - wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner(); + wxDataViewColumn* const column = GetOwner(); + wxDataViewCtrl* const dv_ctrl = column->GetOwner(); DestroyEditControl(); @@ -769,14 +763,9 @@ bool wxDataViewRendererBase::FinishEditing() unsigned int col = GetOwner()->GetModelColumn(); // Now we should send Editing Done event - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_EDITING_DONE, dv_ctrl->GetId() ); - event.SetDataViewColumn( GetOwner() ); - event.SetModel( dv_ctrl->GetModel() ); - event.SetItem( m_item ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EDITING_DONE, dv_ctrl, column, m_item); event.SetValue( value ); - event.SetColumn( col ); event.SetEditCanceled( !isValid ); - event.SetEventObject( dv_ctrl ); dv_ctrl->GetEventHandler()->ProcessEvent( event ); bool accepted = false; @@ -1591,6 +1580,29 @@ wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent ); wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, wxDataViewEvent ); wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_DROP, wxDataViewEvent ); +// Common part of non-copy ctors. +void wxDataViewEvent::Init(wxDataViewCtrlBase* dvc, + wxDataViewColumn* column, + const wxDataViewItem& item) +{ + m_item = item; + m_col = column ? column->GetModelColumn() : -1; + m_model = dvc->GetModel(); + m_column = column; + m_pos = wxDefaultPosition; + m_cacheFrom = 0; + m_cacheTo = 0; + m_editCancelled = false; +#if wxUSE_DRAG_AND_DROP + m_dataObject = NULL; + m_dataBuffer = NULL; + m_dataSize = 0; + m_dragFlags = 0; + m_dropEffect = wxDragNone; +#endif // wxUSE_DRAG_AND_DROP + + SetEventObject(dvc); +} #if wxUSE_SPINCTRL diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index a9273594e6..e1a3861b89 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -293,12 +293,7 @@ private: bool SendEvent(wxEventType type, unsigned int n) { wxDataViewCtrl * const owner = GetOwner(); - wxDataViewEvent event(type, owner->GetId()); - - event.SetEventObject(owner); - event.SetColumn(n); - event.SetDataViewColumn(owner->GetColumn(n)); - event.SetModel(owner->GetModel()); + wxDataViewEvent event(type, owner, owner->GetColumn(n)); // for events created by wxDataViewHeaderWindow the // row / value fields are not valid @@ -1658,12 +1653,7 @@ wxDragResult wxDataViewMainWindow::OnDragOver( wxDataFormat format, wxCoord x, if ( row < GetRowCount() && xx <= GetEndOfLastCol() ) item = GetItemByRow( row ); - wxDataViewModel *model = GetModel(); - - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() ); - event.SetEventObject( m_owner ); - event.SetItem( item ); - event.SetModel( model ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner, item); event.SetDataFormat( format ); event.SetDropEffect( def ); if ( !m_owner->HandleWindowEvent( event ) || !event.IsAllowed() ) @@ -1702,12 +1692,7 @@ bool wxDataViewMainWindow::OnDrop( wxDataFormat format, wxCoord x, wxCoord y ) if ( row < GetRowCount() && xx <= GetEndOfLastCol()) item = GetItemByRow( row ); - wxDataViewModel *model = GetModel(); - - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() ); - event.SetEventObject( m_owner ); - event.SetItem( item ); - event.SetModel( model ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner, item); event.SetDataFormat( format ); if (!m_owner->HandleWindowEvent( event ) || !event.IsAllowed()) return false; @@ -1728,14 +1713,9 @@ wxDragResult wxDataViewMainWindow::OnData( wxDataFormat format, wxCoord x, wxCoo if ( row < GetRowCount() && xx <= GetEndOfLastCol() ) item = GetItemByRow( row ); - wxDataViewModel *model = GetModel(); - wxCustomDataObject *obj = (wxCustomDataObject *) GetDropTarget()->GetDataObject(); - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP, m_owner->GetId() ); - event.SetEventObject( m_owner ); - event.SetItem( item ); - event.SetModel( model ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP, m_owner, item); event.SetDataFormat( format ); event.SetDataSize( obj->GetSize() ); event.SetDataBuffer( obj->GetData() ); @@ -1851,11 +1831,9 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) unsigned int item_last = item_start + item_count; // Send the event to wxDataViewCtrl itself. - wxWindow * const parent = GetParent(); - wxDataViewEvent cache_event(wxEVT_DATAVIEW_CACHE_HINT, parent->GetId()); - cache_event.SetEventObject(parent); + wxDataViewEvent cache_event(wxEVT_DATAVIEW_CACHE_HINT, m_owner, NULL); cache_event.SetCache(item_start, item_last - 1); - parent->ProcessWindowEvent(cache_event); + m_owner->ProcessWindowEvent(cache_event); // compute which columns needs to be redrawn unsigned int cols = GetOwner()->GetColumnCount(); @@ -2537,12 +2515,8 @@ bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item) GetOwner()->InvalidateColBestWidths(); // Send event - wxWindow *parent = GetParent(); - wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId()); - le.SetEventObject(parent); - le.SetModel(GetModel()); - le.SetItem(item); - parent->ProcessWindowEvent(le); + wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner, item); + m_owner->ProcessWindowEvent(le); return true; } @@ -2568,14 +2542,9 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i GetOwner()->InvalidateColBestWidth(view_column); // Send event - wxWindow *parent = GetParent(); - wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId()); - le.SetEventObject(parent); - le.SetModel(GetModel()); - le.SetItem(item); - le.SetColumn(view_column); - le.SetDataViewColumn(GetOwner()->GetColumn(view_column)); - parent->ProcessWindowEvent(le); + wxDataViewColumn* const column = m_owner->GetColumn(view_column); + wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner, column, item); + m_owner->ProcessWindowEvent(le); return true; } @@ -2824,14 +2793,8 @@ bool wxDataViewMainWindow::IsRowSelected( unsigned int row ) void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem& item) { - wxWindow *parent = GetParent(); - wxDataViewEvent le(wxEVT_DATAVIEW_SELECTION_CHANGED, parent->GetId()); - - le.SetEventObject(parent); - le.SetModel(GetModel()); - le.SetItem( item ); - - parent->ProcessWindowEvent(le); + wxDataViewEvent le(wxEVT_DATAVIEW_SELECTION_CHANGED, m_owner, item); + m_owner->ProcessWindowEvent(le); } void wxDataViewMainWindow::RefreshRow( unsigned int row ) @@ -3122,14 +3085,8 @@ bool wxDataViewMainWindow::SendExpanderEvent(wxEventType type, const wxDataViewItem& item) { - wxWindow *parent = GetParent(); - wxDataViewEvent le(type, parent->GetId()); - - le.SetEventObject(parent); - le.SetModel(GetModel()); - le.SetItem( item ); - - return !parent->ProcessWindowEvent(le) || le.IsAllowed(); + wxDataViewEvent le(type, m_owner, item); + return !m_owner->ProcessWindowEvent(le) || le.IsAllowed(); } bool wxDataViewMainWindow::IsExpanded( unsigned int row ) const @@ -3709,13 +3666,8 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) const wxDataViewItem item = GetItemByRow(m_currentRow); - wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_ACTIVATED, - parent->GetId()); - le.SetItem(item); - le.SetEventObject(parent); - le.SetModel(GetModel()); - - if ( parent->ProcessWindowEvent(le) ) + wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_ACTIVATED, m_owner, item); + if ( m_owner->ProcessWindowEvent(le) ) break; // else: fall through to WXK_SPACE handling } @@ -4121,19 +4073,8 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) // the other ones. if (event.RightUp()) { - wxWindow *parent = GetParent(); - wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, parent->GetId()); - le.SetEventObject(parent); - le.SetModel(model); - - if ( item.IsOk() && col ) - { - le.SetItem( item ); - le.SetColumn( col->GetModelColumn() ); - le.SetDataViewColumn( col ); - } - - parent->ProcessWindowEvent(le); + wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, m_owner, col, item); + m_owner->ProcessWindowEvent(le); return; } @@ -4162,10 +4103,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) wxDataViewItem itemDragged = GetItemByRow( drag_item_row ); // Notify cell about drag - wxDataViewEvent evt( wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, m_owner->GetId() ); - evt.SetEventObject( m_owner ); - evt.SetItem( itemDragged ); - evt.SetModel( model ); + wxDataViewEvent evt(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, m_owner, itemDragged); if (!m_owner->HandleWindowEvent( evt )) return; @@ -4279,15 +4217,8 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) { if ( !hoverOverExpander && (current == m_lineLastClicked) ) { - wxWindow *parent = GetParent(); - wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_ACTIVATED, parent->GetId()); - le.SetItem( item ); - le.SetColumn( col->GetModelColumn() ); - le.SetDataViewColumn( col ); - le.SetEventObject(parent); - le.SetModel(GetModel()); - - if ( parent->ProcessWindowEvent(le) ) + wxDataViewEvent le(wxEVT_DATAVIEW_ITEM_ACTIVATED, m_owner, col, item); + if ( m_owner->ProcessWindowEvent(le) ) { // Item activation was handled from the user code. return; diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 7b73d1a9ba..4e04d7994e 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -979,9 +979,8 @@ wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable, if (gs_lastLeftClickHeader) { wxDataViewCtrl *dv = tree_model->internal->GetOwner(); - wxDataViewEvent event( wxEVT_DATAVIEW_COLUMN_SORTED, dv->GetId() ); - event.SetDataViewColumn( gs_lastLeftClickHeader ); - event.SetModel( dv->GetModel() ); + wxDataViewEvent + event(wxEVT_DATAVIEW_COLUMN_SORTED, dv, gs_lastLeftClickHeader); dv->HandleWindowEvent( event ); } @@ -1129,11 +1128,7 @@ static GtkCellEditable *gtk_wx_cell_renderer_text_start_editing( item(column->GetOwner()->GTKPathToItem(wxGtkTreePath(path))); wxDataViewCtrl *dv = column->GetOwner(); - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_START_EDITING, dv->GetId() ); - event.SetDataViewColumn( column ); - event.SetModel( dv->GetModel() ); - event.SetColumn( column->GetModelColumn() ); - event.SetItem( item ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_START_EDITING, dv, column, item); dv->HandleWindowEvent( event ); if (event.IsAllowed()) @@ -3002,9 +2997,7 @@ gtk_dataview_header_button_press_callback( GtkWidget *WXUNUSED(widget), gs_lastLeftClickHeader = column; wxDataViewCtrl *dv = column->GetOwner(); - wxDataViewEvent event( wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() ); - event.SetDataViewColumn( column ); - event.SetModel( dv->GetModel() ); + wxDataViewEvent event(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, dv, column); if (dv->HandleWindowEvent( event )) return FALSE; } @@ -3012,9 +3005,8 @@ gtk_dataview_header_button_press_callback( GtkWidget *WXUNUSED(widget), if (gdk_event->button == 3) { wxDataViewCtrl *dv = column->GetOwner(); - wxDataViewEvent event( wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv->GetId() ); - event.SetDataViewColumn( column ); - event.SetModel( dv->GetModel() ); + wxDataViewEvent + event(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv, column); if (dv->HandleWindowEvent( event )) return FALSE; } @@ -3605,14 +3597,12 @@ gboolean wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource *WXUNUSED(drag delete m_dragDataObject; m_dragDataObject = NULL; - wxDataViewItem item(GetOwner()->GTKPathToItem(path)); + wxDataViewCtrl* const dvc = GetOwner(); + wxDataViewItem item(dvc->GTKPathToItem(path)); if ( !item ) return FALSE; - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, m_owner->GetId() ); - event.SetEventObject( m_owner ); - event.SetItem( item ); - event.SetModel( m_wx_model ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, dvc, item); gint x, y; gtk_widget_get_pointer(m_owner->GtkGetTreeView(), &x, &y); event.SetPosition(x, y); @@ -3676,10 +3666,7 @@ wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest *WXUNUSED(drag_dest), { wxDataViewItem item(GetOwner()->GTKPathToItem(path)); - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP, m_owner->GetId() ); - event.SetEventObject( m_owner ); - event.SetItem( item ); - event.SetModel( m_wx_model ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP, m_owner, item); event.SetDataFormat(gtk_selection_data_get_target(selection_data)); event.SetDataSize(gtk_selection_data_get_length(selection_data)); event.SetDataBuffer(const_cast(gtk_selection_data_get_data(selection_data))); @@ -3699,10 +3686,7 @@ wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest *WXUNUSED(drag_dest), { wxDataViewItem item(GetOwner()->GTKPathToItem(path)); - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() ); - event.SetEventObject( m_owner ); - event.SetItem( item ); - event.SetModel( m_wx_model ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner, item); event.SetDataFormat(gtk_selection_data_get_target(selection_data)); event.SetDataSize(gtk_selection_data_get_length(selection_data)); if (!m_owner->HandleWindowEvent( event )) @@ -3822,10 +3806,7 @@ bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wx bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item ) { - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() ); - event.SetEventObject( m_owner ); - event.SetModel( m_owner->GetModel() ); - event.SetItem( item ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner, item); m_owner->HandleWindowEvent( event ); return true; @@ -3833,12 +3814,9 @@ bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item ) bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned int view_column ) { - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() ); - event.SetEventObject( m_owner ); - event.SetModel( m_owner->GetModel() ); - event.SetColumn( view_column ); - event.SetDataViewColumn( GetOwner()->GetColumn(view_column) ); - event.SetItem( item ); + wxDataViewColumn* const column = m_owner->GetColumn(view_column); + wxDataViewEvent + event(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner, column, item); m_owner->HandleWindowEvent( event ); return true; @@ -4371,10 +4349,8 @@ wxdataview_selection_changed_callback( GtkTreeSelection* WXUNUSED(selection), wx if (!gtk_widget_get_realized(dv->m_widget)) return; - wxDataViewEvent event( wxEVT_DATAVIEW_SELECTION_CHANGED, dv->GetId() ); - event.SetEventObject( dv ); - event.SetItem( dv->GetSelection() ); - event.SetModel( dv->GetModel() ); + wxDataViewEvent + event(wxEVT_DATAVIEW_SELECTION_CHANGED, dv, dv->GetSelection()); dv->HandleWindowEvent( event ); } @@ -4382,11 +4358,8 @@ static void wxdataview_row_activated_callback( GtkTreeView* WXUNUSED(treeview), GtkTreePath *path, GtkTreeViewColumn *WXUNUSED(column), wxDataViewCtrl *dv ) { - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_ACTIVATED, dv->GetId() ); - wxDataViewItem item(dv->GTKPathToItem(path)); - event.SetItem( item ); - event.SetModel( dv->GetModel() ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_ACTIVATED, dv, item); dv->HandleWindowEvent( event ); } @@ -4394,11 +4367,8 @@ static gboolean wxdataview_test_expand_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter, GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv ) { - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_EXPANDING, dv->GetId() ); - - wxDataViewItem item( (void*) iter->user_data );; - event.SetItem( item ); - event.SetModel( dv->GetModel() ); + wxDataViewItem item( (void*) iter->user_data ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EXPANDING, dv, item); dv->HandleWindowEvent( event ); return !event.IsAllowed(); @@ -4408,11 +4378,8 @@ static void wxdataview_row_expanded_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter, GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv ) { - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_EXPANDED, dv->GetId() ); - - wxDataViewItem item( (void*) iter->user_data );; - event.SetItem( item ); - event.SetModel( dv->GetModel() ); + wxDataViewItem item( (void*) iter->user_data ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EXPANDED, dv, item); dv->HandleWindowEvent( event ); } @@ -4420,11 +4387,8 @@ static gboolean wxdataview_test_collapse_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter, GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv ) { - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_COLLAPSING, dv->GetId() ); - - wxDataViewItem item( (void*) iter->user_data );; - event.SetItem( item ); - event.SetModel( dv->GetModel() ); + wxDataViewItem item( (void*) iter->user_data ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_COLLAPSING, dv, item); dv->HandleWindowEvent( event ); return !event.IsAllowed(); @@ -4434,11 +4398,8 @@ static void wxdataview_row_collapsed_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter, GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv ) { - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_COLLAPSED, dv->GetId() ); - - wxDataViewItem item( (void*) iter->user_data );; - event.SetItem( item ); - event.SetModel( dv->GetModel() ); + wxDataViewItem item( (void*) iter->user_data ); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_COLLAPSED, dv, item); dv->HandleWindowEvent( event ); } @@ -4531,10 +4492,8 @@ gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget), gtk_tree_selection_select_path(selection, path); } - wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, dv->GetId() ); - if (path) - event.SetItem(dv->GTKPathToItem(path)); - event.SetModel( dv->GetModel() ); + wxDataViewEvent + event(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, dv, dv->GTKPathToItem(path)); return dv->HandleWindowEvent( event ); } diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 2ae7076d14..c4240a3435 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -544,10 +544,7 @@ outlineView:(NSOutlineView*)outlineView wxCHECK_MSG( dvc->GetModel(), false, "Pointer to model not set correctly." ); - wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP, dvc->GetId()); - event.SetEventObject(dvc); - event.SetItem(wxDataViewItemFromItem(item)); - event.SetModel(dvc->GetModel()); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP, dvc, wxDataViewItemFromItem(item)); BOOL dragSuccessful = false; if ( [bestType compare:DataViewPboardType] == NSOrderedSame ) @@ -755,16 +752,10 @@ outlineView:(NSOutlineView*)outlineView // send first the event to wxWidgets that the sorting has changed so that // the program can do special actions before the sorting actually starts: - wxDataViewEvent event(wxEVT_DATAVIEW_COLUMN_SORTED,dvc->GetId()); // variable definition - - event.SetEventObject(dvc); - if (noOfDescriptors > 0) - { - wxDataViewColumn* const col = [[wxSortDescriptors objectAtIndex:0] columnPtr]; - - event.SetColumn(dvc->GetColumnPosition(col)); - event.SetDataViewColumn(col); - } + wxDataViewColumn* const col = noOfDescriptors > 0 + ? [[wxSortDescriptors objectAtIndex:0] columnPtr] + : NULL; + wxDataViewEvent event(wxEVT_DATAVIEW_COLUMN_SORTED, dvc, col); dvc->GetEventHandler()->ProcessEvent(event); // start re-ordering the data; @@ -793,12 +784,7 @@ outlineView:(NSOutlineView*)outlineView wxCHECK_MSG(dvc, false, "Pointer to data view control not set correctly."); wxCHECK_MSG(dvc->GetModel(), false, "Pointer to model not set correctly."); - wxDataViewEvent - event(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE,dvc->GetId()); - - event.SetEventObject(dvc); - event.SetItem(wxDataViewItemFromItem(item)); - event.SetModel(dvc->GetModel()); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, dvc, wxDataViewItemFromItem(item)); if ([bestType compare:DataViewPboardType] == NSOrderedSame) { NSArray* dataArray((NSArray*)[pasteboard propertyListForType:DataViewPboardType]); @@ -898,22 +884,16 @@ outlineView:(NSOutlineView*)outlineView // send a begin drag event for all selected items and proceed with // dragging unless the event is vetoed: - wxDataViewEvent - event(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG,dvc->GetId()); - - event.SetEventObject(dvc); - event.SetModel(dvc->GetModel()); for (size_t itemCounter=0; itemCounter<[writeItems count]; ++itemCounter) { bool itemStringAvailable(false); // a flag indicating if for the current item a string is available wxDataObjectComposite* itemObject(new wxDataObjectComposite()); // data object for current item wxString itemString; // contains the TAB concatenated data of an item - event.SetItem( - wxDataViewItemFromItem([writeItems objectAtIndex:itemCounter])); - itemString = ::ConcatenateDataViewItemValues(dvc,event.GetItem()); + const wxDataViewItem item = wxDataViewItemFromItem([writeItems objectAtIndex:itemCounter]); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, dvc, item); + itemString = ::ConcatenateDataViewItemValues(dvc, item); itemObject->Add(new wxTextDataObject(itemString)); - event.SetDataObject(itemObject); // check if event has not been vetoed: if (dvc->HandleWindowEvent(event) && event.IsAllowed() && (event.GetDataObject()->GetFormatCount() > 0)) { @@ -1616,11 +1596,8 @@ outlineView:(NSOutlineView*)outlineView // sent whether the cell is editable or not wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_ACTIVATED,dvc->GetId()); - - - event.SetEventObject(dvc); - event.SetItem(wxDataViewItemFromItem([self itemAtRow:[self clickedRow]])); + const wxDataViewItem item = wxDataViewItemFromItem([self itemAtRow:[self clickedRow]]); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_ACTIVATED, dvc, item); dvc->GetEventHandler()->ProcessEvent(event); } @@ -1633,12 +1610,8 @@ outlineView:(NSOutlineView*)outlineView characterAtIndex: 0] == NSCarriageReturnCharacter ) { wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - - wxDataViewEvent eventDV( wxEVT_DATAVIEW_ITEM_ACTIVATED, dvc->GetId() ); - eventDV.SetEventObject(dvc); - eventDV.SetItem( wxDataViewItem( [[self itemAtRow:[self selectedRow]] pointer]) ); - eventDV.SetModel( dvc->GetModel() ); - + const wxDataViewItem item = wxDataViewItem( [[self itemAtRow:[self selectedRow]] pointer]); + wxDataViewEvent eventDV(wxEVT_DATAVIEW_ITEM_ACTIVATED, dvc, item); if ( !dvc->GetEventHandler()->ProcessEvent(eventDV) ) [super keyDown:event]; } @@ -1660,19 +1633,16 @@ outlineView:(NSOutlineView*)outlineView // menu should be shown or not wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU,dvc->GetId()); - - wxDataViewItemArray selectedItems; - - - event.SetEventObject(dvc); - event.SetModel(dvc->GetModel()); // get the item information; // theoretically more than one ID can be returned but the event can only // handle one item, therefore only the first item of the array is // returned: + wxDataViewItem item; + wxDataViewItemArray selectedItems; if (dvc->GetSelections(selectedItems) > 0) - event.SetItem(selectedItems[0]); + item = selectedItems[0]; + + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, dvc, item); dvc->GetEventHandler()->ProcessEvent(event); // nothing is done: return nil; @@ -1688,14 +1658,8 @@ outlineView:(NSOutlineView*)outlineView wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent - event(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK,dvc->GetId()); - - // first, send an event that the user clicked into a column's header: - event.SetEventObject(dvc); - event.SetColumn(dvc->GetColumnPosition(col)); - event.SetDataViewColumn(col); + wxDataViewEvent event(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, dvc, col); dvc->HandleWindowEvent(event); // now, check if the click may have had an influence on sorting, too; @@ -1731,13 +1695,7 @@ outlineView:(NSOutlineView*)outlineView wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_COLLAPSING,dvc->GetId()); - - - event.SetEventObject(dvc); - event.SetItem (wxDataViewItemFromItem(item)); - event.SetModel (dvc->GetModel()); - // finally send the equivalent wxWidget event: + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_COLLAPSING, dvc, wxDataViewItemFromItem(item)); dvc->GetEventHandler()->ProcessEvent(event); // opening the container is allowed if not vetoed: return event.IsAllowed(); @@ -1749,13 +1707,7 @@ outlineView:(NSOutlineView*)outlineView wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EXPANDING,dvc->GetId()); - - - event.SetEventObject(dvc); - event.SetItem (wxDataViewItemFromItem(item)); - event.SetModel (dvc->GetModel()); - // finally send the equivalent wxWidget event: + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EXPANDING, dvc, wxDataViewItemFromItem(item)); dvc->GetEventHandler()->ProcessEvent(event); // opening the container is allowed if not vetoed: return event.IsAllowed(); @@ -1818,12 +1770,7 @@ outlineView:(NSOutlineView*)outlineView wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent event(wxEVT_DATAVIEW_COLUMN_REORDERED,dvc->GetId()); - - - event.SetEventObject(dvc); - event.SetColumn(dvc->GetColumnPosition(col)); - event.SetDataViewColumn(col); + wxDataViewEvent event(wxEVT_DATAVIEW_COLUMN_REORDERED, dvc, col); dvc->GetEventHandler()->ProcessEvent(event); } @@ -1831,12 +1778,9 @@ outlineView:(NSOutlineView*)outlineView { wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_COLLAPSED,dvc->GetId()); - - - event.SetEventObject(dvc); - event.SetItem(wxDataViewItemFromItem( - [[notification userInfo] objectForKey:@"NSObject"])); + const wxDataViewItem item = wxDataViewItemFromItem( + [[notification userInfo] objectForKey:@"NSObject"]); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_COLLAPSED, dvc, item); dvc->GetEventHandler()->ProcessEvent(event); } @@ -1844,12 +1788,9 @@ outlineView:(NSOutlineView*)outlineView { wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EXPANDED,dvc->GetId()); - - - event.SetEventObject(dvc); - event.SetItem(wxDataViewItemFromItem( - [[notification userInfo] objectForKey:@"NSObject"])); + const wxDataViewItem item = wxDataViewItemFromItem( + [[notification userInfo] objectForKey:@"NSObject"]); + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EXPANDED, dvc, item); dvc->GetEventHandler()->ProcessEvent(event); } @@ -1859,11 +1800,7 @@ outlineView:(NSOutlineView*)outlineView wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent event(wxEVT_DATAVIEW_SELECTION_CHANGED,dvc->GetId()); - - event.SetEventObject(dvc); - event.SetModel(dvc->GetModel()); - event.SetItem(dvc->GetSelection()); + wxDataViewEvent event(wxEVT_DATAVIEW_SELECTION_CHANGED, dvc, dvc->GetSelection()); dvc->GetEventHandler()->ProcessEvent(event); } @@ -1928,15 +1865,11 @@ outlineView:(NSOutlineView*)outlineView wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - // send event to wxWidgets: - wxDataViewEvent - event(wxEVT_DATAVIEW_ITEM_EDITING_DONE,dvc->GetId()); + const wxDataViewItem + item = wxDataViewItemFromItem([self itemAtRow:currentlyEditedRow]); - event.SetEventObject(dvc); - event.SetItem( - wxDataViewItemFromItem([self itemAtRow:currentlyEditedRow])); - event.SetColumn(dvc->GetColumnPosition(col)); - event.SetDataViewColumn(col); + // send event to wxWidgets: + wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_EDITING_DONE, dvc, col, item); dvc->GetEventHandler()->ProcessEvent(event); diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index 8aa128eca3..df8d4eb5fb 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -122,13 +122,8 @@ bool wxOSXDataViewModelNotifier::ItemChanged(wxDataViewItem const& item) wxCHECK_MSG(GetOwner() != NULL,false,"Owner not initialized."); if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(item),item)) { - // sent the equivalent wxWidget event: - wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId()); - - dataViewEvent.SetEventObject(m_DataViewCtrlPtr); - dataViewEvent.SetModel(m_DataViewCtrlPtr->GetModel()); - dataViewEvent.SetItem(item); - // sent the equivalent wxWidget event: + // send the equivalent wxWidgets event: + wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_DataViewCtrlPtr, item); m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent); // row height may have to be adjusted: AdjustRowHeight(item); @@ -144,16 +139,11 @@ bool wxOSXDataViewModelNotifier::ItemsChanged(wxDataViewItemArray const& items) { size_t const noOfItems = items.GetCount(); - wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId()); - - - dataViewEvent.SetEventObject(m_DataViewCtrlPtr); - dataViewEvent.SetModel(m_DataViewCtrlPtr->GetModel()); for (size_t indexItem=0; indexItemGetDataViewPeer()->Update(GetOwner()->GetParent(items[indexItem]),items[indexItem])) { - // send for all changed items a wxWidget event: - dataViewEvent.SetItem(items[indexItem]); + // send for all changed items a wxWidgets event: + wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr,items[indexItem]); m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent); } else @@ -211,13 +201,9 @@ bool wxOSXDataViewModelNotifier::ValueChanged(wxDataViewItem const& item, unsign wxCHECK_MSG(GetOwner() != NULL,false,"Owner not initialized."); if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(item),item)) { - wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId()); + wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_DataViewCtrlPtr, m_DataViewCtrlPtr->GetColumn(col), item); - dataViewEvent.SetEventObject(m_DataViewCtrlPtr); - dataViewEvent.SetModel(m_DataViewCtrlPtr->GetModel()); - dataViewEvent.SetColumn(col); - dataViewEvent.SetItem(item); - // send the equivalent wxWidget event: + // send the equivalent wxWidgets event: m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent); AdjustAutosizedColumns(); From c4e892629fbb0f7a585515f59fcf7cb6ae132c91 Mon Sep 17 00:00:00 2001 From: wanup Date: Sat, 19 Mar 2016 00:12:38 +0100 Subject: [PATCH 11/19] Implement wxDataViewChoiceByIndexRenderer for wxOSX Add missing class implementation. Closes #17452. --- docs/changes.txt | 1 + include/wx/osx/dvrenderers.h | 19 ++++++++++++++++ src/osx/cocoa/dataview.mm | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index a7fb5917f5..c2edd51abd 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -82,6 +82,7 @@ wxOSX: - Remove extra borders around wxFilePickerCtrl (John Roberts). - Set up extensions filter correctly in wxFileDialog (nick863). - Turn off automatic quotes substitutions in wxTextCtrl (Xlord2). +- Implement wxDataViewChoiceByIndexRenderer (wanup). Unix: diff --git a/include/wx/osx/dvrenderers.h b/include/wx/osx/dvrenderers.h index 2e43251261..bb41f3d5b8 100644 --- a/include/wx/osx/dvrenderers.h +++ b/include/wx/osx/dvrenderers.h @@ -116,6 +116,25 @@ private: wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewChoiceRenderer); }; +// ---------------------------------------------------------------------------- +// wxDataViewChoiceByIndexRenderer +// ---------------------------------------------------------------------------- + +class WXDLLIMPEXP_ADV wxDataViewChoiceByIndexRenderer: public wxDataViewChoiceRenderer +{ +public: + wxDataViewChoiceByIndexRenderer(const wxArrayString& choices, + wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, + int alignment = wxDVR_DEFAULT_ALIGNMENT); + + virtual bool SetValue(const wxVariant& value) wxOVERRIDE; + virtual bool GetValue(wxVariant& value) const wxOVERRIDE; + + virtual void OSXOnCellChanged(NSObject *value, + const wxDataViewItem& item, + unsigned col) wxOVERRIDE; +}; + #endif // wxOSX_USE_COCOA // --------------------------------------------------------- diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index c4240a3435..022fc779d4 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2836,6 +2836,49 @@ bool wxDataViewChoiceRenderer::MacRender() wxIMPLEMENT_CLASS(wxDataViewChoiceRenderer, wxDataViewRenderer); +// ---------------------------------------------------------------------------- +// wxDataViewChoiceByIndexRenderer +// ---------------------------------------------------------------------------- + +wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer(const wxArrayString& choices, + wxDataViewCellMode mode, + int alignment) + : wxDataViewChoiceRenderer(choices, mode, alignment) +{ + m_variantType = wxS("long"); +} + +void +wxDataViewChoiceByIndexRenderer::OSXOnCellChanged(NSObject *value, + const wxDataViewItem& item, + unsigned col) +{ + wxVariant valueLong(ObjectToLong(value)); + if ( !Validate(valueLong) ) + return; + + wxDataViewModel *model = GetOwner()->GetOwner()->GetModel(); + model->ChangeValue(valueLong, item, col); +} + +bool +wxDataViewChoiceByIndexRenderer::SetValue(const wxVariant& value) +{ + const wxVariant valueStr = GetChoice(value.GetLong()); + return wxDataViewChoiceRenderer::SetValue(valueStr); +} + +bool +wxDataViewChoiceByIndexRenderer::GetValue(wxVariant& value) const +{ + wxVariant valueStr; + if ( !wxDataViewChoiceRenderer::GetValue(valueStr) ) + return false; + + value = (long) GetChoices().Index(valueStr.GetString()); + return true; +} + // --------------------------------------------------------- // wxDataViewDateRenderer // --------------------------------------------------------- From 6316045e19f0b5bb60d6c86d0e17b7c86c8dea92 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 19 Mar 2016 00:14:35 +0100 Subject: [PATCH 12/19] Remove unnecessary wxOSX_USE_COCOA checks in wx/osx/dvrenderers.h These checks are not needed any more now that Carbon is not supported any loner. --- include/wx/osx/dvrenderers.h | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/include/wx/osx/dvrenderers.h b/include/wx/osx/dvrenderers.h index bb41f3d5b8..4da26441a6 100644 --- a/include/wx/osx/dvrenderers.h +++ b/include/wx/osx/dvrenderers.h @@ -57,11 +57,9 @@ public: virtual bool MacRender(); -#if wxOSX_USE_COCOA virtual void OSXOnCellChanged(NSObject *value, const wxDataViewItem& item, unsigned col); -#endif // Cocoa private: wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer); @@ -86,8 +84,6 @@ private: wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer); }; -#if wxOSX_USE_COCOA - // ------------------------------------- // wxDataViewChoiceRenderer // ------------------------------------- @@ -104,11 +100,9 @@ public: wxString GetChoice(size_t index) const { return m_choices[index]; } const wxArrayString& GetChoices() const { return m_choices; } -#if wxOSX_USE_COCOA virtual void OSXOnCellChanged(NSObject *value, const wxDataViewItem& item, unsigned col); -#endif // Cocoa private: wxArrayString m_choices; @@ -135,8 +129,6 @@ public: unsigned col) wxOVERRIDE; }; -#endif // wxOSX_USE_COCOA - // --------------------------------------------------------- // wxDataViewIconTextRenderer // --------------------------------------------------------- @@ -151,11 +143,9 @@ public: virtual bool MacRender(); -#if wxOSX_USE_COCOA virtual void OSXOnCellChanged(NSObject *value, const wxDataViewItem& item, unsigned col); -#endif // Cocoa private: wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer); @@ -176,11 +166,9 @@ public: virtual bool MacRender(); -#if wxOSX_USE_COCOA virtual void OSXOnCellChanged(NSObject *value, const wxDataViewItem& item, unsigned col); -#endif // Cocoa private: wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer); @@ -202,11 +190,9 @@ public: virtual bool MacRender(); -#if wxOSX_USE_COCOA virtual void OSXOnCellChanged(NSObject *value, const wxDataViewItem& item, unsigned col); -#endif // Cocoa private: wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer); @@ -227,11 +213,9 @@ public: virtual bool MacRender(); -#if wxOSX_USE_COCOA virtual void OSXOnCellChanged(NSObject *value, const wxDataViewItem& item, unsigned col); -#endif // Cocoa private: wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer); From a20183440b21fd6af6786fb4aee9c6c372747951 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 19 Mar 2016 00:45:15 +0100 Subject: [PATCH 13/19] Set item being edited earlier in wxDataViewRenderer Partially undo the changes of e417913f4676c8b4ae2104e23cdbdd2c945ee588 and set m_item in StartEditing() as it's supposed to be already set when CreateEditorCtrl() is called and setting it in NotifyEditingStarted() was too late for this. --- src/common/datavcmn.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 1d9ee90af5..c5440b80de 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -678,6 +678,9 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la if( !event.IsAllowed() ) return false; + // Remember the item being edited for use in FinishEditing() later. + m_item = item; + unsigned int col = GetOwner()->GetModelColumn(); const wxVariant& value = CheckedGetValue(dv_ctrl->GetModel(), item, col); @@ -685,7 +688,10 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la // there might be no editor control for the given item if(!m_editorCtrl) + { + m_item = wxDataViewItem(); return false; + } wxDataViewEditorCtrlEvtHandler *handler = new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this ); @@ -703,9 +709,6 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la void wxDataViewRendererBase::NotifyEditingStarted(const wxDataViewItem& item) { - // Remember the item being edited for use in FinishEditing() later. - m_item = item; - wxDataViewColumn* const column = GetOwner(); wxDataViewCtrl* const dv_ctrl = column->GetOwner(); From 1bbc44daff4ee823e4fe385c46c5eba269617c17 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 22 Mar 2016 17:49:49 +0100 Subject: [PATCH 14/19] Support background colour in wxDataViewItemAttr in wxGTK The code handling background colour was commented out for some reason, simply enable it as it seems to be working just fine -- and update the sample to show that it does. --- docs/changes.txt | 1 + samples/dataview/mymodels.cpp | 3 ++- src/gtk/dataview.cpp | 2 -- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index c2edd51abd..4beac69e93 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -71,6 +71,7 @@ All (GUI): wxGTK: - Implement setting link colours in wxHyperlinkCtrl for GTK+3 (Hanmac). +- Support background colour in wxDataViewCtrl attributes. wxMSW: diff --git a/samples/dataview/mymodels.cpp b/samples/dataview/mymodels.cpp index 590d3f2e67..bf6b219206 100644 --- a/samples/dataview/mymodels.cpp +++ b/samples/dataview/mymodels.cpp @@ -470,7 +470,8 @@ bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col, case Col_IconText: if ( !(row % 2) ) return false; - attr.SetColour(*wxLIGHT_GREY); + attr.SetColour(*wxYELLOW); + attr.SetBackgroundColour(*wxLIGHT_GREY); break; case Col_TextWithAttr: diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 4e04d7994e..2e73aae7b2 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -2248,7 +2248,6 @@ void GtkApplyAttr(GtkCellRendererText *renderer, const wxDataViewItemAttr& attr) g_value_unset( &gvalue ); } -#if 0 if (attr.HasBackgroundColour()) { wxColour colour = attr.GetBackgroundColour(); @@ -2268,7 +2267,6 @@ void GtkApplyAttr(GtkCellRendererText *renderer, const wxDataViewItemAttr& attr) g_object_set_property( G_OBJECT(renderer), "cell-background-set", &gvalue ); g_value_unset( &gvalue ); } -#endif } } // anonymous namespace From d324bd2469d92203af93d8987a85d7594c09bf26 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 22 Mar 2016 19:32:06 +0100 Subject: [PATCH 15/19] Don't crash if overridden wxDataViewModel::GetValue() throws Don't let any exceptions propagate to GTK+ code as this results in an immediate crash there, at least with GTK+ 3.14.5. --- src/common/datavcmn.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index c5440b80de..dc238d62a9 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -26,6 +26,7 @@ #endif #include "wx/datectrl.h" +#include "wx/except.h" #include "wx/spinctrl.h" #include "wx/choice.h" #include "wx/imaglist.h" @@ -818,6 +819,11 @@ wxDataViewRendererBase::PrepareForItem(const wxDataViewModel *model, const wxDataViewItem& item, unsigned column) { + // This method is called by the native control, so we shouldn't allow + // exceptions to escape from it. + wxTRY + { + // Now check if we have a value and remember it for rendering it later. // Notice that we do it even if it's null, as the cell should be empty then // and not show the last used value. @@ -849,6 +855,15 @@ wxDataViewRendererBase::PrepareForItem(const wxDataViewModel *model, SetEnabled(enabled); + } + wxCATCH_ALL + ( + // There is not much we can do about it here, just log it and don't + // show anything in this cell. + wxLogDebug("Retrieving the value from the model threw an exception"); + SetValue(wxVariant()); + ) + return true; } From aa9e7d3326bc25d693175f1651db918722727e07 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 22 Mar 2016 21:14:10 +0100 Subject: [PATCH 16/19] Don't make wxDataViewCtrl::ExpandAncestors() virtual This method has a common implementation and is not supposed to be overridden. --- include/wx/dataview.h | 2 +- interface/wx/dataview.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 5cebecc126..781f87dc95 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -706,7 +706,7 @@ public: virtual void UnselectAll() = 0; virtual void Expand( const wxDataViewItem & item ) = 0; - virtual void ExpandAncestors( const wxDataViewItem & item ); + void ExpandAncestors( const wxDataViewItem & item ); virtual void Collapse( const wxDataViewItem & item ) = 0; virtual bool IsExpanded( const wxDataViewItem & item ) const = 0; diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index 950f6a21a1..eef3737576 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -1299,7 +1299,7 @@ public: ensures that the item itself as well as all ancestor items have been read from the model by the control. */ - virtual void ExpandAncestors( const wxDataViewItem & item ); + void ExpandAncestors( const wxDataViewItem & item ); /** Returns pointer to the column. @a pos refers to the position in the From 716dace3d6a414d892b72f7cb99f0effbe7f0487 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 22 Mar 2016 21:22:36 +0100 Subject: [PATCH 17/19] Make wxDataViewCtrl::Expand() expand ancestors in native ports too Expand() called ExpandAncestors() in the generic wxDataViewCtrl implementation but not in the native ones, resulting in observable difference in the behaviour: for example, the wxDataViewTreeCtrl in the dataview sample appeared initially expanded under MSW, using the generic version, but collapsed under GTK and OSX. Harmonize this among all ports. This also has a nice side effect of making Expand() less horribly inefficient as it is not recursively called by ExpandAncestors() which it itself used to call: now ExpandAncestors() only calls DoExpand() which is a simple function that only expands the item passed to it and does nothing else. Closes #14803. --- docs/changes.txt | 1 + include/wx/dataview.h | 6 +++++- include/wx/generic/dataview.h | 3 ++- include/wx/gtk/dataview.h | 3 ++- include/wx/osx/cocoa/dataview.h | 4 +++- include/wx/osx/core/dataview.h | 3 ++- include/wx/osx/dataview.h | 3 ++- src/common/datavcmn.cpp | 9 ++++++++- src/generic/datavgen.cpp | 4 +--- src/gtk/dataview.cpp | 2 +- src/osx/cocoa/dataview.mm | 2 +- src/osx/dataview_osx.cpp | 4 ++-- 12 files changed, 30 insertions(+), 14 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 4beac69e93..80c746a309 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -67,6 +67,7 @@ All (GUI): - Add support for wxAuiManager and wxAuiPaneInfo to XRC (Andrea Zanellato). - Update Scintilla to v3.6.3 (Paul Kulchenko). +- Make wxDataViewCtrl::Expand() expand ancestors in native ports too. wxGTK: diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 781f87dc95..3b8bc71e25 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -705,7 +705,7 @@ public: virtual void SelectAll() = 0; virtual void UnselectAll() = 0; - virtual void Expand( const wxDataViewItem & item ) = 0; + void Expand( const wxDataViewItem & item ); void ExpandAncestors( const wxDataViewItem & item ); virtual void Collapse( const wxDataViewItem & item ) = 0; virtual bool IsExpanded( const wxDataViewItem & item ) const = 0; @@ -747,6 +747,10 @@ protected: virtual void DoSetExpanderColumn() = 0 ; virtual void DoSetIndent() = 0; + // Just expand this item assuming it is already shown, i.e. its parent has + // been already expanded using ExpandAncestors(). + virtual void DoExpand(const wxDataViewItem & item) = 0; + private: // Implementation of the public Set/GetCurrentItem() methods which are only // called in multi selection case (for single selection controls their diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 591ba2fadf..224f90f166 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -236,7 +236,6 @@ public: virtual bool SetRowHeight( int rowHeight ) wxOVERRIDE; - virtual void Expand( const wxDataViewItem & item ) wxOVERRIDE; virtual void Collapse( const wxDataViewItem & item ) wxOVERRIDE; virtual bool IsExpanded( const wxDataViewItem & item ) const wxOVERRIDE; @@ -318,6 +317,8 @@ private: virtual wxDataViewItem DoGetCurrentItem() const wxOVERRIDE; virtual void DoSetCurrentItem(const wxDataViewItem& item) wxOVERRIDE; + virtual void DoExpand(const wxDataViewItem& item) wxOVERRIDE; + void InvalidateColBestWidths(); void InvalidateColBestWidth(int idx); void UpdateColWidths(); diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index f2064218aa..3f246ddfd4 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -161,7 +161,6 @@ public: virtual void EditItem(const wxDataViewItem& item, const wxDataViewColumn *column) wxOVERRIDE; - virtual void Expand( const wxDataViewItem & item ) wxOVERRIDE; virtual void Collapse( const wxDataViewItem & item ) wxOVERRIDE; virtual bool IsExpanded( const wxDataViewItem & item ) const wxOVERRIDE; @@ -190,6 +189,8 @@ protected: virtual void DoSetExpanderColumn() wxOVERRIDE; virtual void DoSetIndent() wxOVERRIDE; + virtual void DoExpand(const wxDataViewItem& item) wxOVERRIDE; + virtual void DoApplyWidgetStyle(GtkRcStyle *style) wxOVERRIDE; private: diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index 65fc99c2b3..f3d613d19d 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -447,7 +447,6 @@ public: virtual void Collapse(const wxDataViewItem& item); virtual void EnsureVisible(const wxDataViewItem& item, wxDataViewColumn const* columnPtr); - virtual void Expand(const wxDataViewItem& item); virtual unsigned int GetCount() const; virtual wxRect GetRectangle(const wxDataViewItem& item, wxDataViewColumn const* columnPtr); @@ -490,6 +489,9 @@ public: // other methods (inherited from wxDataViewWidgetImpl) // virtual void DoSetIndent(int indent); + + virtual void DoExpand(const wxDataViewItem& item); + virtual void HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const; diff --git a/include/wx/osx/core/dataview.h b/include/wx/osx/core/dataview.h index 440be5e8e0..788ab42b03 100644 --- a/include/wx/osx/core/dataview.h +++ b/include/wx/osx/core/dataview.h @@ -62,7 +62,6 @@ public: virtual bool Add (wxDataViewItem const& parent, wxDataViewItemArray const& itesm) = 0; // adds a items to the native control virtual void Collapse (wxDataViewItem const& item) = 0; // collapses the passed item in the native control virtual void EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) = 0; // ensures that the passed item's value in the passed column is visible (column pointer can be NULL) - virtual void Expand (wxDataViewItem const& item) = 0; // expands the passed item in the native control virtual unsigned int GetCount (void) const = 0; // returns the number of items in the native control virtual wxRect GetRectangle (wxDataViewItem const& item, wxDataViewColumn const* columnPtr) = 0; // returns the rectangle that is used by the passed item and column in the native control virtual bool IsExpanded (wxDataViewItem const& item) const = 0; // checks if the passed item is expanded in the native control @@ -104,6 +103,8 @@ public: // other methods // virtual void DoSetIndent (int indent) = 0; // sets the indention in the native control + virtual void DoExpand (wxDataViewItem const& item) = 0; // expands the passed item in the native control + 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 diff --git a/include/wx/osx/dataview.h b/include/wx/osx/dataview.h index 2f7261cc1f..7d81447ebf 100644 --- a/include/wx/osx/dataview.h +++ b/include/wx/osx/dataview.h @@ -169,7 +169,6 @@ public: virtual void Collapse( const wxDataViewItem& item) wxOVERRIDE; virtual void EnsureVisible(const wxDataViewItem& item, const wxDataViewColumn* columnPtr=NULL) wxOVERRIDE; - virtual void Expand(const wxDataViewItem& item) wxOVERRIDE; virtual bool IsExpanded(const wxDataViewItem & item) const wxOVERRIDE; virtual unsigned int GetCount() const; @@ -271,6 +270,8 @@ protected: virtual void DoSetExpanderColumn() wxOVERRIDE; virtual void DoSetIndent() wxOVERRIDE; + virtual void DoExpand(const wxDataViewItem& item) wxOVERRIDE; + virtual wxSize DoGetBestSize() const wxOVERRIDE; // event handling diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index dc238d62a9..d2ab84197f 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -1166,6 +1166,13 @@ const wxDataViewModel* wxDataViewCtrlBase::GetModel() const return m_model; } +void wxDataViewCtrlBase::Expand(const wxDataViewItem& item) +{ + ExpandAncestors(item); + + DoExpand(item); +} + void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item ) { if (!m_model) return; @@ -1185,7 +1192,7 @@ void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item ) // then we expand the parents, starting at the root while (!parentChain.empty()) { - Expand(parentChain.back()); + DoExpand(parentChain.back()); parentChain.pop_back(); } } diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index e1a3861b89..41f4403240 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -5273,10 +5273,8 @@ int wxDataViewCtrl::GetRowByItem( const wxDataViewItem & item ) const return m_clientArea->GetRowByItem( item ); } -void wxDataViewCtrl::Expand( const wxDataViewItem & item ) +void wxDataViewCtrl::DoExpand( const wxDataViewItem & item ) { - ExpandAncestors( item ); - int row = m_clientArea->GetRowByItem( item ); if (row != -1) m_clientArea->Expand(row); diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 2e73aae7b2..8be64c4633 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -4820,7 +4820,7 @@ wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const return m_internal->GetDataViewSortColumn(); } -void wxDataViewCtrl::Expand( const wxDataViewItem & item ) +void wxDataViewCtrl::DoExpand( const wxDataViewItem & item ) { GtkTreeIter iter; iter.user_data = item.GetID(); diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 022fc779d4..61f493874a 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2156,7 +2156,7 @@ void wxCocoaDataViewControl::EnsureVisible(const wxDataViewItem& item, const wxD } } -void wxCocoaDataViewControl::Expand(const wxDataViewItem& item) +void wxCocoaDataViewControl::DoExpand(const wxDataViewItem& item) { [m_OutlineView expandItem:[m_DataSource getDataViewItemFromBuffer:item]]; } diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index df8d4eb5fb..926bf972f7 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -506,9 +506,9 @@ void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn } } -void wxDataViewCtrl::Expand(wxDataViewItem const& item) +void wxDataViewCtrl::DoExpand(wxDataViewItem const& item) { - return GetDataViewPeer()->Expand(item); + return GetDataViewPeer()->DoExpand(item); } bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const From b7e0625b9046013a4c4c495d76b1d5ee0a802bb9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 22 Mar 2016 21:44:38 +0100 Subject: [PATCH 18/19] Don't indent the expander column in list wxDataViewCtrl in wxOSX Indenting the column contents to leave enough space for the expanders is unnecessary in this case, so just don't do it. Closes #17409. --- docs/changes.txt | 1 + src/osx/cocoa/dataview.mm | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 80c746a309..55618bd2cf 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -85,6 +85,7 @@ wxOSX: - Set up extensions filter correctly in wxFileDialog (nick863). - Turn off automatic quotes substitutions in wxTextCtrl (Xlord2). - Implement wxDataViewChoiceByIndexRenderer (wanup). +- Fix unnecessary indentation in list-like wxDataViewCtrl (Andreas Falkenhahn). Unix: diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 61f493874a..3bd3efadb7 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2239,6 +2239,15 @@ bool wxCocoaDataViewControl::AssociateModel(wxDataViewModel* model) else m_DataSource = NULL; [m_OutlineView setDataSource:m_DataSource]; // if there is a data source the data is immediately going to be requested + + // By default, the first column is indented to leave enough place for the + // expanders, but this looks bad if there are no expanders, so don't use + // indent in this case. + if ( model && model->IsListModel() ) + { + DoSetIndent(0); + } + return true; } From 6beaeedf581dfd8bf2bf4d5b87c98889b803acd0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 24 Mar 2016 16:31:15 +0100 Subject: [PATCH 19/19] Correct tests for wxUSE_GENERICDATAVIEWCTRL in wxOSX code We must include wx/dataview.h, where this symbol is defined, before testing for it. --- src/osx/cocoa/dataview.mm | 10 ++++++++-- src/osx/dataview_osx.cpp | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 3bd3efadb7..db4f96d6d1 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -10,7 +10,11 @@ #include "wx/wxprec.h" -#if (wxUSE_DATAVIEWCTRL == 1) && !defined(wxUSE_GENERICDATAVIEWCTRL) +#if wxUSE_DATAVIEWCTRL + +#include "wx/dataview.h" + +#if !defined(wxUSE_GENERICDATAVIEWCTRL) #ifndef WX_PRECOMP #include "wx/app.h" @@ -3290,4 +3294,6 @@ void wxDataViewColumn::SetNativeData(wxDataViewColumnNativeData* newNativeDataPt m_NativeDataPtr = newNativeDataPtr; } -#endif // (wxUSE_DATAVIEWCTRL == 1) && !defined(wxUSE_GENERICDATAVIEWCTRL) +#endif // !wxUSE_GENERICDATAVIEWCTRL + +#endif // wxUSE_DATAVIEWCTRL diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index 926bf972f7..2cdbc36020 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -9,7 +9,11 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -#if (wxUSE_DATAVIEWCTRL != 0) && (!defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0)) +#if wxUSE_DATAVIEWCTRL + +#include "wx/dataview.h" + +#ifndef wxUSE_GENERICDATAVIEWCTRL #include @@ -728,5 +732,6 @@ wxBEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase) EVT_MOTION(wxDataViewCtrl::OnMouse) wxEND_EVENT_TABLE() -#endif // (wxUSE_DATAVIEWCTRL != 0) && (!defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0)) +#endif // !wxUSE_GENERICDATAVIEWCTRL +#endif // wxUSE_DATAVIEWCTRL