Commit Graph

830 Commits

Author SHA1 Message Date
Vadim Zeitlin
e2a5c1ffc8 Don't provide wxSharedClientDataContainer::m_data accessors
This is not really necessary and breaks encapsulation of this private
method. It is enough to provide just a way to copy the data from another
object as this is all that the derived classes really need.
2022-04-28 00:36:40 +02:00
Frode Roxrud Gill
f646e8b11c Allow cloning client data stored in wxGrid attributes etc
Add wxSharedClientDataContainer class storing ref-counted client data
and use it instead of plain wxClientDataContainer in wxGridCellAttr,
wxGridCellEditor and wxGridCellRenderer classes.

This allows to keep the same client data associated with many grid cells
without having to make many copies of it.
2022-04-28 00:28:58 +02:00
DietmarSchwertberger
1b158caa83 Improve usability of wxGrid actions using mouse dragging
Implement auto scrolling and handle ESCAPE to cancel the actions done by
dragging the mouse, such as resizing or selecting an area.

Closes #22292.
2022-04-27 19:09:40 +02:00
DietmarSchwertberger
7f8f2a9aa3 Fix asserts when changing columns of wxGrid using native header
The number of columns has to be changed after updating the m_colAt and
m_colWidths arrays, as the native header uses them.

This extends the changes of a2d65663a0 (Fix assert when adding columns
to wxGrid using native header., 2013-05-31) to inserting and deleting
the columns too.

See #15225.

Closes #22294.
2022-04-10 16:14:58 +02:00
DietmarSchwertberger
3719ab3725 Add support for rearranging wxGrid rows order interactively
Add EnableDragRowMove() function and wxEVT_GRID_ROW_MOVE, similarly to
the existing column function and event.

Closes #22260.
2022-04-07 17:39:56 +02:00
Kvaz1r
1d585eef05 Fix scrollbar position in wxGrid and wxDataViewCtrl in wxUniv
Skip the event in wxEVT_SIZE handler in wxGrid and wxDataViewCtrl as it
was already done for wxListCtrl in 98c2eef619 (Fix scrollbar position in
wxListCtrl in wxUniv, 2021-09-05).

Closes #22145.
2022-02-25 18:23:12 +01:00
Paul Cornett
32eb4af061 Avoid using wxClientDC to redraw grid lines
This only happens when changing whether/how the lines are drawn, so
there should be no performance issue with just repainting the window.
2022-01-17 08:55:48 -08:00
Paul Cornett
8cfdabd50d Avoid a use of wxClientDC for drawing
Just refresh the cell if the highlight color is changed
2022-01-17 08:55:48 -08:00
Paul Cornett
4217573a3f Fix wxGrid::SetCurrentCell() with Wayland
Avoid wxClientDC with GTK3 as well as OSX. Additionally, refresh
only the cells that need it, rather than the entire window.
See #18448
2022-01-16 21:35:20 -08:00
Vadim Zeitlin
9b820b74b2 Fix handling selection in wxGrid::Render()
Temporarily reset the m_selection pointer itself instead of clearing the
selection, this is much more efficient, especially for big grids, and
also more correct, as the old code simply lost the original selection in
non-block selection modes.
2021-10-26 19:41:06 +01: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
Vadim Zeitlin
5cac8a6918 Enforce valid drag column/row index in DoGridDragResize()
Add an assert to this function checking that the index is valid before
using it with wxGridOperations::GetLineStartPos(), and actually avoid
calling the function when this is not the case to avoid assertion
failures when wxEVT_GRID_CELL_LEFT_CLICK is handled in user code.

Also add comments clarifying the preconditions for calling various
drag-related functions.

Closes #19218.
2021-07-03 16:31:15 +01:00
Vadim Zeitlin
e70be8f82b Fix indentation in wxGrid mouse processing code
Indent "break" statements correctly and remove unnecessary braces.

No real changes.

This commit is best viewed ignoring whitespace-only changes.
2021-07-03 15:52:04 +01:00
Vadim Zeitlin
c59ed10c2a Fix DPI change handling in wxGrid with hidden row/column labels
Don't reset the labels windows size to the default value, it should stay
as 0 because otherwise we break the invariants

	m_rowLabelWidth  != 0 <=> m_rowLabelWin->IsShown()
	m_colLabelHeight != 0 <=> m_colLabelWin->IsShown()

that the rest of the code relies on.

