Improve consistency of checkboxes in wxListCtrl (PR #23890)

39 views
Skip to first unread message

Maarten

unread,
Sep 21, 2023, 9:57:57 AM9/21/23
to wx-...@googlegroups.com, Subscribed

Improve consistency of checkboxes in wxListCtrl between virtual and report mode, and between the generic and MSW implementation, see #23869.

Also disable WS_EX_COMPOSITED for virtual wxListCtrl because it generates an endless stream of cache events, see #23878.


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/23890

Commit Summary

  • b29927f Generate wxEVT_LIST_ITEM_[UN]CHECKED events for MSW virtual wxListCtrl
  • 4908c77 Support using IsItemChecked in MSW virtual wxListCtrl
  • e054aef Don't use internal check state for generic virtual wxListCtrl
  • 41adea8 Ignore wxListCtrl CheckItem/IsItemChecked when checkboxes are disabled
  • 00657ed Update listctrl example to recent wxListCtrl checkbox changes
  • 3d43876 Disable WS_EX_COMPOSITED for virtual wxListCtrl
  • ee36b32 Update documentation of wxListCtrl IsItemChecked and CheckItem

File Changes

(6 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890@github.com>

Maarten

unread,
Sep 21, 2023, 10:24:00 AM9/21/23
to wx-...@googlegroups.com, Subscribed

This could also be backported to 3.2.

Not sure if the change to include/wx/generic/private/listctrl.h will cause abi/api problems, but this change could be omitted. It is an precaution to prevent the internal checkbox state from being out-of-sync with the external state from OnGetItemIsChecked.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/c1729688839@github.com>

VZ

unread,
Sep 21, 2023, 5:10:38 PM9/21/23
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.

Thanks for the fixes!

I am not sure we can backport this to 3.2 as this changes the behaviour in not quite obvious way, but we should definitely apply this to master, I'd just like to clarify a couple of things before doing it.


In src/msw/listctrl.cpp:

> +    if ( !HasCheckBoxes() )
+        return;

Should this be a wxCHECK_RET() instead? I.e. isn't it a programmers error to call this if there are no checkboxes?


In src/msw/listctrl.cpp:

> @@ -257,6 +257,11 @@ bool wxListCtrl::Create(wxWindow *parent,
     if ( !MSWCreateControl(WC_LISTVIEW, wxEmptyString, pos, size) )
         return false;
 
+    // LISTVIEW generates and endless stream of LVN_ODCACHEHINT event for a
+    // virtual wxListCtrl, so disabled WS_EX_COMPOSITED.

Tiny nitpick, but you probably meant

⬇️ Suggested change
-    // virtual wxListCtrl, so disabled WS_EX_COMPOSITED.
+    // virtual wxListCtrl, so disable WS_EX_COMPOSITED.

In src/msw/listctrl.cpp:

> +    if ( !HasCheckBoxes() )
+        return false;

Same question as above.


In src/generic/listctrl.cpp:

> +#if defined(__WXMSW__)
+    // LISTVIEW generates and endless stream of LVN_ODCACHEHINT event for a
+    // virtual wxListCtrl, so disabled WS_EX_COMPOSITED.
+    if ( IsVirtual() )
+        MSWDisableComposited();
+#endif
+

Sorry, I don't understand this: we're not using the native control here, why do we need this?


In src/msw/listctrl.cpp:

> @@ -1494,12 +1499,31 @@ bool wxListCtrl::EnableCheckBoxes(bool enable)
 
 void wxListCtrl::CheckItem(long item, bool state)
 {
-    ListView_SetCheckState(GetHwnd(), (UINT)item, (BOOL)state);
+    if ( !HasCheckBoxes() )
+        return;
+
+    if ( IsVirtual() )
+    {
+        wxListEvent le(state ? wxEVT_LIST_ITEM_CHECKED : wxEVT_LIST_ITEM_UNCHECKED, GetId());

I'd probably add a comment saying that ListView_SetCheckState() generates the same event that we have to generate ourselves here because we can't call it for the virtual controls.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/review/1638704231@github.com>

VZ

unread,
Sep 30, 2023, 9:10:21 AM9/30/23
to wx-...@googlegroups.com, Subscribed

Maarten, should I make the changes indicated above myself and merge this or will you make them yourself or do you think they shouldn't be done at all?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/c1741763552@github.com>

Maarten

unread,
Sep 30, 2023, 9:14:47 AM9/30/23
to wx-...@googlegroups.com, Subscribed

I will make the changes.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/c1741764356@github.com>

Maarten

unread,
Sep 30, 2023, 11:49:17 AM9/30/23
to wx-...@googlegroups.com, Subscribed

@MaartenBent commented on this pull request.


In src/msw/listctrl.cpp:

> +    if ( !HasCheckBoxes() )
+        return;

Yes, I added it.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/review/1651712904@github.com>

Maarten

unread,
Sep 30, 2023, 11:51:08 AM9/30/23
to wx-...@googlegroups.com, Subscribed

@MaartenBent commented on this pull request.


In src/generic/listctrl.cpp:

> +#if defined(__WXMSW__)
+    // LISTVIEW generates and endless stream of LVN_ODCACHEHINT event for a
+    // virtual wxListCtrl, so disabled WS_EX_COMPOSITED.
+    if ( IsVirtual() )
+        MSWDisableComposited();
+#endif
+

I was testing the generic implementation on Windows, then it is needed. But normally this isn't possible so this code is indeed not needed.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/review/1651713182@github.com>

Maarten

unread,
Sep 30, 2023, 11:53:19 AM9/30/23
to wx-...@googlegroups.com, Push

@MaartenBent pushed 7 commits.

  • 07df143 Generate wxEVT_LIST_ITEM_[UN]CHECKED events for MSW virtual wxListCtrl
  • eca7ec0 Support using IsItemChecked in MSW virtual wxListCtrl
  • fa26c87 Don't use internal check state for generic virtual wxListCtrl
  • 1b8f498 Ignore wxListCtrl CheckItem/IsItemChecked when checkboxes are disabled
  • abdbe66 Update listctrl example to recent wxListCtrl checkbox changes
  • 3987323 Disable WS_EX_COMPOSITED for virtual wxListCtrl
  • f68bb39 Update documentation of wxListCtrl IsItemChecked and CheckItem


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/push/15241521084@github.com>

Maarten

unread,
Sep 30, 2023, 11:56:59 AM9/30/23
to wx-...@googlegroups.com, Subscribed

@MaartenBent commented on this pull request.


In src/msw/listctrl.cpp:

> +    if ( !HasCheckBoxes() )
+        return false;

Not sure about this one. Sometimes it is easier to just call IsItemChecked() even if checkboxes are disabled. Like I do now in the code below. This would have to be changed to HasCheckBoxes() && IsItemChecked(line).

https://github.com/wxWidgets/wxWidgets/blob/f68bb391ce844ac1805394719758fb7b101aadb7/src/generic/listctrl.cpp#L2095-L2100


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/review/1651714162@github.com>

VZ

unread,
Sep 30, 2023, 1:23:58 PM9/30/23
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.


In src/msw/listctrl.cpp:

> +    if ( !HasCheckBoxes() )
+        return false;

OK, thanks, let's leave it like this, but I'll add a note about this (not necessarily obvious) behaviour to the docs.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/review/1651727649@github.com>

VZ

unread,
Sep 30, 2023, 1:27:28 PM9/30/23
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.


In src/msw/listctrl.cpp:

> +    if ( !HasCheckBoxes() )
+        return false;

Oops, actually this is already documented, sorry for not realizing this.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/review/1651728006@github.com>

VZ

unread,
Sep 30, 2023, 1:28:14 PM9/30/23
to wx-...@googlegroups.com, Subscribed

I'm going to merge this to master soon but I think it should also be backported to 3.2.

Am I correct in thinking that everything but 3987323 should be safe to backport?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/c1741819556@github.com>

Maarten

unread,
Sep 30, 2023, 1:39:31 PM9/30/23
to wx-...@googlegroups.com, Subscribed

Yes, I think so.
I was questioning earlier if the changes to include/wx/generic/private/listctrl.h would cause abi/api problems. But wxListLineData is not exported, so it should be fine.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/c1741821833@github.com>

VZ

unread,
Sep 30, 2023, 5:15:08 PM9/30/23
to wx-...@googlegroups.com, Subscribed

Merged #23890 into master.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23890/issue_event/10518013723@github.com>

Reply all
Reply to author
Forward
0 new messages