Commit Graph

696 Commits

Author SHA1 Message Date
Vadim Zeitlin
15de1a4cf4 Optimize refresh when resizing grid rows or columns
This avoids visible flickering of column/row labels when row/column is
interactively resized.
2020-03-11 21:59:15 +01:00
Vadim Zeitlin
a004b8ba24 Remove unnecessary Refresh() from wxGrid::DoEndDragResizeLine()
The grid is completely refreshed by the call to SetLineSize(), so doing
it again here is completely unnecessary.
2020-03-11 21:59:15 +01:00
Vadim Zeitlin
ebbadae09a Double buffer wxGridWindow drawing
This eliminates noticeable flicker under MSW when changing selection,
for example.
2020-03-11 21:59:15 +01:00
Vadim Zeitlin
c2b0edefbd Also remove unused wxGrid wxEVT_ERASE_BACKGROUND handler
It is never used anyhow, as wxGrid is entirely covered by its children
windows.
2020-03-11 21:59:15 +01:00
Vadim Zeitlin
e671386d1a Use wxBG_STYLE_PAINT for wxGridWindow
This is more explicit, efficient and simpler than defining an empty
wxEVT_ERASE_BACKGROUND handler, which is not needed any longer.
2020-03-11 21:59:15 +01:00
Vadim Zeitlin
a5807b8fcf Remove unnecessary wxGrid::OnPaint()
This method was explicitly defined to do nothing, so just remove it.

No real changes.
2020-03-11 21:59:15 +01:00
Vadim Zeitlin
2e64ba6d6e Also add wxGridCellEditorPtr and wxGridCellRendererPtr
This is similar to the previous commit and replaces manual calls to
DecRef() on the renderers/editors with the use of smart pointers for
them too.
2020-02-08 15:14:24 +01:00
Vadim Zeitlin
5f34b1749e Use wxGridCellAttrPtr instead of manual DecRef() calls
Provide GetAttrPtr() and GetCellAttrPtr() convenience functions that can
be used instead of the original Ptr-less versions to avoid the need to
manually call DecRef() on the returned wxGridCellAttr pointers.

No real changes, just simplify the code and make it safer.
2020-02-08 14:55:36 +01:00
Ilya Sinitsyn
e0c09c8438 Only overflow left-aligned cells in wxGrid
Doing it for cells using a different alignment doesn't work correctly
and it's not clear whether it really makes sense, so just don't do it at
all for now.

Closes https://github.com/wxWidgets/wxWidgets/pull/1726
2020-02-07 19:35:35 +01:00
Ilya Sinitsyn
a40acbb28e Add CanOverflow function to wxGridCellAttr
Add function to determine whether the cell will draw the overflowed text
to neighbour cells. Note that only left aligned cells currently can overflow.
2020-02-07 19:34:50 +01:00
Vadim Zeitlin
2f2ea1d193 Merge branch 'im/osx_fixes' of https://github.com/imciner2/wxWidgets
wxOSX fixes for wxGrid background, wxDataViewCtrl with wx[HV]SCROLL
styles and changing the window level.

See https://github.com/wxWidgets/wxWidgets/pull/1717
2020-02-04 02:31:38 +01:00
Vadim Zeitlin
276a815ed5 Merge branch 'grid-ellipsize-offset' of https://github.com/thesiv/wxWidgets
Fix text cropping when using ellipsization in wxGrid.

See https://github.com/wxWidgets/wxWidgets/pull/1720
2020-02-04 02:14:19 +01:00
Vadim Zeitlin
e171757160 Merge branch 'grid-selecting'
Fix several problems related to selecting cells from keyboard in wxGrid.

Closes https://github.com/wxWidgets/wxWidgets/pull/1719
2020-02-04 02:13:20 +01:00
Ilya Sinitsyn
45839843e6 Use a constant for the wxGrid text margin
Use a constant instead of a hardcoded value for the text margin.
2020-02-04 05:36:24 +07:00
Ilya Sinitsyn
72824bc269 Fix text cropping when using ellipsization in wxGrid
A text is cropped for cells with ellipsization enabled when width of the
cell nearly equal to width of the text because wxGrid::DrawTextRectangle
function variant with the parameter of type wxArrayString adds the offset
before actually drawing the text using dc.DrawText or dc.DrawRotatedText.
2020-02-04 05:36:24 +07: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
5b797618a1 Merge WXK_HOME and WXK_END handling in a single case
There are more commonalities than differences between the handling of
these 2 keys and it's better to have a single version of this code.