Closes #18904.
2021-06-24 14:40:35 +01:00
Vadim Zeitlin
092bd70519 Restore lighter shadow colours for wxGrid row/column separators
This was also changed in 3c28244806 (Improve wxGrid appearance in dark
mode under macOS, 2020-08-07) but there doesn't appear to be any good
reason to do it as wxSYS_COLOUR_3DDKSHADOW is the same as the previously
used wxSYS_COLOUR_3DSHADOW (a.k.a. wxSYS_COLOUR_BTNSHADOW) under Mac, so
this didn't change anything there -- but did make the shadows darker and
hence more pronounced and more noticeable under MSW.

Undo this change to restore the old and nicer looking appearance.
2021-05-22 16:13:18 +01:00
Vadim Zeitlin
829d3fd094 Restore wxGrid cursor visibility under non-Mac platforms
The changes of 3c28244806 (Improve wxGrid appearance in dark mode under
macOS, 2020-08-07) resulted in using white highlight colour over white
background under at least MSW and probably elsewhere, making the grid
cursor invisible by default.

Fix this by using wxSYS_COLOUR_WINDOWTEXT which must contrast with
wxSYS_COLOUR_WINDOW used for the background colour.
2021-05-22 16:06:10 +01:00
Vadim Zeitlin
1671a21e7c Fix crash when scrolling wxGrid in which scrolling is disabled
If "pixels per line" is set to 0, indicating that scrolling is disabled,
just don't scroll in the corresponding direction instead of dividing by
zero.

Closes https://github.com/wxWidgets/wxWidgets/pull/2323
2021-04-27 13:58:49 +02:00
Paul Cornett
4388b9bd6b Make some member functions const 2021-03-04 11:49:33 -08:00
Dimitri Schoolwerth
7bf2dc71c3 Remove wxGridCellWithAttr
After the previous commit the coords stored by wxGridCellWithAttr have
become redundant as the coords are now also stored as part of the key
used for an attributes map. With then only an attribute remaining in
wxGridCellWithAttr it can be removed completely, letting the value of
an attributes map point directly to a (ref-counted) attribute instead.
2021-02-15 12:36:03 +01:00
Dimitri Schoolwerth
061191e659 Improve responsiveness of a wxGrid having plenty of attributes
Speed up grid attribute lookups by using a hash map instead of array.

Closes #12764.
2021-02-15 12:36:03 +01:00
Dimitri Schoolwerth
3123c76394 Fix grid multicell integrity after inserting/deleting rows/columns
Deal with possible size changes of a multicell (both main and inside
cells) when inserting or deleting rows or columns and, in the case of
deletion only, the disappearing of a multicell's main cell.

Closes #4238.
2021-02-07 22:59:02 +01:00
Dimitri Schoolwerth
04a3dda5c5 Refactor common wxGridCellAttrData::UpdateAttrRows/Cols code
Move two symmetrical functions into one and clean up, preparing it for
multicell support.
2021-02-07 22:59:02 +01:00
Dimitri Schoolwerth
1f5b77bad3 Make use of grid helper function GetCellSpan()
Also gets rid of an additional attribute lookup that was recently
added in 00c497125e containing a minimal fix.
2021-01-19 22:30:33 +01:00
Dimitri Schoolwerth
860d9d09bc Refactor code deciding the kind of span of a grid cell
Move wxGrid's GetCellSize() cell span logic into GetCellSpan() for
future usage.
2021-01-19 22:26:03 +01:00
Dimitri Schoolwerth
00c497125e Fix drawing of grid cells appearing inside a multicell
Grid cells are considered for redrawing solely based on having
a (text) value. This can lead to infinite recursion with overflowing
inside cells if wxGridCellStringRenderer::Draw() wants to draw cells
appearing after this one but instead visits the same cell again (because
of a negative cell size as opposed to expected default cell size of 1x1
or a larger spanning size) and calls DrawCell() again for this cell
which will call the renderer's Draw() again etc...

Fix by not taking inside cells into consideration for redrawing. This
is the right thing to do as earlier on in the same function a cell is
not drawn for the same reason. Also the aforementioned Draw() mentions
it shouldn't be called for cell sizes <= 0.

Also fixes the crashing grid test just introduced in 6d3dbc3fe5.
2021-01-19 22:17:41 +01:00
Daniel Kulp
3c28244806 Improve wxGrid appearance in dark mode under macOS
Use more appropriate colours for the row/column cell headers and don't
hardcode black (i.e. at least use white instead in dark mode) for the
frozen border.

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

See #18941.
2021-01-18 00:03:10 +01:00
Paul Cornett
dd864cffe0 Fix border drawing glitch in wxGrid column header
See #18980
2020-11-20 21:46:09 -08:00
Vadim Zeitlin
bd8c74f368 Fix positioning of bottom-aligned checkboxes in wxGrid
This fixes a bug due to a typo in ab02d36e10 (Account for vertical
alignment in wxGetGridCheckBoxRect() too, 2019-11-22) which used the
vertical component of a wrong object and so didn't actually offset the
checkbox by its size from the bottom of the cell rectangle, as it should
have done.

