Commit Graph

552 Commits

Author SHA1 Message Date
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
Paul Cornett
948ddc6e0f Eliminate -Wcast-qual warnings with GCC and Clang
Use const_cast, mutable, and various other changes to avoid -Wcast-qual
2020-02-02 22:50:32 -08:00
Vadim Zeitlin
b02fbafb96 Don't update wxDataViewColumn after it was resized interactively
Previously, the column was updated, i.e. wxHeaderCtrl::UpdateColumn()
was called, after the column width was changed interactively by the
user. This was unnecessary and actually harmful as it resulted in
recursion and display corruption.

Stop doing this by adding yet another width-related function to the
generic wxDataViewColumn called WXOnResize(), which just updates the
main window display, but doesn't update the header at all, and calling
it instead of SetWidth(), which does both, when the column is resized.

Closes #18245.
2020-01-19 03:28:13 +01:00
Vadim Zeitlin
655e29ff1a Remove a duplicate OnColumnChange() call
If the width really changed, wxDataViewColumn::SetWidth() already calls
wxDataViewCtrl::OnColumnChange() (via UpdateWidth()), so it's
unnecessary to call the latter again immediately after calling the
former. And if the width didn't change, it's not necessary to call it at
all, so in either case the OnColumnChange() call can be just removed.

No real changes.
2020-01-19 03:11:40 +01:00
Vadim Zeitlin
248d4a8631 Fix size of the last column after the previous commit
The loop computing "colswidth" (the sum of widths including last column)
actually incorrectly computed "lastColX" (the sum of widths until the
last column), fix this.

See #18295.
2019-10-19 23:00:58 +02:00
Vadim Zeitlin
6af316b537 Auto size last visible column in generic wxDataViewCtrl
Resize the last visible column and not just the last column, which might
be hidden, to fill up all the available space.

See #18295.
2019-10-19 22:02:20 +02:00
Maarten Bent
56fab0aabb Improve wxDataView on DPI change
Fix the row heights after a DPI change and adjust the column widths.
Use DPIChangedEvent instead of MSWUpdateFontOnDPIChange because the child
controls (m_clientArea, m_headerArea) need to update their font sizes first.
2019-09-28 23:37:01 +02:00
wangqr
0ea4366163 Fix the width of expander in wxDataViewCtrl
In 8f386265dc, the width of a tree
expander is changed to the native value on the platform. But some
calculations still use guessed value (m_lineHeight) as the width. This
fixes the value, by retrieving the width using the same method as in
OnPaint().

Closes https://github.com/wxWidgets/wxWidgets/pull/1508

Closes #18473.
2019-08-27 13:19:48 +02:00
PeterO
8f386265dc Use correct expander size in wxDataViewCtrl under MSW
Add wxRendererNative::GetExpanderSize(), implement it using the
appropriate theme element and use it instead of hardcoding the expander
size to 3 character widths.

Closes https://github.com/wxWidgets/wxWidgets/pull/1431

Closes #18449.
2019-07-20 17:00:32 +02:00
Vadim Zeitlin
d9684e1ceb Allow calling EnableSystemTheme(false) before creating the window
This is important as enabling the system theme results in changes to the
native ListView control appearance that are not undone later even if the
system theme is disabled. Notably, the item rectangle width is reduced
by 2 pixels when system theme is enabled and it's not increased to its
original value even when it's disabled later, resulting in gaps between
items through which the control background shows, for example. This also
makes items drawn using our own HandleItemPaint() slightly, but
noticeably, larger than the items using standard appearance, which looks
bad.

All these problems can be avoided if we skip enabling the system theme
in the first place if EnableSystemTheme(false) had been called before
creating the control, so support doing it like this and document that
this is the preferred way of disabling the system theme use.

Closes #17404, #18296.
2019-05-26 23:20:21 +02:00
Václav Slavík
560a81b913 wxDVC: Don't calculate hidden columns' widths
Don't call wxDataViewColumn::GetWidth() in OnPaint() for columns that
are hidden: they won't be drawn and their width won't affect anything.
The call looks deceptively simple, but may invoke best width
recalculation that can be very expensive on large models.
2019-05-10 18:18:20 +02:00
Paul Cornett
90ce6a4334 Remove unused variables 2019-04-04 10:40:45 -07:00
donovan6000
7cd48f7db1 Fixes how disabled wxDataViewToggle columns are displayed when control is disabled 2019-03-25 18:02:41 -07:00
Vadim Zeitlin
2531780c3b Avoid division by 0 in generic wxDataViewCtrl scrolling code
Apparently, ScrollTo() can be called when processing keyboard input in
the control before its initial resize and hence before scrolling is
initialized and in this case per-unit scroll units are still 0, so
dividing by them is not a good idea.

Just avoid scrolling in this case.

Closes https://github.com/wxWidgets/wxWidgets/pull/1262
2019-03-18 18:18:47 +01:00
Paul Cornett
7c3ce912e0 Use ctor-initializer rather than assignment for non-POD class members 2019-02-25 10:23:35 -08:00
Pavel Kalugin
be12bc6a8a Fix selection in generic wxDataViewCtrl after adding an item
Notify m_selection about the new item in all cases, not just when using
a virtual list model.

