Commit Graph

603 Commits

Author SHA1 Message Date
Vadim Zeitlin
4073f3b9bf Use wxBitmapBundle in wxDataViewCtrl-related classes
Extend the existing use of wxIcon in wxDataViewIconText,
wxDataViewCheckIconText, the corresponding renderers and
wxDataViewTreeCtrl to wxBitmapBundle.

As with the other classes, the existing setters have been preserved as
they remain almost entirely compatible with the existing code and the
return type of the existing getters was preserved, with new getters
being introduced for returning wxBitmapBundle only where they're really
required.

Update the sample to use wxBitmapBundle with its wxDataViewTreeCtrl.
2022-01-23 21:55:30 +01:00
Vadim Zeitlin
e6addf1128 Take DPI scaling into account for wxDataViewCtrl scroll rate
Use FromDIP() to make scrolling work visually the same in high DPI as in
normal one.
2022-01-23 17:29:43 +01:00
Vadim Zeitlin
906808b8e5 Fix wxDataViewCtrl default row height in high DPI
Use FromDIP() to ensure that it is not too small when using DPI scaling.

Also make the code slightly more clear by using a meaningful variable
name instead of a (duplicated) comment.
2022-01-23 17:29:43 +01:00
Vadim Zeitlin
1a1c02804b Add more FromDIP() calls to generic wxDataViewCtrl renderers
Some of them had been already updated to return the values scaled
appropriately for the current DPI in 56fab0aabb (Improve wxDataView on
DPI change, 2019-01-10), but not all, so add the missing calls to
wxDataView{Progress,IconText}Renderer too.
2022-01-23 17:29:43 +01:00
Vadim Zeitlin
7e3059dee0 Merge branch 'dvc-multi-format-dnd'
Accept multiple data formats via drag-and-drop in wxDataViewCtrl.

See #2478, #2616.
2022-01-15 23:39:03 +01:00
Maarten Bent
e2d34e982e Skip all wxDPIChangedEvent
So base classes will process the event too.
This is need for (at least) wxGenericColourButton It has its own handler,
but also needs to handle the DPI event in wxButtonImageData.
2022-01-05 22:47:32 +01:00
Paul Cornett
1be048fc53 Make sure there is a current row before comparing its position 2021-12-30 17:11:51 -08:00
Paul Cornett
1700f62fd4 Don't take focus into account when setting selected state for cell text
The selected state is always set for the background of a selected cell,
so it should also be set for the text/foreground. Fixes text color for
unfocused selected cells with Windows high-contrast themes.
2021-12-28 23:20:05 -08:00
Paul Cornett
3611a41e07 Set position for wxEVT_DATAVIEW_ITEM_CONTEXT_MENU with generic wxDataViewCtrl
See #19188
2021-12-22 17:24:06 -08:00
Vadim Zeitlin
7797ffc730 Add wxDataViewEvent::InitData() helper
Reuse it from both the generic and macOS versions to avoid doing the
same thing in both of them.
2021-12-10 20:42:18 +01:00
Vadim Zeitlin
31bdfd6523 Make CreateDataObject() return wxDataObjectComposite
This function must return a composite data object and not just any
wxDataObject because its callers cast the returned object to this class,
so make it a bit more type-safe.
2021-12-10 20:06:30 +01:00
Vadim Zeitlin
cd555f9ff5 Use vector instead of array of wxDataFormats
Also rename EnableDropTarget() to EnableDropTargets(), as calling
EnableDropTarget(wxDF_XXX) would be ambiguous due to the existence of a
non-explicit wxVector ctor taking size_t (which is a mistake on its own,
but is probably not worth changing any more).
2021-12-10 19:57:41 +01:00
valid-ptr
7129d2b11c Accept multiple data formats via drag-and-drop in wxDataViewCtrl
Allow specifying multiple formats to be accepted when dragging data to
wxDataViewCtrl in the generic and Cocoa implementations.

Add wxDataViewCtrlBase::EnableDropTarget() overload taking an array of
wxDataFormats to support this at the API level.

Add new DoEnableDropTarget() used by both EnableDropTarget() overloads
and implement it in the generic and Cocoa ports. GTK implementation
still uses only a single format, as before.

Also refactor the Cocoa implementation: all operations using dragged
data are now handled by wxDropTarget and unnecessary DataViewPboardType
as removed.

