Commit Graph

489 Commits

Author SHA1 Message Date
Daniel Kulp
d8b3fc84c2 Fix sorting in generic wxDataViewCtrl broken by recent changes
The comparator used with std::sort() must return true only if the first
item is strictly less than the second one, this is a requirement of the
sorting algorithm and not respecting it results in wrong final order.

See https://github.com/wxWidgets/wxWidgets/pull/642
2018-01-24 23:40:37 +01:00
Vadim Zeitlin
0d77df8af1 Merge branch 'dvc-update-fix'
See https://github.com/wxWidgets/wxWidgets/pull/674
2018-01-23 15:51:08 +01:00
Vadim Zeitlin
91f54ea7e4 Remove a useless assert from wxDataViewTreeNode::GetChildNodes()
Checking that a pointer is non-null before dereferencing it is perfectly
useless: the code will crash anyhow, so assert doesn't help with
debugging it in debug builds nor with preventing the crash in release.
2018-01-17 10:15:11 +01:00
Vadim Zeitlin
ff3b3269dd Fix adding items to wxDataViewCtrl broken in the last commit
SetHasChildren(true) must be called before checking GetChildNodes() if
the parent hadn't had any items in the initial model.

Also remove the assert checking that the node is open in
BuildTreeHelper() as we may need to build even a closed tree branch.
2018-01-17 10:15:11 +01:00
Vadim Zeitlin
4dc78a33e0 Fix adding items to a never opened branch of generic wxDataViewCtrl
Calling ItemAdded() on a parent item that had never been opened yet
"lost" all its children that initially existed in the model, as the
corresponding subtree wasn't built any more in Expand() when this item
was finally opened because the list of item children wasn't empty any
more after ItemAdded() added the new child to it.

