From e0ef3830c13f0d7d7b871c27348de6c042e520d9 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sat, 17 Apr 2021 18:42:09 +0100 Subject: [PATCH 1/4] Fix centering of images in wxListCtrl items when selected Closes #11331. --- include/wx/generic/private/listctrl.h | 6 +++--- src/generic/listctrl.cpp | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/wx/generic/private/listctrl.h b/include/wx/generic/private/listctrl.h index e0da92797f..63c97e24d9 100644 --- a/include/wx/generic/private/listctrl.h +++ b/include/wx/generic/private/listctrl.h @@ -190,9 +190,9 @@ public: wxT("width can only be increased") ); m_rectAll.width = w; - m_rectLabel.x = m_rectAll.x + (w - m_rectLabel.width) / 2; - m_rectIcon.x = m_rectAll.x + (w - m_rectIcon.width) / 2; - m_rectHighlight.x = m_rectAll.x + (w - m_rectHighlight.width) / 2; + m_rectLabel.x += (w - m_rectLabel.width) / 2; + m_rectIcon.x += (w - m_rectIcon.width) / 2; + m_rectHighlight.x += (w - m_rectHighlight.width) / 2; } } *m_gi; diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 1810bb19f3..e82b217201 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -552,8 +552,7 @@ void wxListLineData::SetPosition( int x, int y, int spacing ) if ( item->HasImage() ) { - m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4 + - (m_gi->m_rectAll.width - m_gi->m_rectIcon.width) / 2; + m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4; m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4; } From 797bc2c087756b0f577dd7ee02554e931d22e409 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sat, 17 Apr 2021 19:33:25 +0100 Subject: [PATCH 2/4] Introduce ABI shims for wxListCtrl column ordering functions This way it is easier to add the functions later on without breaking ABI. --- include/wx/generic/listctrl.h | 8 ++++++++ include/wx/listbase.h | 8 ++++++++ include/wx/msw/listctrl.h | 8 ++++---- include/wx/qt/listctrl.h | 8 ++++---- src/generic/listctrl.cpp | 25 +++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/include/wx/generic/listctrl.h b/include/wx/generic/listctrl.h index 8bd63b7ae5..48949dac07 100644 --- a/include/wx/generic/listctrl.h +++ b/include/wx/generic/listctrl.h @@ -68,6 +68,14 @@ public: bool SetColumn( int col, const wxListItem& item ) wxOVERRIDE; int GetColumnWidth( int col ) const wxOVERRIDE; bool SetColumnWidth( int col, int width) wxOVERRIDE; + + // Column ordering functions + int GetColumnOrder(int col) const wxOVERRIDE; + int GetColumnIndexFromOrder(int order) const wxOVERRIDE; + + wxArrayInt GetColumnsOrder() const wxOVERRIDE; + bool SetColumnsOrder(const wxArrayInt& orders) wxOVERRIDE; + int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think wxRect GetViewRect() const; diff --git a/include/wx/listbase.h b/include/wx/listbase.h index f786bfd278..7d8e8f68b4 100644 --- a/include/wx/listbase.h +++ b/include/wx/listbase.h @@ -399,6 +399,14 @@ public: virtual int GetColumnWidth(int col) const = 0; virtual bool SetColumnWidth(int col, int width) = 0; + // Column ordering functions + virtual int GetColumnOrder(int col) const = 0; + virtual int GetColumnIndexFromOrder(int order) const = 0; + + virtual wxArrayInt GetColumnsOrder() const = 0; + virtual bool SetColumnsOrder(const wxArrayInt& orders) = 0; + + // Other miscellaneous accessors. // ------------------------------ diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index 64bac9ca90..cb5e16a2fe 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -129,14 +129,14 @@ public: // Gets the column order from its index or index from its order - int GetColumnOrder(int col) const; - int GetColumnIndexFromOrder(int order) const; + int GetColumnOrder(int col) const wxOVERRIDE; + int GetColumnIndexFromOrder(int order) const wxOVERRIDE; // Gets the column order for all columns - wxArrayInt GetColumnsOrder() const; + wxArrayInt GetColumnsOrder() const wxOVERRIDE; // Sets the column order for all columns - bool SetColumnsOrder(const wxArrayInt& orders); + bool SetColumnsOrder(const wxArrayInt& orders) wxOVERRIDE; // Gets the number of items that can fit vertically in the diff --git a/include/wx/qt/listctrl.h b/include/wx/qt/listctrl.h index ae529b503a..34a5eba779 100644 --- a/include/wx/qt/listctrl.h +++ b/include/wx/qt/listctrl.h @@ -60,14 +60,14 @@ public: // Gets the column order from its index or index from its order - int GetColumnOrder(int col) const; - int GetColumnIndexFromOrder(int order) const; + int GetColumnOrder(int col) const wxOVERRIDE; + int GetColumnIndexFromOrder(int order) const wxOVERRIDE; // Gets the column order for all columns - wxArrayInt GetColumnsOrder() const; + wxArrayInt GetColumnsOrder() const wxOVERRIDE; // Sets the column order for all columns - bool SetColumnsOrder(const wxArrayInt& orders); + bool SetColumnsOrder(const wxArrayInt& orders) wxOVERRIDE; // Gets the number of items that can fit vertically in the diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index e82b217201..3ba6b9576c 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -5162,6 +5162,31 @@ bool wxGenericListCtrl::SetColumnWidth( int col, int width ) return true; } +// Column ordering functions +int wxGenericListCtrl::GetColumnOrder(int col) const +{ + // TODO: Implement this on generic port + return col; +} + +int wxGenericListCtrl::GetColumnIndexFromOrder(int order) const +{ + // TODO: Implement this on generic port + return order; +} + +wxArrayInt wxGenericListCtrl::GetColumnsOrder() const +{ + // TODO: Implement this on generic port + return wxArrayInt(); +} + +bool wxGenericListCtrl::SetColumnsOrder(const wxArrayInt& WXUNUSED(orders)) +{ + // TODO: Implement this on generic port + return false; +} + int wxGenericListCtrl::GetCountPerPage() const { return m_mainWin->GetCountPerPage(); // different from Windows ? From 48b1175f61e85fd0fec45264ab6f4dd1c1054145 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sat, 17 Apr 2021 19:34:26 +0100 Subject: [PATCH 3/4] Update the documentation for wxListCtrl column ordering --- interface/wx/listctrl.h | 88 +++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/interface/wx/listctrl.h b/interface/wx/listctrl.h index d44b21d8b5..93f09127ac 100644 --- a/interface/wx/listctrl.h +++ b/interface/wx/listctrl.h @@ -152,6 +152,40 @@ enum modes. You can use the generic implementation for report mode as well by setting the @c mac.listctrl.always_use_generic system option (see wxSystemOptions) to 1. + @subsection column_order Column Ordering + + By default, the columns of a list control appear on the screen in order + of their indices, i.e. column 0 appears first, then column 1 next, + and so on. However this can be changed by using the SetColumnsOrder() function + to arbitrarily reorder the columns visual order. + + The user can also rearrange the columns interactively by dragging them. + In this case, the index of the column is not the same as its order and + the functions GetColumnOrder() and GetColumnIndexFromOrder() should be + used to translate between them. + + @note All the other functions still work with the column indices, + i.e. the visual positioning of the columns on screen doesn't affect the + code setting or getting their values for example. + + Example of reordering columns: + @code + wxListCtrl *list = new wxListCtrl(...); + for ( int i = 0; i < 3; i++ ) + list->InsertColumn(i, wxString::Format("Column %d", i)); + + wxArrayInt order(3); + order[0] = 2; + order[1] = 0; + order[2] = 1; + list->SetColumnsOrder(order); + + // now list->GetColumnsOrder() will return order and + // list->GetColumnIndexFromOrder(n) will return order[n] and + // list->GetColumnOrder() will return 1, 2 and 0 for the column 0, + // 1 and 2 respectively + @endcode + @beginStyleTable @style{wxLC_LIST} @@ -538,8 +572,10 @@ public: corresponds to the value of the element number @a pos in the array returned by GetColumnsOrder(). - Please see SetColumnsOrder() documentation for an example and - additional remarks about the columns ordering. + @note This function makes sense for report view only and currently is only + implemented in the wxMSW port. Use @c wxHAS_LISTCTRL_COLUMN_ORDER to guard uses + of this function so that they will start working under the other platforms when + support for the column reordering is added there. @see GetColumnOrder() */ @@ -552,8 +588,10 @@ public: given visual position, e.g. calling it with @a col equal to 0 returns the index of the first shown column. - Please see SetColumnsOrder() documentation for an example and - additional remarks about the columns ordering. + @note This function makes sense for report view only and currently is only + implemented in the wxMSW port. Use @c wxHAS_LISTCTRL_COLUMN_ORDER to guard uses + of this function so that they will start working under the other platforms when + support for the column reordering is added there. @see GetColumnsOrder(), GetColumnIndexFromOrder() */ @@ -569,8 +607,10 @@ public: On error, an empty array is returned. - Please see SetColumnsOrder() documentation for an example and - additional remarks about the columns ordering. + @note This function makes sense for report view only and currently is only + implemented in the wxMSW port. Use @c wxHAS_LISTCTRL_COLUMN_ORDER to guard uses + of this function so that they will start working under the other platforms when + support for the column reordering is added there. @see GetColumnOrder(), GetColumnIndexFromOrder() */ @@ -1027,17 +1067,6 @@ public: /** Changes the order in which the columns are shown. - By default, the columns of a list control appear on the screen in order - of their indices, i.e. the column 0 appears first, the column 1 next - and so on. However by using this function it is possible to arbitrarily - reorder the columns visual order and the user can also rearrange the - columns interactively by dragging them. In this case, the index of the - column is not the same as its order and the functions GetColumnOrder() - and GetColumnIndexFromOrder() should be used to translate between them. - Notice that all the other functions still work with the column indices, - i.e. the visual positioning of the columns on screen doesn't affect the - code setting or getting their values for example. - The @a orders array must have the same number elements as the number of columns and contain each position exactly once. Its n-th element contains the index of the column to be shown in n-th position, so for a @@ -1045,28 +1074,9 @@ public: results in the third column being displayed first, the first one next and the second one last. - Example of using it: - @code - wxListCtrl *list = new wxListCtrl(...); - for ( int i = 0; i < 3; i++ ) - list->InsertColumn(i, wxString::Format("Column %d", i)); - - wxArrayInt order(3); - order[0] = 2; - order[1] = 0; - order[2] = 1; - list->SetColumnsOrder(order); - - // now list->GetColumnsOrder() will return order and - // list->GetColumnIndexFromOrder(n) will return order[n] and - // list->GetColumnOrder() will return 1, 2 and 0 for the column 0, - // 1 and 2 respectively - @endcode - - Please notice that this function makes sense for report view only and - currently is only implemented in wxMSW port. To avoid explicit tests - for @c __WXMSW__ in your code, please use @c wxHAS_LISTCTRL_COLUMN_ORDER - as this will allow it to start working under the other platforms when + @note This function makes sense for report view only and currently is only + implemented in the wxMSW port. Use @c wxHAS_LISTCTRL_COLUMN_ORDER to guard uses + of this function so that they will start working under the other platforms when support for the column reordering is added there. @see GetColumnsOrder() From f556a34086c3d9759d2c33955fb092ed41a4d42a Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sun, 18 Apr 2021 01:19:05 +0100 Subject: [PATCH 4/4] Remove the mentions of the native OSX wxListCtrl control This control was removed during the Carbon code removal in commit 5ba67c67e47d069f65d648ab16dfc505c5400bfc, so the system option does nothing now (and was only mentioned in the documentation and the sample). --- interface/wx/listctrl.h | 7 +++---- interface/wx/sysopt.h | 3 --- samples/listctrl/listtest.cpp | 18 +----------------- samples/listctrl/listtest.h | 6 ------ 4 files changed, 4 insertions(+), 30 deletions(-) diff --git a/interface/wx/listctrl.h b/interface/wx/listctrl.h index 93f09127ac..b0bba1a9a7 100644 --- a/interface/wx/listctrl.h +++ b/interface/wx/listctrl.h @@ -147,10 +147,9 @@ enum To intercept events from a list control, use the event table macros described in wxListEvent. - wxMac Note: Starting with wxWidgets 2.8, wxListCtrl uses a native - implementation for report mode, and uses a generic implementation for other - modes. You can use the generic implementation for report mode as well by setting - the @c mac.listctrl.always_use_generic system option (see wxSystemOptions) to 1. + @note The native wxOSX implementation for report mode that was added in wxWidgets + 2.8 was removed in wxWidgets 3.1, meaning for wxWidgets 3.1+ wxOSX uses the generic + implementation for all modes. @subsection column_order Column Ordering diff --git a/interface/wx/sysopt.h b/interface/wx/sysopt.h index 53d496544e..eb1845f5f7 100644 --- a/interface/wx/sysopt.h +++ b/interface/wx/sysopt.h @@ -105,9 +105,6 @@ @flag{window-default-variant} The default variant used by windows (cast to integer from the wxWindowVariant enum). Also known as wxWINDOW_DEFAULT_VARIANT. - @flag{mac.listctrl.always_use_generic} - Tells wxListCtrl to use the generic control even when it is capable of - using the native control instead. Also known as wxMAC_ALWAYS_USE_GENERIC_LISTCTRL. @flag{mac.textcontrol-use-spell-checker} If 1 activates the spell checking in wxTextCtrl. @flag{osx.openfiledialog.always-show-types} diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 92ae0a1926..f2615a01b9 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -150,9 +150,6 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(LIST_TOGGLE_HEADER, MyFrame::OnToggleHeader) EVT_MENU(LIST_TOGGLE_BELL, MyFrame::OnToggleBell) EVT_MENU(LIST_CHECKVISIBILITY, MyFrame::OnCheckVisibility) -#ifdef __WXOSX__ - EVT_MENU(LIST_MAC_USE_GENERIC, MyFrame::OnToggleMacUseGeneric) -#endif // __WXOSX__ EVT_MENU(LIST_FIND, MyFrame::OnFind) EVT_MENU(LIST_TOGGLE_CHECKBOX, MyFrame::OnToggleItemCheckBox) EVT_MENU(LIST_GET_CHECKBOX, MyFrame::OnGetItemCheckBox) @@ -229,10 +226,6 @@ MyFrame::MyFrame(const wxString& title) menuView->Append(LIST_SMALL_VIRTUAL_VIEW, "Small virtual vie&w\tF8"); menuView->AppendSeparator(); menuView->Append(LIST_SET_ITEMS_COUNT, "Set &number of items"); -#ifdef __WXOSX__ - menuView->AppendSeparator(); - menuView->AppendCheckItem(LIST_MAC_USE_GENERIC, "Mac: Use Generic Control"); -#endif wxMenu *menuList = new wxMenu; menuList->Append(LIST_GOTO, "&Go to item #3\tCtrl-3"); @@ -391,15 +384,6 @@ void MyFrame::OnCheckVisibility(wxCommandEvent& WXUNUSED(event)) wxLogMessage( "Line 9 is not visible" ); } -#ifdef __WXOSX__ - -void MyFrame::OnToggleMacUseGeneric(wxCommandEvent& event) -{ - wxSystemOptions::SetOption("mac.listctrl.always_use_generic", event.IsChecked()); -} - -#endif // __WXOSX__ - void MyFrame::OnGoTo(wxCommandEvent& WXUNUSED(event)) { if ( m_listCtrl->IsEmpty() ) @@ -433,7 +417,7 @@ void MyFrame::OnFocusLast(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event)) { if ( !m_listCtrl->IsEmpty() ) - { + { m_listCtrl->SetItemState(0, (~m_listCtrl->GetItemState(0, wxLIST_STATE_SELECTED) ) & wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); } else diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h index c40ee918ca..04410ecbf1 100644 --- a/samples/listctrl/listtest.h +++ b/samples/listctrl/listtest.h @@ -148,9 +148,6 @@ protected: void OnToggleLines(wxCommandEvent& event); void OnToggleHeader(wxCommandEvent& event); void OnToggleBell(wxCommandEvent& event); -#ifdef __WXOSX__ - void OnToggleMacUseGeneric(wxCommandEvent& event); -#endif // __WXOSX__ void OnFind(wxCommandEvent& event); void OnToggleItemCheckBox(wxCommandEvent& event); void OnGetItemCheckBox(wxCommandEvent& event); @@ -245,9 +242,6 @@ enum LIST_FREEZE, LIST_THAW, LIST_TOGGLE_LINES, -#ifdef __WXOSX__ - LIST_MAC_USE_GENERIC, -#endif LIST_CHECKVISIBILITY, LIST_CTRL = 1000 };