Closes #18907.
2020-11-02 00:55:47 +01:00
Gary Allen
095d1e317c Add wxGridSelectNone selection mode
In this mode the user can't select any cells at all in wxGrid.
2020-10-31 17:01:36 +01:00
PB
f57f214122 Remove BCC-specific hdrstop pragma from everywhere 2020-10-12 21:58:37 +02:00
Vadim Zeitlin
be2a61519b Merge branch 'grid-selected'
Split the wxGrid RANGE_SELECT event into separate SELECTING and SELECTED
events.

See https://github.com/wxWidgets/wxWidgets/pull/2028
2020-08-31 14:55:56 +02:00
Vadim Zeitlin
d41539ef05 Merge branch 'fix-grid-resizing'
Fix bugs in wxGrid mouse handling and simplify the code.

See https://github.com/wxWidgets/wxWidgets/pull/2018
2020-08-31 14:53:37 +02:00
Ilya Sinitsyn
0e8ca0c8f9 Fix the cursor mode switching in wxGrid mouse move event handler
Allow switching between row and column resizing modes in mouse move event
handler.
2020-08-24 02:09:01 +02:00
Ilya Sinitsyn
d6aec06150 Process the wxGrid mouse click depending on the current mode
Simplify the code of wxGrid::DoGridCellLeftDown() and make it more
correct by using m_cursorMode instead of duplicating (not 100%
correctly) the logic used to set it in DoGridMouseMoveEvent().

If the assumption that m_cursorMode is already set by the time
DoGridCellLeftDown() is called turns out to be wrong, e.g. when wxGrid
is used on touch screens, we would need to refactor these functions to
extract the code determining m_cursorMode from the mouse location into a
separate function that would be called from both.

Note that this commit is best viewed with "git diff -w" to see how little
has really changed.
2020-08-24 02:08:54 +02:00
Vadim Zeitlin
9765b6d58e Send SELECTING events while selecting rows/columns too
Generalize the changes of 415f080c80 (Split wxGrid RANGE_SELECT event
into SELECTING and SELECTED, 2020-07-27) to the case when the mouse is
dragged over row or column headers: also send SELECTING events while
dragging and a SELECTED event at the end, whether it's due to releasing
the mouse button or losing mouse capture.
2020-08-21 16:10:40 +02:00
Vadim Zeitlin
408ebfd253 Capture mouse while selecting rows/columns too
Change the logic in ChangeCursorMode() to explicitly exclude the modes
for which the mouse should not be captured, as CaptureMouse() should be
called in most cases (and ideally for all of them in the future) and do
capture it for WXGRID_CURSOR_SELECT_{ROW,COL} too, if only to be
notified about mouse capture loss.
2020-08-21 15:54:47 +02:00
Ilya Sinitsyn
39725cabd4 Fix wxGrid selecting mode ending condition 2020-08-20 16:56:03 +02:00
Ilya Sinitsyn
0a2c62fc5c Remove the selecting mode flag from wxGridSelection
Remove m_isSelecting and StartSelecting() from wxGridSelection to avoid
inconsistency of wxGridSelection selecting mode state with wxGrid state,
as wxGrid already has m_isDragging field which tells it if the selection
state is final or not.

Instead, just allow wxGrid to specify the event to send from
ExtendCurrentBlock().

We still need a separate EndSelecting() for sending the final
wxEVT_GRID_RANGE_SELECTED event, but send it only for the last selection
block, and not all the selected blocks, as this makes more sense (there
should be one SELECTED event for each block and it was already sent for
the other blocks before) and is consistent with the events generated
when performing the same actions from keyboard.
2020-08-20 16:56:03 +02:00
Daniel Kulp
415f080c80 Split wxGrid RANGE_SELECT event into SELECTING and SELECTED
This will allow the applications that are only interested in the final
selection to ignore the intermediate SELECTING events, which are now
sent as soon as the selection changes while dragging the mouse, and only
handle the final SELECTED ones, when the drag is over.
2020-08-20 16:56:03 +02:00
Scott Talbert
9be1f86ca0 Fix regression in wxGrid::DeselectRow() and wxGrid::DeselectCol() 2020-08-13 20:01:45 -04:00
Vadim Zeitlin
8e126d2cd6 Don't call RefreshRect() with negative size in wxGrid code
Don't bother trying to refresh areas beyond the visible part of the
window: not only it's useless, but it also results in debug warnings
from Cairo/pixman due to the use of negative rectangle width/height.