This was broken back in 36a5983f64 and
only fixed for virtual list controls, but not all the other ones, in
9f5af0a494.
2019-02-15 14:39:13 +01:00
Vadim Zeitlin
f09b3de914 Restore drawing item focus rectangle in generic wxDataViewCtrl
The current, but not selected, item was not visually marked in any way
since the changes of 4ac0250f90 which
replaced the calls to wxRendererNative::DrawFocusRect() with the calls
to DrawItemSelectionRect() which is not called when the item is not
selected.

Restore DrawFocusRect() call in this case and also pass
wxCONTROL_FOCUSED to DrawItemSelectionRect() even though this doesn't
seem to change much in practice.

Closes https://github.com/wxWidgets/wxWidgets/pull/1089

Closes #18304.
2019-01-16 01:29:23 +01:00
Vadim Zeitlin
288d26598c Merge branch 'dvc-var-height'
Optimize generic wxDataViewCtrl performance with variable line heights.

Closes https://github.com/wxWidgets/wxWidgets/pull/1053
2019-01-16 01:25:06 +01:00
Václav Slavík
488cbb7848 Fix flicker when reducing wxDVC width
After 841c14c37c, reducing width of a
generic wxDataViewCtrl caused flickering (horizontal scrollbar
appearing and disappearing immediately) when the columns were resized
by user code to fix exactly.

Fixed by calling AdjustScrollbars() after determining column sizes. It
doesn’t make sense to call it before, because UpdateColumnSizes() may
change required width.

See #18295.
2019-01-10 14:25:11 +01:00
Jens Göpfert
8c64209df1 ensure m_rowHeightCache is not NULL before accessing it 2019-01-08 00:12:26 +01:00
Vadim Zeitlin
b2cdd287bb Resolve change log conflict with master
Reapply the change log change manually to master version of the file to
let the CI builds merge this branch automatically.
2018-12-20 02:24:49 +01:00
Vadim Zeitlin
c922c95c96 Fix the just introduced signed/unsigned comparison warning
Cast to unsigned before comparing with an unsigned variable.
2018-12-20 02:21:53 +01:00
jensgoe
12edcbccc8 clear height cache if model is cleared 2018-12-19 20:45:32 +01:00
jensgoe
7ab9e992b6 ensure row >= GetRowCount() if GetLineAt reaches invalid item
refactored method structure for better readability
2018-12-19 20:45:00 +01:00
Vadim Zeitlin
8856715d2d Use wxVector instead of wxList for wxDataViewCtrl columns storage
As wxDataViewColumnList was never public, it should be fine to not
define it any more and use a vector instead.

This makes the code more clear and also marginally more efficient.
2018-12-15 14:43:47 +01:00
Vadim Zeitlin
2340a16d18 Allow increasing the size of the last column in wxDataViewCtrl
Previously, the last column couldn't be effectively resized at all, as
its size was always automatically set to the remaining width of the
window after subtracting the widths of all the previous columns. Now
this is only done if this remaining width is greater than the width
given to the column by the user or by the program.

Effectively, this means that the user can now drag-resize the column to
increase its size (at the price of showing the horizontal scrollbar).

See #18295.
2018-12-15 14:27:52 +01:00
Vadim Zeitlin
68bb67c009 Revert "Prevent the user from resizing the last wxDataViewCtrl column"
This reverts commit 24054c95d8 as it
actually should be possible to increase the size of the last column,
even if this shows the horizontal scroll bar.
2018-12-13 23:46:25 +01:00
Vadim Zeitlin
24054c95d8 Prevent the user from resizing the last wxDataViewCtrl column
This is useless as this column will be automatically expanded to fill
all the available space anyhow.

See #18295.
2018-12-13 23:42:15 +01:00
Vadim Zeitlin
841c14c37c Fix expanding last wxDataViewCtrl column in the generic version
The code added in 4156e1a5c9 didn't quite
work correctly because it used the old size of the window, before it was
resized, and not the new size. This was almost unnoticeable when
drag-resizing the window, but very noticeable when maximizing the
containing TLW, as could be seen on the 3rd page of the dataview sample,
for example, where the last column kept its size instead of expanding.

See #13904, #18295.
2018-12-13 18:50:18 +01:00
jensgoe
1f0e32e485 fixed handling of NULL items 2018-12-10 13:55:04 +01:00
Vadim Zeitlin
9a91f59399 Revert the change to RefreshRows() in a recent commit
There doesn't seem to be any reason for this check to exist.
2018-12-07 04:17:16 +01:00
Vadim Zeitlin
cee89508d3 Simply destroying row heights cache
There is no reason to neither check that the pointer is non-null nor to
call Clear() on it before deleting it, so don't do it.
2018-12-07 04:17:16 +01:00
Vadim Zeitlin
090491cdbc Minor style and formatting clean up of the new code
Fix typos in comments and indent them.

Wrap over-long lines.