Update the dataview sample to show the new functionality.
2021-12-10 19:55:44 +01:00
Vadim Zeitlin
55420130b5 Don't use items without values in generic wxDVC
In particular, don't draw them, as this would reuse the value of the
previously drawn item, which would be wrong -- just leave them blank if
PrepareForItem() returned false, which happens if GetValue() returned a
null value or a value of a wrong type.
2021-12-01 01:43:52 +00:00
Vadim Zeitlin
3787f55a6b Add wxDPIChangedEvent::Scale() and use it in this event handlers
This is more concise and less error-prone than multiplying/dividing DPI
values manually.

No real changes except, maybe, in wxSlider code where the rounding was
done differently before for some reason.
2021-07-13 23:05:16 +01:00
Andreas Falkenhahn
527bcb246b Fix item position in sorted generic wxDataViewCtrl
Compare the item whose value has changed with both the previous and the
next items, if any.

Closes #19194.
2021-06-11 00:16:12 +02:00
Vadim Zeitlin
3ed930c736 Use wxCompositeWindow for generic wxDataViewCtrl implementation
This makes several methods that didn't have any effect before work
correctly, including SetToolTip(), whose effect is now shown in the
sample, but also SetCursor() and SetLayoutDirection().

Some methods would now actually work too well: SetForegroundColour() and
SetBackgroundColour() implementations in wxCompositeWindow apply to all
sub-windows, but in wxDataViewCtrl they are only supposed to affect the
items, but not the header, so we need to override them to prevent the
base class version from being used. It is still preferable to explicitly
disable these two methods and inherit all the other ones (including any
possibly added in the future) from wxCompositeWindow to implementing all
the methods manually in wxDataViewCtrl itself.
2021-05-24 14:24:24 +01:00
Vadim Zeitlin
bbd0c52440 Fix Left/Right arrows in multi-selection generic wxDataViewCtrl
They didn't reset the existing selection when used without Shift and
didn't extend the selection when used with Shift.

Fix both of these problems by reusing the existing logic from
GoToRelativeRow() and, added in this commit, GoToRow() which was
extracted from GoToRelativeRow().

Closes #19068.
2021-02-01 17:28:34 +01:00
Vadim Zeitlin
dbfa1c206e Rename and better document OnVerticalNavigation() helper function
This is not an event handler itself, so it shouldn't use "On" prefix
which is reserved, by convention, for the event handlers.

It also doesn't need wxKeyEvent, but just wxKeyboardState, so change its
signature accordingly. This will notably allow to use it from mouse
event handlers too if necessary.

No real changes.
2021-02-01 17:28:34 +01:00
Jorge Moraleda
ca9fa09fd8 Fix drawing expander column without values in generic wxDVC
When an item is marked as not containing any value in the expander
column, we must still draw the expander button if it has children, so
skip only drawing the item value in this case (and also preparing it for
drawing it, as calling PrepareForItem() would trigger an assert failure
for the items without value), but still execute the rest of the drawing
code for it, including drawing the background and expander button.

Closes https://github.com/wxWidgets/wxWidgets/pull/2144
2020-12-30 14:47:01 +01:00
Jorge Moraleda
ce4d95eac0 Fix not resorting generic wxDVC when model sort order changes
We can't skip resorting wxDataViewCtrl contents when the sort order is
defined by the model class, as it can change at any moment, so restrict
this optimization to the cases when we're sorting by the value of some
column.

Closes https://github.com/wxWidgets/wxWidgets/pull/2153
2020-12-29 17:23:18 +01:00
Jorge Moraleda
9640f0027f Fix assert when computing best column width in generic wxDVC
Do not invoke a renderer's PrepareForItem when estimating best column
width in generic wxDVC for items with no value because PrepareForItem
fails for items with no value when the null variant cannot be converted
to the expected type.

Closes https://github.com/wxWidgets/wxWidgets/pull/2149
2020-12-29 16:47:54 +01:00
Vadim Zeitlin
a53e69beb0 Allow expanding/collapsing items from keyboard in generic wxDVC
Add the usual handlers for '-', '+' and '*' keys. The last one is
especially convenient, as it does something that couldn't be easily done
at all interactively before.
2020-12-05 16:37:13 +01:00
Vadim Zeitlin
d47fa718cd Add wxDataViewCtrl::ExpandChildren()
This convenient method allows to expand all children of the item
recursively.