Closes #18848.
2020-07-23 16:21:42 +02:00
Ian McInerney
b256aa6956 Replace wxEVT_GRID_HIDE_EDITOR usage with CallAfter
This simplifies the code by removing the need for a special event,
and also means the combox popup handler is no longer needed to reset
the inSetFocus flag for the closing handler.
2020-07-14 12:28:13 +01:00
Vadim Zeitlin
a9b419af51 Fix code determining the rows to refresh in wxGrid::SetColSize()
The changes in 15de1a4cf4 (Optimize refresh when resizing grid rows or
columns, 2020-02-18) incorrectly translated XToPos() used in
SetRowSize() to YToRow(), which compiled due to an implicit conversion
of m_gridWin pointer to bool, but did the wrong thing, as the wrong grid
window could be used for a frozen grid.

Fix this by switching to internalYToRow() which actually does what the
original code tried to do.

Co-authored-by: Artur Wieczorek <artwik@wp.pl>
2020-07-05 15:04:00 +02:00
Vadim Zeitlin
97924a3b81 Use internalYToRow() instead of YToRow(true)
No real changes, just be consistent: as we have internalYToRow() macro
which passes true as "clipToMinMax" YToRow() parameter instead of the
default false, use it everywhere instead of using it almost everywhere
and still using YToRow(true) and XToCol(true) explicitly just once each.

Also add a comment explaining the difference between internalAToB() and
public AToB() functions.
2020-07-05 14:58:02 +02:00
Vadim Zeitlin
13e1b384e7 Fix another possible bug in wxEVT_GRID_CELL_CHANGED handling
Even when wxEVT_GRID_CELL_CHANGED is really vetoed, it's still possible
that m_currentCellCoords was changed by the handler, so use the row/col
coordinates of the cell that was really changed instead of the possibly
different m_currentCellCoords value to avoid a bug similar to the one
fixed by the previous commit.
2020-06-30 19:15:15 +02:00
Vadim Zeitlin
8445d1993e Fix bug in workaround for event handlers deleting wxGrid cells
The changes of e6e6dbe077 (Fix problems due to deleting grid cells in
the event handlers, 2020-05-02) fixed the bug (see #18731), but
introduced another one in place: if wxEVT_GRID_CELL_CHANGED handler
deleted any cells, wxGrid code could mistakenly restore the "old" cell
value (actually it restored the value for a different cell, as the
current cell coordinates necessarily changed too in this case).

This bug became more visible after the addition of activatable editors
as the new code asserts, instead of trying to restore the old value, if
wxEVT_GRID_CELL_CHANGED is vetoed, which also resulted in asserts if the
handler deleted the current cell instead.

Fix this by separating the cases of event being really vetoed and of the
event handler deleting the cell for which the event was generated and
handle the latter separately from the former where it matters.

This commit is best viewed ignoring whitespace changes.
2020-06-30 19:04:52 +02:00
Vadim Zeitlin
f877106663 Use EventResult enum instead of magic numbers in wxGrid code
This is more verbose, but also much more clear (and so allows to remove
some previously necessary comments).

No real changes, even keep the same values for the enum elements as were
previously used: this is probably unnecessary but do it just to minimize
changes.
2020-06-30 18:51:13 +02:00
Vadim Zeitlin
3cc3236f10 Add support for "activatable" editors to wxGrid
This is useful for editors which don't really need to show any control
as they can change their value directly and will be used to reimplement
wxGridCellBoolEditor in the upcoming commits.
2020-06-30 02:25:14 +02:00
Vadim Zeitlin
4e62b24042 Fix bug with Shift-Enter selecting cells while editing
It was unexpected that pressing Shift-Enter while an editor was active
didn't close it, but just selected the cell below (and then the one
below it if pressed again and so on), so now always finish editing when
it's pressed.

It could be argued that it's still unexpected for Shift-Enter to select
the cell below after closing the editor, but this is consistent with how
Tab works, and so shouldn't be as confusing as the old behaviour.
2020-06-28 23:14:32 +02:00
Vadim Zeitlin
3747169660 Remove apparently unnecessary wxGrid::m_inOnKeyDown
Although this variable, and a check for it in OnKeyDown(), was present
since the first version of this code added back in f85afd4e46 (Added new
wxGrid classes[...], 1999-10-06), there doesn't seem to be any
indication that it has ever been needed, so remove it to simplify the
code and make it possible to add early returns to this function easily.

No real changes yet.
2020-06-28 22:53:10 +02:00