No changes in behaviour.
2020-02-01 02:23:05 +01:00
Vadim Zeitlin
c7707a16c7 Simplify check for current cell in Home/End handling code
Prefer to just test whether we have it instead of breaking out of the
case if we don't, this is slightly more straightforward.

No real changes.
2020-02-01 01:57:56 +01:00
Ilya Sinitsyn
6e6eb799c8 Implement wxGrid cells selection for Home and End keys
Select cells if Shift is pressed when handling Home and End keys
2020-02-01 01:53:59 +01:00
Ilya Sinitsyn
68ccc77e20 Fix wxGrid Home and End keys handling
Take into account that rows and columns may be hidden and columns also can be
reordered.
2020-02-01 01:53:59 +01:00
Ilya Sinitsyn
d455c5b99e Fix making the wrong wxGrid cell visible when selecting
We should make visible the cell of the corner of the current selected block.

Also fix names of the wxGrid::UpdateBlockBeingSelected parameters because
actually passed сщщквы are of any opposite selection block corners.
2020-02-01 01:53:59 +01:00
Ian McInerney
278d98b2b6 OSX: Draw background in wxGrid cell when editor is open
This was removed when Quick Draw was in use due to an issue,
but Quick Draw has been removed, so re-enable it.
2020-01-23 23:21:08 +00:00
Artur Wieczorek
28098259a8 Suppress MSVC++ performance warning
MSVC++ doesn't seem to honour implicit int -> bool conversion and raises
warning C4800: "'int': forcing value to bool 'true' or 'false' (performance
warning)".
2020-01-19 09:56:24 +01:00
Vadim Zeitlin
46042843e8 Implement support for ellipsization mode in wxGrid
Add another wxGrid::DrawTextRectangle() overload, taking wxGridCellAttr
and ellipsizing the string if necessary, i.e. if the fitting mode of
this attribute indicates that we should do it.

Switch the code of all renderers for which it makes sense to use
ellipsization to use the new overload.
2020-01-11 19:15:15 +01:00
Vadim Zeitlin
f13085441c Add wxGridFitMode and functions working with it
Replace "bool overflow" flag with a class allowing to specify the same
overflow/clipping behaviour currently, but also allowing to extend it,
notable to add ellipsization support, in the future.

Preserve the existing API by reimplementing it in terms of the new one.

Also update the same to demonstrate a cell which always overflows,
independently of the default cell behaviour.
2020-01-11 18:02:12 +01:00
Vadim Zeitlin
e3eb05df72 Skip not handled mouse events in wxGrid code
Unhandled mouse events should be skipped. Otherwise wxEVT_CONTEXT_MENU
event couldn't be generated by right clicking anywhere inside wxGrid and
could be only generated for the main grid part (but not the labels) by
pressing Shift-F10 under MSW.

Closes https://github.com/wxWidgets/wxWidgets/pull/1697
2020-01-09 23:26:46 +01:00
Vadim Zeitlin
55f148a2ea Avoid asserts when moving mouse in empty wxGridColLabelWindow too
The changes of the previous commit were insufficient, as we could also
use an invalid column index when handling mouse event in an empty grid.

Fix this by checking for the line validity in PosToEdgeOfLine() instead
of adding another ad hoc check to wxGridColLabelWindow itself, as it
seems reasonable for this function to verify that it uses valid indices.

See #18629.
2019-12-14 00:03:01 +01:00
Vadim Zeitlin
9c1e8fde8f Avoid asserts when painting empty wxGridColLabelWindow
When the grid is empty, XToCol() has no choice but to return invalid
index (because there are no valid ones) when it's called from the
drawing code and passing such indices to GetColPos() results in an
assert, which is fatal inside wxEVT_PAINT handler.

Just short-circuit all this code by not doing anything in the case of
empty grid. This is sloppy, but simpler and more robust than any
alternatives.

