A generic multi-select wxListCtrl did not deselect a single selected
item that did not have focus when the user single-selected another
item.
This fixes a regression introduced in fedc80eee3 (Improve selection and
focus events generation in wxGenericLisCtrl, 2020-10-10).
Closes#24312.
Don't reset the selection in a generic multi-selection wxListCtrl while
Ctrl or Shift key is pressed to be consistent with wxMSW behaviour.
This commit is best viewed ignoring whitespace-only changes.
Closes#24332.
The list control needs to be updated after the user has edited an item
label because, for example, in icon view the column width and positions
of subsequent columns may change if the edited label is or was wider
than the icons and other labels in the column.
Closes#24311.
Changing the selection could behave wrongly and result in an assert
failure as the selection anchor could have become invalid, due to the
change of the number of items in the control.
Fix this by invalidating it when this happens.
The check for the line being deleted being in the visible range
prevented us from refreshing anything at all if the line which was just
deleted was the last line of the control.
This didn't update the number of selected items, which resulted in other
problems later on, including accessing items with invalid index which
could lead to a crash.
Closes#23729.
This could be a noticeable optimization as it should be much more
efficient to store many lines in a single block of memory instead of
using pointers to them and it also simplifies the code as we don't need
to delete the pointers any more.
Don't manage the pointer lifetime manually but use a smart pointer for
it: this is simpler and allows to make this class default-movable.
Also make it non-copyable as it never actually was (copying it would
have resulted in a double free of the owned pointer).
This simplifies the code and avoids unnecessary heap allocations as we
can store the objects in the vectors directly instead of storing
pointers to them.
This class contains (sometimes) owned pointers and so can't be copied
but it can be moved, so make it moveable.
No real changes, this is done in preparation for storing objects of this
type in a std::vector.
Get rid of Init() function and just initialize all the members in their
declarations, as this is less verbose, more clear and more robust.
Note that we also initialize m_rect now, which was left uninitialized by
Init() before, as it's simpler and more reliable to always do even if we
happen to overwrite it in the ctor.
This not only simplifies the code but also makes it more efficient by
avoiding unnecessary heap allocations, as we can now just store the
objects themselves in the vector instead of storing pointers to them.
No real changes, this is just a code cleanup/modernization.
For some reason, the margin was only used in wxGTK ever since it was
added back in ccdbdc8936 (Added native selection rectangle drawing.,
2006-11-11) even though it came with a comment saying that this
should be done for all platforms.
Finally do this now to make the list look better under e.g. macOS.
Closes#23155.
Since wxListCtrl under wxMSW cannot edit labels without the presence of
this flag, and an assertion failure triggered if the flag is missing to
it and also all the other ports for consistency.
Also document that wxLC_EDIT_LABELS flag is required in EditLabel()
description.
See #23024.
Ensure the edit control is created before sending wxEVT_LIST_BEGIN_LABEL_EDIT
event, as calling wxListCtrl::GetEditControl() from inside the handler should
always return a valid pointer
Closes#23024.
Add a helper function calling wxDC::DrawBitmap() and hiding its ugly
"useMask" boolean parameter which was also error-prone, e.g. some
recently modified code passed wxIMAGELIST_DRAW_TRANSPARENT to it by
mistake.
No real changes, this is just a refactoring.
After the changes of the last commit this variable is not of wxImageList
type any more, so its name became confusing, so rename it and also be a
bit more precise by indicating that it corresponds to the small, and not
normal, images.
No real changes.
Use wxWithImages::GetImageBitmapFor() instead of wxImageList in this
control code to ensure that we use the provided high DPI bitmaps, if we
have them, instead of always scaling up the fixed-size image list
images.
Closes#22907.
This is a combination of running clang-tidy with modernize-use-nullptr
check for some ports (GTK, X11, OSX) and manual changes to the ports for
which it couldn't be used easily (MSW, DFB) and also manually updating
the docs.
Also replace NULL with null or nullptr in the comments as this is more
consistent with the use of nullptr in the code and makes it simpler to
grep for the remaining occurrences of NULL itself.
And also use null in the assert messages.
Only a few occurrences of "NULL" are still left in non-C files, mostly
corresponding to unclear comments or string output which it might not be
safe to change.
The control still needs to be repainted after calling
RecalculatePositions(), so don't reset the dirty flag in it and do it
only in RecalculatePositionsAndRefresh() instead.
Arguably, EnsureVisible() should call the latter function itself, but
don't change this for now and just correct the regression caused by the
changes of d8fe06891e (Avoid bool argument in wxListMainWindow::
RecalculatePositions(), 2021-08-06).
Closes#22511.
Destroy wxGenericListCtrl children earlier, so that this happens while
this object is still a wxListCtrl and not just a wxWindow, to fix an
assert triggered by the changes of 3eee299cd3 (Micro optimization in
wxListMainWindow::SendNotify(), 2022-06-08).
Check that it consistently returns 0 in the wxLC_ICON and
wxLC_SMALL_ICON modes under all platforms.
Document the behaviour of this function in all modes.
The old API seems unnecessarily complex, it is simpler to just let the
application call ShowSortIndicator() itself from its
wxEVT_LIST_COL_CLICK handler, which needs to be defined anyhow in order
to actually sort the items, rather than require it to enable sort
indicator, explicitly set it initially and then remember to not set it
any longer in response to the column clicks.
Also make RemoveSortIndicator() non-virtual and implement it simply as
ShowSortIndicator(-1) because this actually simplifies the code too.
It doesn't seem right for ShowSortIndicator() to silently do nothing if
EnableSortIndicator() hadn't been called before, so make it enable the
sort indicators if they hadn't been enabled yet.
The alternative would be to assert in this function, but this seems less
useful.
Also add some comments to wxMSW version.
Don't do anything at all if nothing changes and if the indicator does
change, refresh only the header window and not the whole list control,
which seems unnecessary.
Don't use "const int" or "const bool" for parameter types, the "const"
here is ignored and using it is inconsistent with all the rest of the
library.
No real changes.
There doesn't seem to be any reason to not show sort indicators in the
columns of virtual list controls, so simply remove the test for
IsVirtual() in DrawSortArrow().
This allows d8ec0aa001 (Support sort indicators in wxListCtrl header,
2021-11-28) to work for wxListCtrl with wxLC_VIRTUAL too.
Put the code common to all wxListCtrl implementations in the common base
class instead of duplicating it in wxMSW, wxQt and generic versions.
No real changes yet, this is a pure refactoring which prepares for the
upcoming changes.
Don't set default width every time the column is updated, as it happens
e.g. when it's clicked by the user, but only when it is created, by
moving the code added in 96d36383bd (Use sensible default column width
in generic wxListCtrl too, 2021-08-17) from SetItem() to the ctor of
wxListHeaderData.
Closes#19256.
Sub-item hit testing is still not implemented, but at least initialize
the output parameter to the documented value instead of leaving some
junk in it.
Right clicking item always selected it, which made it possible to have
multiple selected items even in a single-selection control.
Restore HighlightAll(false) erroneously removed by fedc80eee3 (Improve
selection and focus events generation in wxGenericLisCtrl, 2020-09-06)
to fix this and restore the correct old behaviour.
Note that even in multiple selection mode right clicking a previously
unselected item should still clear the selection, as it does it in the
other GTK programs (and also under MSW).