This is directly supported by both native implementations, so it makes
sense to have this in wxDataViewCtrl itself, even if it could be also
(less efficiently) implemented in the user code.
2020-12-05 16:37:13 +01:00
Vadim Zeitlin
faffc5fe0a Only invalidate row height cache when a row is really expanded
It's wasteful to do it if it's already expanded or won't be expanded
because the EXPANDING event is vetoed.
2020-12-05 16:36:12 +01:00
Vadim Zeitlin
931b472342 Add items to generic wxDataViewCtrl immediately in ItemAdded()
This reverts the changes of 4dc78a33e0 (Fix adding items to a never
opened branch of generic wxDataViewCtrl, 2018-01-17) which was supposed
to fix a problem which doesn't seem to be reproducible any longer (and,
unfortunately, wasn't recorded in the commit message back then), but
introduced another problem instead: postponing adding the node to the
tree didn't work correctly in case of depth-first model traversal in the
user code calling ItemAdded() for all the items, as in this case the
next call to ItemAdded() for a child of the item that wasn't added to
the tree because its parent hadn't been opened yet, would result in
adding this item and all its siblings to the tree when FindNode(parent)
would be called. And this, in turn, would result in the siblings of this
item being added to the tree twice.

Adding a test reproducing this problem is difficult, as we don't have
any way to check the internal state of wxDataViewMainWindow from the
outside, so this commit still doesn't do this, unfortunately.

Closes #18405.
2020-10-19 13:14:50 +02:00
Vadim Zeitlin
c24dddc462 Return empty rectangle from GetItemRect() for collapsed items
GetItemByRow() returned a valid row even for an item which was collapsed
which is clearly inappropriate for its use in GetItemRect(), which is
supposed return an invalid rectangle if the item is not visible. It also
might be inappropriate in other cases, but this is not totally clear and
it seems like it is supposed to return a valid row even for collapsed
items at least sometimes, so just make its behaviour conditional by
adding a new flags parameter to GetItemRect() and to Walker() helper
used by it itself, so that it could skip over collapsed items.

Update the test to show that it succeeds now even when the item is
present in the tree, as it only passed before because the item had never
been expanded at all, and so wasn't really present in the tree
structure and the updated test would have failed without the changes to
the code in this commit.
2020-10-19 01:31:14 +02:00
Vadim Zeitlin
6efdb3b337 Put generic wxDataViewCtrl helpers in an anonymous namespace
No real changes, just don't pollute the global namespace unnecessarily.
2020-10-19 01:24:55 +02:00
PB
f57f214122 Remove BCC-specific hdrstop pragma from everywhere 2020-10-12 21:58:37 +02:00
Vadim Zeitlin
90783fec05 Merge branch 'generic-dvc-improve-dnd'
Improve drag-and-drop in generic wxDataViewCtrl.

See https://github.com/wxWidgets/wxWidgets/pull/1836
2020-06-07 17:22:05 +02:00
Vadim Zeitlin
3dd91d24c2 Slightly simplify proposed drop index determination
No real changes, just reorganize the code in a way that should hopefully
be more clear to understand.
2020-05-25 01:52:32 +02:00
Vadim Zeitlin
60e0e9a8fc Make RefreshDropHint() code slightly shorter and simpler
Use an alias instead of typing the same long m_dropItemInfo.m_row
multiple times.

Remove unnecessary use of std::max().
2020-05-25 01:52:32 +02:00
Vadim Zeitlin
155e2beafd Use symbolic constant instead of hardcoded 15/85%
It's still hardcoded, but now it has a name, which explains what it is
and can be searched for.

No real changes.
2020-05-25 01:52:32 +02:00
Vadim Zeitlin
6a084e799e Merge branch 'dvc-colsize-vert-scroll'
Fix issues with generic wxDVC last column size when using
wxPersistentDVC.

See https://github.com/wxWidgets/wxWidgets/pull/1832
2020-05-06 18:44:28 +02:00
Vadim Zeitlin
013cacee4d Don't use unsigned variables for pixel values
This is not a good idea because we really don't want them to wrap around
and it also provokes signed/unsigned comparison warnings when using
them.

Also make this variable and the other related one const.
2020-05-03 21:10:03 +02:00
Konstantin S. Matveyev
403a8ed115 Improve drag-and-drop support in generic wxDataViewCtrl
Set the proposed drop index in wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE event
generated by the control to allow dropping either on or between the
items in the control, as it was already possible with the Mac version.