Closes #18629.
2019-12-13 16:19:47 +01:00
Vadim Zeitlin
90d547feb6 Don't redraw current cell when the grid is frozen
Don't update the grid appearance when inside a sequence of batch
operations, it will be updated at the end of it anyhow and doing it in
the middle only results in extra flicker.
2019-12-03 02:56:46 +01:00
Vadim Zeitlin
e0b8ef85f2 Don't use invalid grid cell coordinates when deleting grid rows
Since the changes of dda6aa6bdc wxGrid
code could ask the grid table for the data of an invalid cell due to
redrawing the old, and now possibly invalid, current cell from inside
SetCurrentCell() called from wxGrid::Redimension().

Fix this by explicitly resetting the old current cell to an invalid
value when changing it in UpdateCurrentCellOnRedim().

Also avoid calling SetCurrentCell() entirely if the current cell doesn't
change, as this is just completely unnecessary and results in a possible
unexpected wxEVT_GRID_SELECT_CELL event.

See https://github.com/wxWidgets/wxWidgets/pull/1546
2019-12-03 02:47:08 +01:00
Vadim Zeitlin
811be7ced7 Fix wxGridCellAttr::GetNonDefaultAlignment() for invalid inputs
The recent change of 19844d27ac fixed this
function for valid values of input/output parameters on input, but broke
it if the parameters had invalid value: in this case, we still need to
fill them even if this attribute doesn't have any specific alignment of
its own.

Account for this case too now, explain the logic of this function in the
comments inside it and extend the unit test to check for this case too.

Now the function should really conform to its documented (and expected,
including by the existing code in various grid renderers) behaviour.

Closes https://github.com/wxWidgets/wxWidgets/pull/1665
2019-12-03 02:26:49 +01:00
Vadim Zeitlin
abc8841f0b Use default wxCheckBox size in wxGridCellBoolEditor
Using wxRendererNative::GetCheckBoxSize() as the size of wxCheckBox just
doesn't work with GTK 3, as the control has additional padding between
its actual contents and the focus rectangle, which means that its actual
size must be greater than the size to be passed to DrawCheckBox() in
order to draw a checkbox of the same size.

However it isn't really necessary to resize wxCheckBox at all, it's
enough for DrawCheckBox() to produce a check mark of the same size as
that shown in a default-sized wxCheckBox and this does work in wxGTK.

So keep the default size of wxCheckBox to make everything work.

