Commit Graph

67957 Commits

Author SHA1 Message Date
Vadim Zeitlin
bc3c6fea70 Fix Shift-Ctrl-arrows handling
Extending the selection with Ctrl-arrows is different from all the other
cases, as we need to combine both the selection anchor and the current
cell coordinates when doing it.

This means that we can't reuse the same PrepareForSelectionExpansion()
helper for this case, so this function is not useful finally and this
commit removes it entirely. It also replaces GetCurrentBlockCornerRow()
and GetCurrentBlockCornerCol() functions with GetExtensionAnchor() which
combines both of them.

Finally, it adds wxGridDirectionOperations::TryToAdvance() helper to
avoid repeating the IsAtBoundary() check which was previously part of
PrepareForSelectionExpansion() in multiple places.

And because the "extending" and normal parts of DoMoveCursorByBlock()
are so different now, it also factors out AdvanceByBlock() helper which
can be used to keep these parts well separate from each other instead of
intermixing them together.

With all these preparatory changes, it's finally possible to implement
the "extending selection by block" logic relatively easily, with the
bulk of this branch actually taken by comments explaining why do we have
to do what we do.

Add unit tests verifying that the functions used by Shift-Ctrl-arrow
work as expected.
2020-04-13 00:49:22 +02:00
Vadim Zeitlin
9b031be8d1 Fix fatal bug in wxGridSelection::DeselectBlock()
The selBlock reference could be used after the vector invalidation,
which resulted in using the wrong vector element at best and could
probably lead to a crash at worst.

Don't use it after invalidating the vector any longer.

This notably fixes a bug in row-or-column selection mode where the grid
wasn't updated visually after modifying its selection by deselecting a
single cell as soon as there were more than one selected row or column.
2020-04-12 18:57:59 +02:00
Vadim Zeitlin
4f7ed07f5e Don't use row/column headers for selection incompatible with mode
Mouse events in row/column headers should be just ignored when the
current selection mode disallows row/column selection.

This wasn't the case before, and while actually selecting the line
corresponding to the header was disallowed further down the call chain,
clicking it still unexpectedly cleared the existing selection and
dragging mouse in the header window selected the entire grid.

Fix this by just never entering the corresponding cursor mode in the
first place if it's incompatible with the current selection mode.
2020-04-12 18:39:34 +02:00
Vadim Zeitlin
4cabffb983 Fix test for "almost visible" row in GetFirstFullyVisibleRow()
The test didn't correspond to the comment and resulted in always
considering the first row not visible instead of the intended effect.
2020-04-12 18:29:26 +02:00
Vadim Zeitlin
b98f439686 Also rename wxGridSelection::ExtendOrCreateCurrentBlock()
This function finally doesn't ever create a new block, except for the
trivial case when there is no current block, so rename it to a simpler
and more clear name.

No real changes.
2020-04-12 02:43:42 +02:00
Vadim Zeitlin
30eaa28de5 Rename wxGrid::GetSelectionRange() to GetSelectedBlocks()
This seems to be more consistent with the existing functions and doesn't
create ambiguity with a grid range.

Also rename wxGridSelectionRange to just wxGridBlocks as, in principle,
this class could be used for iterating over any blocks, not just the
selected ones.

No changes in functionality, this is just a renaming.
2020-04-12 02:38:37 +02:00
Vadim Zeitlin
b10755e553 Fix selection expansion in row/column-only selection modes
We should never adjust the fixed coordinate of the selection blocks in
this mode, so ensure we never end up with a partially selected line in
this case by preserving the -- correct by construction -- current block
coordinates in this direction.
2020-04-12 02:38:37 +02:00
Vadim Zeitlin
32bb5e9157 Fix Shift-click/arrow behaviour for column/row selection
Extend the current block to the entire line when the corresponding
header is Shift-clicked and, importantly, keep the full-line selection
when using Shift-arrows later to make the selection behave in the
expected way.
2020-04-12 02:38:37 +02:00
Vadim Zeitlin
c90bed6f8e Stop passing invalid coordinates to ExtendOrCreateCurrentBlock()
This made the logic of this function unnecessarily more complicated.
Instead, just fall back to the current cell coordinates in the only
place where this could happen before.

