Commit graph

701 commits

Author SHA1 Message Date
taler21
d091a44adb Fix missing deselection of single selected but not focused item
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.
2024-02-19 13:58:51 +01:00
taler21
85b04c1c24 Don't reset selection while Ctrl or Shift key is pressed
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.
2024-02-16 14:01:31 +01:00
taler21
716bf59449 Ensure full label is shown after editing it in generic wxListCtrl
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.
2024-02-13 21:17:07 +01:00
Vadim Zeitlin
82cb7d1074 Merge branch 'generic-listctrl-center-label'
Fix centering of item label in generic wxListCtrl

See #2340, #24292.
2024-02-09 18:36:53 +01:00
taler21
e7dba90bd0 Make auto-grow of in-place editor in generic wxListCtrl work again
Auto-growing of the editor has not worked since the changes of
a8a8915453 (Made code more similar to
wxTreeCtrl' code, 2008-01-10).

Closes #24293.
2024-02-09 17:30:21 +01:00
taler21
82b5f85418 Fix centering of item label in generic wxListCtrl
The item label was not centered if the icon is wider than the label.
2024-02-08 08:44:20 +01:00
Vadim Zeitlin
857fa3670e Make checks for m_findBell slightly more readable
Make it clear that we only need to set it to 1 if it had been set to -1
before.

No real changes.
2023-11-07 19:05:10 +01:00
Vadim Zeitlin
163d310369 Use wxTimer::StartOnce() instead of wxTIMER_ONE_SHOT
This is more readable and shorter, so encourage using this form.

No real changes.
2023-11-07 19:01:38 +01:00
Vadim Zeitlin
5885eea5ea Fix refreshing wxGenericListCtrl with multiple selection
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.
2023-10-22 01:06:38 +02:00
Vadim Zeitlin
8d036af816 Fix not refreshing generic wxListCtrl after deleting last item
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.
2023-10-06 18:17:15 +02:00
Maarten Bent
1b8f498685
Ignore wxListCtrl CheckItem/IsItemChecked when checkboxes are disabled 2023-09-30 17:43:37 +02:00
Maarten Bent
fa26c8724d
Don't use internal check state for generic virtual wxListCtrl
Just like the MSW virtual wxListCtrl, the checkbox state is determined by OnGetItemIsChecked.

See #23869
2023-09-30 17:32:54 +02:00
Scott Talbert
3ae3a4e1f5
Support using Numpad Enter for ending wxListCtrl editing (#23762)
Fixes #23761.
2023-08-12 16:04:26 -07:00
Vadim Zeitlin
d6dd0ebb6e Fix deleting selected item in wxGenericListCtrl
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.
2023-07-24 14:03:34 +02:00
Vadim Zeitlin
b6937799e6 Store wxListLineData objects, not pointers, in the vector
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.
2023-01-19 02:11:43 +01:00
Vadim Zeitlin
93da9ff74e Use std::unique_ptr<> in wxListLineData and make it movable
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).
2023-01-19 02:11:43 +01:00
Vadim Zeitlin
f62047f867 Replace wxList classes used in wxGenericListCtrl with vectors
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.
2023-01-19 02:11:43 +01:00
Vadim Zeitlin
a5777cdcbd Make wxListItemData movable and not copyable
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.
2023-01-19 02:11:43 +01:00
Vadim Zeitlin
f547bf0647 Replace wxListItemData::Init() with member initialization
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.
2023-01-19 02:11:43 +01:00
Vadim Zeitlin
53188d30f0 Make wxListHeaderData::GetItem() const
Because there is no reason for it not to be it.
2023-01-19 00:27:24 +00:00
Vadim Zeitlin
b7e7d506c5 Use std::vector instead of wx array in wxGenericListCtrl code
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.
2023-01-18 23:56:55 +00:00
Vadim Zeitlin
b6071fc6c6 Use margins around the text in wxGenericListCtrl on all platforms
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.
2023-01-18 23:42:56 +00:00
ali kettab
2578ffb54a Assert if wxListCtrl::EditLabel() is used without wxLC_EDIT_LABELS
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.
2022-12-10 12:57:46 +01:00
ali kettab
f802b869fa Fix wxTextCtrl creation in wxGenericListCtrl::EditLabel()
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.
2022-12-10 12:55:10 +01:00
Vadim Zeitlin
c94399121f Don't duplicate same code for small icon, list and report modes
Handle all of them in a single condition instead of using three
different ones.

No real changes.
2022-10-25 23:48:25 +02:00
Vadim Zeitlin
6dd4e73ea3 Add wxDrawImageBitmap() helper and use it in wx{List,Tree}Ctrl
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.
2022-10-25 23:48:25 +02:00
Vadim Zeitlin
69648b4322 Rename variable to have a less confusing name
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.
2022-10-25 23:48:25 +02:00
Gerhard Stein
502e189f47 Support high DPI bitmaps in wxGenericListCtrl
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.
2022-10-25 23:48:25 +02:00
Vadim Zeitlin
4f4c5fcfdf Use nullptr instead of NULL in the code and documentation
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.
2022-10-18 01:25:25 +02:00
PB
88d526660f Replace wxOVERRIDE and wxNOEXCEPT with override and noexcept
Don't use deprecated macros in wxWidgets itself.
2022-10-15 18:10:45 +02:00
Vadim Zeitlin
b83178086d Use wxVector::shrink_to_fit() directly
Don't use deprecated wxShrinkToFit() as now wxVector always has this
member function because it is available even in STL build when using
C++11.
2022-10-11 00:02:29 +02:00
Lauri Nurmi
66916c74a3 Fix double negatives used with 'neither' in docs and comments
In many cases it should be 'either', and 'nor' should be 'or'
accordingly.

No changes to actual code.

Closes #22723.
2022-08-19 16:22:21 +02:00
taler21
1a5bb42407 Fix refresh after calling generic wxListCtrl::EnsureVisible()
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.
2022-06-11 17:46:14 +02:00
Vadim Zeitlin
1614d97bb8 Fix assert failure in SendNotify()
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).
2022-06-08 16:51:32 +02:00
Vadim Zeitlin
9547cbc6a4 Extend wxListCtrl::GetColumnCount() tests to all modes
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.
2022-06-08 13:52:53 +01:00
Vadim Zeitlin
3eee299cd3 Micro optimization in wxListMainWindow::SendNotify()
Just call GetListCtrl() once instead of calling both it and GetParent()
multiple times.