This means wxGetGridCheckBoxRect() is not useful any more, so replace it
with wxGetContentRect() which just positions a rectangle of the given
size inside another one (this should probably be moved somewhere else,
as it's more general than wxGrid).
2019-11-29 04:57:59 +01:00
Vadim Zeitlin
ab02d36e10 Account for vertical alignment in wxGetGridCheckBoxRect() too
Do it if only for consistency with the horizontal alignment.
2019-11-28 02:14:50 +01:00
Vadim Zeitlin
6b63016fb2 Use helper wxRect::CentreIn()
No real changes, just make the code a bit more concise and clear.
2019-11-28 02:14:50 +01:00
Vadim Zeitlin
57f89c626c Fix the code which tried to account for too small cell rect
It didn't actually manage to do it as it used wrong comparison.
2019-11-28 02:14:50 +01:00
Vadim Zeitlin
4f6b29fb0c Remove "X" suffix from GRID_CELL_CHECKBOX_MARGIN_X
The same margin will be used in the vertical direction too.
2019-11-28 02:14:50 +01:00
Vadim Zeitlin
851d11ba2c Determine the checkbox size in wxGetGridCheckBoxRect() itself
It doesn't make much sense to pass the size to the function supposed to
compute it, so call wxRendererNative::GetCheckBoxSize() from the
function itself instead of forcing its callers to do it.

No real changes.
2019-11-28 02:14:50 +01:00
Ilya Sinitsyn
3ca9491c5f Improve grid editors placing
Remove the code in wxGrid::ShowCellEditControl() which moves grid
editors unnecessarily and also remove workarounds that were required
because of it in the editors SetSize() functions.

This helps to ensure that the editor is placed at the same position the
renderer draws the cell value, so that it doesn't jump around annoyingly
when editing starts (which was especially noticeable for boolean-valued
cells).
2019-11-28 02:14:50 +01:00
Vadim Zeitlin
19844d27ac Fix default attribute wxGridCellAttr::GetNonDefaultAlignment()
This function is not supposed to overwrite the given alignment values
unless the alignment is specifically set for the given cell, but it
always overwrote them when called on m_defaultCellAttr, i.e. the
attribute used by the cells that don't have any special attribute.

This meant that custom attributes had to be set (or, more efficiently, a
custom attribute provider returning non-null attributes for all cells
had to be used) previously just to make the right alignment used by
default by number or date renderers work.

Fix this by ignoring the values set in the default attribute in this
function.

Also add a unit test (which required adding a special helper class just
to allow testing wxGrid::GetCellAttr() used by the renderers) that used
to fail but passes now.
2019-11-04 00:35:32 +01:00
Vadim Zeitlin
ad6799f249 Merge branch 'grid-uitests-gtk'
Fixes to wxUIActionSimulator allowing the tests using it to work for
wxGrid in wxGTK.

And some improvements and bug fixes to wxGrid itself.

Closes https://github.com/wxWidgets/wxWidgets/pull/1609
2019-10-21 21:12:01 +02:00
Vadim Zeitlin
16619c5e77 Use DIPs for the margins around text in wxGrid columns
Improve the appearance on high DPI displays where the margins were
previously too small under MSW.
2019-10-19 18:31:50 +02:00
Vadim Zeitlin
f29b6564b1 Really fix recent regression in grid content autosizing
Fix autosizing broken in 3c72396a36 and
not fully fixed by f7e335c031.

Simplify the code to make it more obviously correct, by separating the
computation of the extent suitable for the label and determining the
size to use taking into account the extents of both the column data and
the its column.

Also add the unit test checking that auto-sizing works correctly in all
the different cases.

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

Co-Authored-By: Ilya Sinitsyn <the_siv@mail.ru>
2019-10-19 18:28:03 +02:00
Vadim Zeitlin
b4dee76b4c Set focus to the main grid window in wxGrid::SetFocus()
After changing wxGrid to not inherit from wxPanel, this needs to be done
explicitly now.
2019-10-18 04:00:46 +02:00
Vadim Zeitlin
9a424602e4 Stop deriving wxGrid from wxPanel
This is unnecessary as TAB navigation is not supposed to work between
wxGrid children and actually harmful as this resulted in SetFocus()
doing nothing, instead of setting focus to wxGridWindow, if the focus
was on wxGrid itself for some reason (this happened at least in the grid
unit tests and resulted in failures because the in-place editor didn't
appear as expected).
2019-10-18 04:00:46 +02:00
Maarten Bent
05e0fad687 Resolve some recently introduced warnings 2019-10-13 08:34:30 -07:00
Vadim Zeitlin
5e3ba81bbf Revert accidentally committed wxGrid changes
These changes were included in 18e05aeeee
accidentally, revert them for now (they will be recommitted later with a
proper commit message).

See https://github.com/wxWidgets/wxWidgets/pull/1601
2019-10-12 16:08:24 +02:00
Olly Betts
18e05aeeee Remove no-op uses of wxNO_FULL_REPAINT_ON_RESIZE
This behaviour has been the default and this constant 0 since
e441e1f4e8 which was over 16 years ago.

Closes https://github.com/wxWidgets/wxWidgets/pull/1601
2019-10-11 14:12:43 +02:00
Ilya Sinitsyn
dc99faa096 Fix focus issue with composite grid editor windows
The grid editor window can be composite, so check whether it or one of
its children focus has focus when determining whether we should set the
focus to the grid when the grid editor is being hidden, otherwise the
focus was simply lost when such an editor was hidden.

Closes https://github.com/wxWidgets/wxWidgets/pull/1599
2019-10-09 19:53:19 +02:00
Ilya Sinitsyn
86f14a033c Fix the issue with the grid cell editor special chars handling
Some of the grid cell editors (all of them not based on wxTextCtrl
basically, i.e. wxGridCellBoolEditor, wxGridCellChoiceEditor,
wxGridCellEnumEditor) didn't process Esc, Enter and Tab under MSW,
making them inconvenient to use.

Fix this by adding wxWANTS_CHARS style flag to ensure the editors do get
these keys.

Closes https://github.com/wxWidgets/wxWidgets/pull/1598
2019-10-09 16:57:25 +02:00
Ilya Sinitsyn
8971321542 Send the autosize column event for grid native header columns
Send wxEVT_GRID_COL_AUTO_SIZE on double clicking on a separator line of
the grid native header to allow override default behaviour.
2019-10-07 22:25:10 +02:00