Doing this still preserves the correct behaviour of Shift-arrow
selection when entire rows/columns are selected and the current cell is
not the leftmost/topmost cell (due to scrolling), but the code is
simpler.

Remove the now always true condition check and assert that it's indeed
always true.

Note that the changes to gridsel.cpp in this commit are best viewed
ignoring whitespace changes.
2020-04-12 02:38:37 +02:00
Vadim Zeitlin
415bab551c Add wxGridSelection::SelectAll() and use it in wxGrid
The difference between calling SelectAll() and SelectBlock() with a
block covering the entire grid is that the former discards any
previously selected blocks, which become clearly redundant.

As a consequence, clicking on the grid corner 10 times in a row still
results in a selection with a single block, not 10 (identical) blocks.
2020-04-12 02:38:37 +02:00
Vadim Zeitlin
7d56146998 Add a comment for ClearSelection()
No real changes, just mention that this function does more than just
clearing the selection.
2020-04-12 02:38:37 +02:00
Vadim Zeitlin
1cb2ec06ee Fix off-by-1 bugs in wxGrid::GetFirstFullyVisible{Row,Column}()
These functions always returned the first partially visible line, not
the first fully visible one as intended because IsXXXShown() always
returned true when it applied to that line and we need to increment the
index first, before calling it -- even if this requires writing the loop
in a slightly uglier way.

This fixes bugs in commits 0920a1646b (Make wxGrid row selecting more
user friendly, 2020-03-04) and 89dd47edee (Make wxGrid column selecting
more user friendly, 2020-03-04).
2020-04-12 02:38:37 +02:00
Vadim Zeitlin
b095e67ac3 Show more detailed information about selection in the grid sample
Show the selected cells/rows/columns/blocks instead of just showing
their number, as we now have an efficient (i.e. taking time proportional
to the number of selected blocks and not to the number of the individual
cells, rows or columns) way of doing this.

See #2576.
2020-04-12 02:38:37 +02:00
Vadim Zeitlin
f3ff89601f Slightly clarify ExtendOrCreateCurrentBlock() code
Don't use long-lived non-const "block" reference, this makes it
difficult to see that it's never changed until the very end of the
function, when it's updated.