No real changes.
2022-06-08 13:36:47 +01:00
Kvaz1r
dbd0bb70bb
Fix GetColumnCount for wxLC_LIST style 2022-06-07 12:53:33 +03:00
Vadim Zeitlin
52649cc566 Remove wxListCtrl::EnableSortIndicator()
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.
2021-12-14 14:09:23 +00:00
Vadim Zeitlin
30ce892ed5 Let wxListCtrl::ShowSortIndicator() implicitly enable indicators
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.
2021-12-13 14:31:49 +00:00
Vadim Zeitlin
c287840faa Optimize changing sort indicator in wxGenericListCtrl
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.
2021-12-13 14:29:59 +00:00
Vadim Zeitlin
58290168e5 Remove top level "const" from {Enable,Show}SortIndicator()
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.
2021-12-13 14:18:18 +00:00
Vadim Zeitlin
dbe8e30b56 Allow using column sort indicators in virtual wxListCtrl too
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.
2021-12-13 14:15:25 +00:00
Maarten Bent
d8ec0aa001 Support sort indicators in wxListCtrl header 2021-12-09 17:32:05 +01:00
Vadim Zeitlin
aca0c74e60 Add wxListCtrl::Set{Normal,Small}Images()
These new functions allow to use wxBitmapBundle for the images in this
control instead of wxImageList.

Update the sample to use the new API.
2021-11-11 01:20:35 +00:00
Vadim Zeitlin
5941dea234 Move wxImageList-related code to wxListCtrlBase
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.
2021-11-11 00:52:12 +00:00
Vadim Zeitlin
d89af4e311 Fix regression with spurious generic wxListCtrl columns resizing
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.
2021-09-07 19:44:02 +02:00
Vadim Zeitlin
98c2eef619 Fix scrollbar position in wxListCtrl in wxUniv
Skip the event in wxGenericListCtrl::OnSize() to let wxUniv position the
window scrollbars correctly.

See https://github.com/wxWidgets/wxWidgets/pull/2512

Closes #19254.
2021-09-05 17:36:57 +02:00
AliKet
cb6d67bab4 Reset selection on right click in a more efficient way
Instead of using HighlightAll(), use the second argument of
HighlightOnly() to remove selection from the previous current item.
2021-08-23 01:59:07 +02:00
Vadim Zeitlin
0e9e6aaf3a Set "subitem" argument of HitTest() to -1 in generic wxListCtrl
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.
2021-08-23 00:24:24 +02:00
Vadim Zeitlin
14511a8bec Fix selection on right click in generic wxListCtrl
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).
2021-08-23 00:16:32 +02:00