Fix this by simply not doing anything in ItemAdded() in this situation,
there is no need to update a closed tree branch immediately anyhow.
2018-01-17 00:15:50 +01:00
Vadim Zeitlin
77c7c80696 Update modified items in generic wxDataViewCtrl immediately
Recent optimizations avoiding resort on item change (see
https://github.com/wxWidgets/wxWidgets/pull/642) have also optimized
away refreshing the modified item, which was done implicitly, as a side
effect of resorting, before, so the changes were not reflected on
display immediately any longer.

Fix this by simply refreshing the item explicitly and also add a way to
test for the correct behaviour in the sample.
2018-01-16 13:12:43 +01:00
Vadim Zeitlin
4f456c8a19 Refactor "changed" notifiers in generic wxDataViewCtrl code
No real changes, just add the new DoItemChanged() used from both
ItemChanged() and ValueChanged() notifications to avoid repeating the
same code in both functions.
2018-01-16 13:12:43 +01:00
Vadim Zeitlin
a2ad7f9bf6 Merge branch 'dvc-sort-opt'
Optimize item sorting in generic wxDataViewCtrl and other minor
enhancements.

See https://github.com/wxWidgets/wxWidgets/pull/642
2018-01-04 21:42:42 +01:00
orbitcowboy
f423b88ded Replace post-increment on iterators with pre-increment
This is a micro-optimization, as pre-increment is at least as efficient
as post-increment and typically slightly more so because it doesn't need
to make a copy of the iterator, and better conforms to the prevailing
C++ style.

Closes https://github.com/wxWidgets/wxWidgets/pull/655
2017-12-29 19:59:24 +01:00
Vadim Zeitlin
1dbe3dafe4 Stop storing window pointer in all wxDataViewTreeNode objects
This didn't make any sense, all these objects reachable from the given
root node are used by the same window, so storing the same pointer in
all of them just wasted memory unnecessarily.

Avoid this by passing wxDataViewMainWindow pointer explicitly to those
methods of wxDataViewTreeNode that need it.

No changes in behaviour, this is just a (memory use) optimization.
2017-12-17 19:16:34 +01:00
Vadim Zeitlin
1bfe42b0ce Simplify sort order handling for first child item
Test whether this is the first child before testing whether the branch
is open as this allows to avoid the special case of inserting the first
child under the root node and simplifies the assert condition to a
simple check that the sort order is already what we expect.
2017-12-17 19:09:04 +01:00
Vadim Zeitlin
3f41e84830 Remove unused wxDataViewSelection dynamic array macro
This should have been done in 36a5983f64
but was forgotten and the unused array remained in the code.
2017-12-17 18:59:36 +01:00
Vadim Zeitlin
5365f3563e Get rid of global sort-related variables in wxDataViewCtrl
Having to set up global variables before (re)sorting the items was too
ugly and became even more so after the latest changes optimizing item
sorting as sorting is done in more places now.

Improve the code by introducing a SortOrder class instead of dealing
with the sort column and sort order direction separately and,
especially, by using std::sort() (which should be fine to use here,
considering that it's used since quite some time in wxArrayString
implementation) with a comparator object instead of qsort(), which
doesn't allow passing any data to the sort callback otherwise than via
the global variables.

No changes in behaviour.
2017-12-17 18:58:04 +01:00
Vadim Zeitlin
a7c68663fd Replace macro-based items array with wxVector in wxDataViewCtrl
No real changes, just try to minimize the use of the old macro-based
containers as there is really no reason to do it here.
2017-12-17 18:40:03 +01:00
Vadim Zeitlin
259a357824 Use index, not value, when removing items from wxDataViewTreeNode
This avoids another (linear) search among the item siblings, as we can
use the index we've just found instead directly.
2017-12-17 17:31:09 +01:00
Vadim Zeitlin
0268c062c0 Minor improvements to wxDataViewCtrl sorting optimization commit
Simplify some code and make it more clear, notably by changing
conditionals to be easier to follow.

Also avoid repeating the same functions calls (like SortPrepare() or
UpdateDisplay()) by folding them into the functions that actually need
them to be done.
2017-12-17 17:23:42 +01:00
Vadim Zeitlin
8d9f0e6fef Initialize BranchNodeData members in declaration order
Doing it out of order is harmless here, but would result gcc -Wreorder
warnings.
2017-12-16 17:32:53 +01:00
Vadim Zeitlin
eef994016a Reorder BranchNodeData struct members to make it more compact
By simply putting two bool fields consecutively to each other, we reduce
the number of bytes of padding used from 6 to 2 in a typical 32 bit
build, saving 4 (or 8, in 64 bits) bytes per branch item.
2017-12-16 17:30:11 +01:00
Erik Sperling Johansen
51ed404ca5 Optimize sorting items in wxDataViewCtrl
Limit node sorting to a minimum, by making all sorts happen on demand
and utilizing already sorted child lists to do quicker insertions.
2017-12-16 17:21:04 +01:00
Vadim Zeitlin
c85da939e5 Tidy up the previous commit slightly
Declare the variables just before using them (and also initialize them
at the same time); use more readable variable names; fix braces style
and add a comment explaining why do we do all this in the first place.

No real changes.
2017-12-10 19:21:03 +01:00
Jens Göpfert
57bdd372fb Reduce number of calls to GetLineStart() in generic wxDVC
GetLineStart() is very expensive when using wxDV_VARIABLE_LINE_HEIGHT
style, so don't call it again unnecessarily if we already have the
result.
2017-12-10 19:06:29 +01:00
Maarten Bent
afc02a34ee More use of wxFALLTHROUGH in MSW code and samples 2017-11-25 17:52:08 +01:00
Paul Cornett
cdb9436975 Use wxFALLTHROUGH 2017-11-12 09:34:22 -08:00
Andreas Falkenhahn
eb035485d7 Add wxDataViewCtrl::GetTopItem() and GetCountPerPage()
Add methods doing the same thing for wxDataViewCtrl as the existing wxListBox
methods.

Closes #17498.
2017-10-21 22:10:35 +02:00
Anil Kumar
22a4feea53 Update current item in generic wxDataViewCtrl::SetSelections()
SetSelections was clearing the previous selection, invalidating the
current item, but didn't set it after selecting the new items.

This was causing issues in keyboard selection, e.g. pressing Shift+click
didn't select all the items between the selected and the clicked ones.

Fix this by making the last item of the new selection current, which is
the expected behaviour considering that SetSelections() should be
equivalent to calling SetSelection() with all items one by one.

Signed-off-by: Anil Kumar <anilkumar8753@gmail.com>

Closes https://github.com/wxWidgets/wxWidgets/pull/557
2017-09-19 22:32:21 +02:00
jensgoe
dd4a9de048 Fix drawing background in wxDataViewCtrl with rules
wxRect to draw the background was prepared in a wrong way if wxDataView had
vertical or horizontal rules.

Fix this by adjusting the correct component of the rectangle when using
horizontal rules and by fixing an off by one bug when using vertical ones.
2017-05-03 16:05:20 +02:00
Václav Slavík
60bd6842e4 Fix handling of ampersands in wxDataViewCtrl markup
Handle "&amp;" in exactly the same way as "&" in wxMarkupParser, i.e. do not
map the former to "&&" to prevent it from being interpreted as a mnemonic as
this is incompatible with using markup for anything but the control labels,
e.g. for wxDataViewCtrl items text, in which mnemonics are not recognized.
And even when using markup for control labels, it was a questionable decision
as it's really not clear at all why should the XML entity and the raw
character itself be handled differently.

Also split wxMarkupText into two classes, wxMarkupText that handles
mnemonics in the markup (which is typically a label) and a very
similar, but not derived, wxItemMarkupText that handles mnemonics-less
markup for list etc. items, uses DrawItemText() and supports
ellipsizing.

Illustrate the use of ampersands in the dataview sample.
2017-04-07 18:45:39 +02:00
Maarten Bent
f6f72449fe Resolve -Wmisleading-indentation warnings. 2017-02-24 23:37:38 +01:00
Václav Slavík
6aff1c8c64 Compilation and warnings fixes for wxUSE_HELP=0 2017-02-02 18:22:10 +01:00
Václav Slavík
1f56389e8b Fix generic wxDVC::EnsureVisible() to show full row
Generic wxDataViewCtrl's EnsureVisible() previously only ensured that at
least some part of the item (even if just 1px of it) was visible,
instead of being fully shown.
2017-01-12 17:46:29 +01:00
Jouk
062e3c3d32 Adding missing ; 2017-01-05 16:32:42 +01:00
Vadim Zeitlin
7cddac83a9 Merge branch 'custom-msw-class'
Allow using custom Windows class names for our windows and use this to give a
unique class name allowing to identify it in the screen readers to
wxDataViewCtrl.

Closes https://github.com/wxWidgets/wxWidgets/pull/373
2016-12-20 21:51:09 +01:00
Vadim Zeitlin
9ff563b0f8 Use special "wxDataView" Windows class name in wxMSW
This makes it possible for the screen readers to handle wxDataViewCtrl
specially and better than by default.
2016-12-20 21:50:51 +01:00
Scott Furry
068e0f6ec4 Fix build breaking typo in wxDataViewCtrl accessibility code
Dereference the pointer before casting it to unsigned int.
2016-12-19 19:13:53 +01:00
Václav Slavík
f7514467ae Don't use wxACC_STATE_SYSTEM_READONLY for wxDVC items
Items in wxDataViewCtrl are only read-only if there's no editable
column, in which case all items are read-only. This flag is only useful
for accessibility if only some of the items in the list are read-only;
if all of them are, it's just noise.
2016-12-13 18:56:20 +01:00
Václav Slavík
ff1dba498e Add wxDataViewValueAdjuster
Add wxDataViewRenderer:: SetValueAdjuster() and a
wxDataViewValueAdjuster class. This can be used to customize rendering
of values depending on whether they are highlighted (selection) or not,
without having to implement an entire new custom renderer.
2016-12-11 15:20:42 +01:00
Václav Slavík
095c958525 Fix ~wxDataViewCtrl assert when running under JAWS
Accessible object must be destroyed as soon as possible, because
otherwise a screen reader may try to query it before wxWindow destructor
removed it, but after ~wxDataViewCtrl destructor finished. The
wxACC_EVENT_OBJECT_DESTROY notification causes exactly that under JAWS.
2016-11-03 16:27:28 +01:00
Václav Slavík
d3924b7d41 Report value as percent in wxDataViewProgressRenderer
GetAccessibleDescription() should return the value as percents, not a
raw number, because that's what m_value means.
2016-10-31 09:29:21 +01:00
Artur Wieczorek
9b8f46df36 Implement wxDataViewCustomRenderer::GetAccessibleDescription()
This is a default description of the renderer content (for accessibility purposes).
Thanks to this implementation there is not necessary to override GetAccessibleDescription() in the renderers derived from wxDataViewCustomRenderer.
2016-10-30 20:59:51 +01:00
Artur Wieczorek
fb219aaf35 Add accessibility event notifications to wxDVC 2016-10-30 20:49:56 +01:00
Artur Wieczorek
eeaa613705 Fix wxDataViewCtrlAccessible::DoDefaultAction
Calling wxDataViewTreeNode::ToggleOpen() is not sufficient to actually expand/collapse the item.
Calls to wxDataViewMainWindow::Expand()/Collapse() are necessary to do so.
2016-10-30 20:41:08 +01:00
Artur Wieczorek
dbb2781199 Fix wxDataViewCtrlAccessible::GetName() and GetDescription()
Call wxDataViewRenderer::GetAccessibleDescription() to retrieve the content of the renderer instead of using a raw item value taken from wxDataViewModel. GetAccessibleDescription() returns a renderer-aware text dedicated for accessibility purposes and hence text presented in GetName() and GetDescription() is accurate in contrary to the text deduced from the item value.
2016-10-24 22:12:53 +02:00
Artur Wieczorek
d9fbde805b Implement wxDataViewRenderer::GetAccessibleDescription() method
The purpose of this method is to provide a textual description of the renderer's content to the class implementing accessibility framework in wxDVC (wxDataViewCtrlAccessible).
It is exposed if wxUSE_ACCESSIBILITY is set to 1.
2016-10-24 21:52:22 +02:00
Václav Slavík
58fc33d7c2 Support ellipsizing of markup text in wxDVC
Fix wxDataViewTextRenderer to at least partially respect ellipsize mode
when using markup text. Generic implementation only supports
wxELLIPSIZE_END and wxELLIPSIZE_NONE at the moment, but the wxOSX and
wxGTK ones have full support.
2016-10-21 17:36:32 +02:00
Václav Slavík
f3b8dac3b7 Fix wxNullVariant handling in wxDataViewBitmapRenderer
In both the generic and GTK+ implementations, setting the value of a
bitmap column to wxNullVariant resulted in the bitmap, if set for some
rows, being repeated on the rows with null value.
2016-10-19 16:46:54 +02:00
Artur Wieczorek
cfe0eaa7f2 Create wxAccessible object on demand in wxDVC
Create wxAccessible objects only in response to calls to GetOrCreateAccessible() to save resources.
2016-10-16 23:48:27 +02:00
Artur Wieczorek
d8b2da0334 Remove wxUSE_VARIANT guards
wxDataViewCtrl requires wxVariant so these guards are not necessary.
2016-10-15 21:02:05 +02:00
Artur Wieczorek
a88cdfb49b Make strings localization-friendly
Reorganize string literals and add comments to make string more friendly  for translators.
2016-10-14 23:59:44 +02:00
Artur Wieczorek
d25cfa0e50 Handle disabled/hidden/invisible items for wxDVC accessibility purposes
Return corresponding states (wxACC_STATE_SYSTEM_UNAVAILABLE, wxACC_STATE_SYSTEM_INVISIBLE, wxACC_STATE_SYSTEM_OFFSCREEN) for objects which are disabled, hidden or invisible (out of screen).
2016-10-14 23:57:08 +02:00
Artur Wieczorek
239361c7c4 Fix determining last visible row in wxDataViewCtrl
If entire client area is filled with displayed rows, the last visible row is the row occupying the line at the bottom of the client area (at y = dimY-1).
Because last displayed row can be partially visible in the client area, it cannot be determined as previous row to the row virtually displayed below the client area (at y = dimY), like it is currently implemented.
2016-10-14 23:50:50 +02:00