Remove useless top-level const.
2018-12-07 04:17:16 +01:00
jensgoe
d6a137b730 Improve wxDataViewCtrl performance with wxDV_VARIABLE_LINE_HEIGHT
Store the line heights in a cache to make the (generic) wxDataViewCtrl
usable with this style.
2018-12-07 04:05:16 +01:00
Vadim Zeitlin
da612f02b5 Stop editing in generic wxDataViewCtrl when any button is pressed
Previously, the editor was hidden if the left mouse button was pressed,
but not for the right (or any other) button, which could result in a
confusing situation when a user could select a command from a context
menu shown from the corresponding event handler and start editing
another item while the current one was still being edited too.
2018-12-06 22:53:28 +01:00
Vadim Zeitlin
2d18aaf58a Move check for mouse button down events in wxDataViewMainWindow
No real changes, just prepare for the next commit.
2018-12-06 20:48:32 +01:00
Maarten Bent
39ff5b90e5 Replace wxDeprecatedGUIConstants enum values 2018-11-25 21:29:32 +01:00
Vadim Zeitlin
9460038b3f Return empty rectangle from GetItemRect() if item is not visible
This was already the case if the item was not visible because its parent
was not expanded, but now make it also true for the items which are not
visible due to the current scrollbar position.

Add unit tests checking for this and also verifying that GetItemRect()
returns the coordinates in the physical window coordinates.
2018-11-04 18:28:33 +01:00
Vadim Zeitlin
c3779f2e5d Clarify ItemToRowJob in generic wxDataViewCtrl code
Rename its m_ret field to a more clear and more consistent with
RowToTreeNodeJob::m_current name and also make m_current, unlike m_ret,
0-based from the beginning instead of having to subtract 1 from it in
GetResult().

There should be no changes in the class behaviour.
2018-11-04 17:29:24 +01:00
Vadim Zeitlin
4b8fed3ad6 Make ItemToRowJob::m_item const
No real changes, just indicate that this member variable doesn't change.
2018-11-04 17:21:09 +01:00
Vadim Zeitlin
1f0aad61e2 Use standard naming convention for ItemToRowJob members
Use "m_" prefix for all of them.

No real changes.
2018-11-04 17:20:11 +01:00
Vadim Zeitlin
ed20421181 Clarify RowToTreeNodeJob in generic wxDataViewCtrl code
Get rid of hardcoded, without any explanation, "-2" value passed to this
class ctor and instead initialize its m_current member to -1 and explain
why do we do it and increment it after processing the current item, not
before, in operator().

No changes in behaviour.
2018-11-04 17:17:50 +01:00
Vadim Zeitlin
ada5de3d0d Fix wxDataViewCtrl::GetItemRect() for collapsed items
Calling GetItemRect() for an item which was not currently visible
because its parent was collapsed resulted in silently returning the
value for a wrong value before the recent fix to GetRowByItem() and in
a crash after it because GetTreeNodeByRow() returned null when passed
invalid row index.

Fix this by explicitly checking whether the item is shown and just
returning an empty rectangle instead.

Also document this behaviour and add a unit test for it.
2018-11-04 17:15:42 +01:00
Vadim Zeitlin
685f9ff57d Fix bug in GetRowByItem() in generic wxDataViewCtrl
If the item was not found at all, which can happen if all its parents
are not expanded, this function still returned a valid but completely
wrong row index.

This affected many functions which could call it for the items which
were not necessarily visible, i.e. all of them except for the event
handlers as events can only affect the visible items, including but not
limited to SetCurrentItem(), all the selection-related functions, all
the expansion-related functions, EnsureVisible(), HitTest() and
GetItemRect().
2018-11-04 17:03:16 +01:00
Vadim Zeitlin
739ce60552 Remove the unused RowToTreeNodeJob::m_parent variable
This variable was assigned to but never used.

Also remove the corresponding ctor argument which was only used to
initialize this unused variable.
2018-11-04 14:58:23 +01:00
Vadim Zeitlin
3d4a47a6bb Change RowToTreeNodeJob::m_row type to int and make it const
It doesn't make much sense to use an "unsigned int" variable only to
cast it to int everywhere where it's used. Just make it "int" from the
get go and have a single cast to int in the caller.

Also make m_row const as it never changes.
2018-11-04 14:56:36 +01:00
Vadim Zeitlin
05ae63e40a Use standard naming convention for RowToTreeNodeJob members
Prefix them with "m_" to indicate that they're member variables.

No real changes.
2018-11-04 14:55:43 +01:00
Václav Slavík
e5beb4e93f Improve wxDataViewMainWindow::RefreshRow speed
RefreshRow() is called very frequently, and in particular after every
ItemChanged notification. Calling GetEndOfLastCol() in it repeatedly is
extremely inefficient in presence of auto-sizing columns, and doesn't
make much sense anyway - controls with significant space unoccupied by
columns are rare, and rendering of such unused space is efficient (just
background erase). It is therefore more performant to simply refresh
the entire row instead of repeatedly and expensively calculating the
smallest rectangle that needs repainting.

Fixes previously wrong calculation of the refreshed rectangle in
RefreshRows() in the process.

Fixes major performance regression introduced in
77c7c80696.

Closes https://github.com/wxWidgets/wxWidgets/pull/970
2018-10-30 23:50:40 +01:00