Closes https://github.com/wxWidgets/wxWidgets/pull/1822
2020-05-03 21:10:04 +02:00
Konstantin S. Matveyev
bcddfd6efb Don't start dragging invalid items in generic wxDataViewCtrl
It's not useful to allow dragging from the control area where there are
no items and it resulted in assert failures due to using an invalid row
in wxDataViewDropSource::GiveFeedback(), so simply don't do it at all.

Note that native GTK wxDataViewCtrl implementation doesn't do this
neither, so it also makes the behaviour more consistent.

Closes https://github.com/wxWidgets/wxWidgets/pull/1828
2020-05-02 20:06:49 +02:00
Vadim Zeitlin
aacd26c27b Save specified, not actual, col width in wxPersistentDataViewCtrl
This is more correct as saving the current width of the last column
would prevent the user from shrinking it under the last automatically
set size, i.e. the UI behaviour would change after restarting the
program, which shouldn't be the case.

Doing this required making WXGetManuallySetWidth(), which previously
existed in the generic version only, available in all ports, so do it
and also rename it to WXGetSpecifiedWidth() in the process, as this
seems a somewhat better name (it doesn't have to be manually specified,
i.e. it could also be done by the program itself or even implicitly by
wxPersistentDataViewCtrl).

Don't make this function public, at least for now, because it's not
clear how could it be useful and it might still need to be changed to
behave differently in the other ports.
2020-05-01 03:39:40 +02:00
Vadim Zeitlin
d74389f930 Fix WXGetManuallySetWidth() for columns using wxCOL_WIDTH_DEFAULT
Columns without any explicitly specified width still shouldn't be shrunk
down to 0 size by UpdateColumnSizes(), so handle them as if they were
created using wxDVC_DEFAULT_WIDTH instead -- which is what their actual
width is/would be.

This is a better fix than the one in 0c90ea40c3 (Don't auto-resize
wxDataViewCtrl columns below their initial size, 2019-10-03) and that
commit can be reverted now, as will be done soon.

See #18343.
2020-05-01 03:39:21 +02:00
Vadim Zeitlin
6c5f3f8929 Refactor generic wxDataViewColumn to use DoGetEffectiveWidth()
This function will be used for m_manuallySetWidth too, in addition to
m_width, in the next commit.

No changes yet in this one.
2020-05-01 03:25:52 +02:00
Vadim Zeitlin
ecc58e5211 Allow shrinking last column down to its minimal size
Not doing this when the last column size should have been exactly equal
to its manually set size resulted in showing the horizontal scrollbar
unnecessarily.
2020-05-01 03:23:52 +02:00
Vadim Zeitlin
9ed122b31f Update column sizes after updating scrollbars, not before
As UpdateColumnSizes() uses client size, call it after the client size
is set correctly after adjusting scrollbars to the new virtual size.
2020-05-01 03:22:40 +02:00
Vadim Zeitlin
7a8f04302f Use client size for calculating column sizes, not the full size
We need account for the place taken by the vertical scrollbar, if any.
2020-05-01 03:21:45 +02:00
Vadim Zeitlin
f10d9e199f Remove unnecessary GetColumnCount() test in wxDataViewCtrl code
The presence of columns is already checked inside UpdateColumnSizes()
itself, so there is no need to do it before calling it too.

No real changes.
2020-04-30 23:37:00 +02:00
Jorge Moraleda
e3b216b75e Consistent indentation in generic DVC 2020-04-20 19:50:26 -07:00
Jorge Moraleda
773a1876de In DVC, if current column was set by keyboard to something not editable and the user pressed Space/F2 then do not edit anything because focus is visually on that column and editing something else would be surprising. But if the current column was set by mouse to something not editable, treat the situation as if there was whole-row focus, because the mouse click could very well be targeted on the row rather than on an individual cell. 2020-04-20 19:43:34 -07:00
Jorge Moraleda
ede053def6 A DVC cell that has no value is not editable 2020-04-18 14:10:59 -07:00
Vadim Zeitlin
b90a74f6fe Minor formatting and code style fixes
Put braces around loop body.

Use const for local variables.

No real changes.
2020-04-17 23:30:07 +02:00
Vadim Zeitlin
736628f7a0 Fix crash due to dereferencing null pointer in list mode
TryAdvanceCurrentColumn() is called with NULL node in this case, so
avoid dereferencing it.
2020-04-17 23:30:07 +02:00
Vadim Zeitlin
c80626d33a Replace IsItemMultivalued() with IsItemSingleValued()
This allows to simplify logic when calling it by avoiding negation.

No real changes.
2020-04-17 23:30:07 +02:00