Compare "blockStart" with "block" itself instead of comparing it with
"newBlock" which is initially its copy but gets modified later (however
these modifications don't affect the comparisons involving it).

Add a comment explaining why are we doing what we do here.
2020-04-12 02:38:37 +02:00
Vadim Zeitlin
7d0b352485 Add MSVS debug visualizers for wxGrid{Cell,Block}Coords
This makes debugging wxGrid code much more pleasant.
2020-04-12 02:38:37 +02:00
Vadim Zeitlin
69a05b0340 Use the same selection expansion logic for Shift-Ctrl-cursor
Expanding the selection from keyboard with Ctrl pressed should move in
the same way Ctrl-cursor does, but use the same selection anchor as
Shift-cursor does instead of always using the current cell.

This makes the expansion work much more intuitively in the grid, e.g.
pressing Shift-Ctrl-Down in

    1 2
    3 4

grid when 1 and 2 are selected now selects all the cells instead of
selecting 1 and 3 as it did before.
2020-04-06 02:39:21 +02:00
Vadim Zeitlin
fe6d07d2d1 Some minor comments wording changes in wxGridSelection
Try to better explain the behaviour of the methods of this class.
2020-04-06 02:26:02 +02:00
Vadim Zeitlin
b17d3ecb52 Remove unused private BlockContain() function
This was probably left over after wxGridBlockCoords::ContainsBlock()
introduction.
2020-04-05 17:38:08 +02:00
Vadim Zeitlin
1d43ae7dc6 Refactor selection expansion code to use actual wxKeyboardState
Switch from using just "bool expandSelection" in the grid functions
(possibly) extending the current selection to using the full
wxKeyboardState.

This allows to pass it to ExtendOrCreateCurrentBlock() and slightly
simplify the code by using DoMoveCursorFromKeyboard().
2020-04-05 15:56:45 +02:00
Vadim Zeitlin
ddc87d66e8 Increase the size of the windows in the grid sample
Make larger part of the grid visible initially and also show more lines
in the log window.

No real changes, this is purely cosmetic.
2020-04-05 15:51:35 +02:00
Vadim Zeitlin
d031ef154a Simplify wxGrid::SetSelectionMode() selection updating logic
Don't try to extend the existing selected blocks to rows/columns, this
contradicts the documented behaviour which is to discard the selected
blocks that become invalid in the new mode.

Do handle switching to wxGridSelectRowsOrColumns mode, as there doesn't
seem to be any reason not to.

Update the tests to check for the expected selection update behaviour.
2020-04-05 02:11:04 +02:00
Vadim Zeitlin
13978a6626 Remove outdated comment from wxGridSelection code
Don't mention variable which doesn't exist any more.
2020-04-05 01:52:35 +02:00
Vadim Zeitlin
0ab23a0072 Add a comment about wxGridSelection::IsInSelection() complexity
No real changes.
2020-04-05 01:42:40 +02:00
Vadim Zeitlin
791a9e68ae Rename and simplify wxGridBlockCoords::ContainsBlock()
Change the return type of this function to a simple and clear bool
instead of 3-valued int requiring a special explanation. This is simpler
and not any less efficient as checking for whether one block contains
another or the other one contains this one are separate operations
anyhow.

Rename the function to a more grammatically correct name.

Also move it inline as it's now trivial enough for this to be worth it.
2020-04-05 01:37:56 +02:00
Vadim Zeitlin
a5952ee087 Rename wxGridBlockCoords::ContainsCell() and move it inline
Make the function name more grammatically correct.

No real changes.
2020-04-04 19:45:19 +02:00
Vadim Zeitlin
0a5a904d8d Simplify wxGridSelectionRange to provide only iterators
This class was a strange hybrid of a container/view/range and iterator,
as it both provided begin()/end() container-like methods and
iterator-like methods for dereferencing/advancing.

Simplify this by removing the latter part and making this class really
just a range, with its own iterator class in order to avoid leaking the
exact type of the iterator used in the API.

Note that while it's now completely trivial, it is still useful as it
isolates the application code from the vector used to store the selected
blocks currently and will allow to change internal representation in the
future without breaking the existing code.
2020-04-04 19:37:23 +02:00
Vadim Zeitlin
7231a6a855 Make temporary variable in GetSelectionRange() const
We don't need to modify the selection blocks here.

No real changes.
2020-04-04 19:04:33 +02:00
Vadim Zeitlin
0f8e985252 Define wxGridSelectionRange::iterator in terms of vector iterator
This fixes compilation when using std::vector<> implementation for
wxVector (i.e. with wxUSE_STD_CONTAINERS==1).
2020-04-04 19:04:17 +02:00
Ilya Sinitsyn
a469d36783 Fix the test where wxGrid scrolling when selecting cells 2020-04-04 18:50:37 +02:00
Ilya Sinitsyn
bfca68c74a Move the wxGrid cursor to the corner of the last selection
Move the wxGrid cursor to the corner of the last selection when splitting
the selection block on click with Ctrl.
2020-04-04 18:50:37 +02:00
Ilya Sinitsyn
f8015b13b1 Implement wxGrid selection blocks iterating interface 2020-04-04 18:50:37 +02:00
Ilya Sinitsyn
8ebdf101b8 Make wxGrid cells selecting by mouse more user friendly 2020-04-04 18:50:37 +02:00
Ilya Sinitsyn
0920a1646b Make wxGrid row selecting more user friendly 2020-04-04 18:50:37 +02:00
Ilya Sinitsyn
89dd47edee Make wxGrid column selecting more user friendly 2020-04-04 18:50:37 +02:00
Ilya Sinitsyn
e1b9ece9a4 Edit the current wxGrid selection block
Really edit the current selection block instead of storing the temporary
information about the current selection and applying it on releasing Shift
key or LKM.
2020-04-04 18:50:37 +02:00
Ilya Sinitsyn
72e7bde306 Refactor wxGrid::MakeCellVisible() to scroll in only one direction
Allow -1 for a row or a column single parameter.
2020-04-04 18:50:37 +02:00
Ilya Sinitsyn
206bad9ba0 Remove wxEVT_GRID_RANGE_SELECT handling by wxGrid::SendEvent()
VZ: [...] this is not used by wxGrid itself and SendEvent() is not part
of the public API, so we never made any promises about being able to call
it with wxEVT_GRID_RANGE_SELECT.
2020-04-04 18:50:37 +02:00
Ilya Sinitsyn
779d3f7f17 Clear the selection in wxGrid::SetTable
The selection in m_selection was not considered at all so it was worked not
correctly any way.
2020-04-04 18:50:37 +02:00
Ilya Sinitsyn
d4919d3334 Remove wxGridSelection::ToggleCellSelection()
Remove the function because it's not usefull anymore and used only in one
place.
2020-04-04 18:50:36 +02:00
Ilya Sinitsyn
cdf3187fe5 Improve rows, columns and cells deselection in wxGrid
Use DeselectBlock() instead of ToggleCellSelection() to improve execution
speed and make the code more clean.
2020-04-04 18:50:36 +02:00
Ilya Sinitsyn
f1c3dfdca6 Do not merge wxGrid selection blocks
Remove blocks merging because it complicates the behavior at the user point
of view and the code.
2020-04-04 18:50:36 +02:00
Ilya Sinitsyn
02509cbc39 Refactor wxGridSelection to store selection as blocks only
Store all types of selection with an array of blocks instead of arrays of
cells, blocks, rows and columns.

It (hopefully) simplifies the code and allows us to implement editing of
the last selection block much easier.
2020-04-04 18:50:36 +02:00
Ilya Sinitsyn
d1c8bba2b6 Fix SelectEmptyGrid wxGrid unit test
Use CATCH nested sections correctly.
2020-04-04 18:50:36 +02:00
Ilya Sinitsyn
acd72efbf1 Implement wxGridBlockCoords class
wxGridBlockCoords represents a location of a block of cells in the grid.
2020-04-04 18:50:36 +02:00
Ilya Sinitsyn
673ed29d7b Make wxGridSelection to be non-friend to wxGrid
Improve integrity of the wxGridSelection internal data by removing `friend`
declaration.
2020-04-04 18:50:36 +02:00
Ilya Sinitsyn
79219fdbb2 Remove unused wxGrid member variable 2020-04-04 18:50:36 +02:00
Vadim Zeitlin
43b3a3fc5b Merge branch 'grid-hidpi'
wxGrid improvements for high DPI and DPI changes

See https://github.com/wxWidgets/wxWidgets/pull/1776
2020-04-04 18:46:54 +02:00
Vadim Zeitlin
28a9f50bc7 Merge branch 'grid-align-overflow'
Fix overflow in wxGrid cells with non-default alignment.

See https://github.com/wxWidgets/wxWidgets/pull/1775
2020-04-04 18:46:18 +02:00
Artur Wieczorek
372a609e82 Use ellipsis character instead of "..." approximation
This way editor button label will be shorter.
2020-04-04 18:07:46 +02:00
Artur Wieczorek
c7b789d351 Increase wxPropertyGrid line height under wxGTK3
Line height calculation based on the font size is not right for wxGTK3
because native buttons (used as in-line editor buttons) don't scale down
well and they are not displayed properly within the line.
Minimal button size when the label is displayed properly is 35 so this
has to be minimal line height under wxGTK3.

Closes #18715.
2020-04-04 18:02:40 +02:00