This check was introduced back in 283b7808d8 (added support for readonly
cells and 3d border drawing, 2000-02-16), but was wrong even then and
remained wrong ever since: we must not set m_cellEditCtrlEnabled to true
when the current cell is read-only, so there is no need to check for the
latter condition if m_cellEditCtrlEnabled is indeed true.
Ensure that we really never erroneously set m_cellEditCtrlEnabled for
the read-only cells by replacing an wxASSERT_MSG checking for this in
EnableCellEditControl() with wxCHECK_RET().
Also explicitly document this function precondition, also added back in
b54ba67107 ([...] added CanEnableCellControl() and use it before calling
EnableEC, 2000-02-17) but never documented so far.
This code seems to have been there ever since da6af900f1 (Added
drag-shrinking, 2000-02-04), but while it probably made sense back then,
it lost its purpose a long time ago as the cell editor is now not only
hidden, but also disabled when drag-resizing starts, so it doesn't make
sense to attempt showing it back when the mouse button is released: it's
never going to do anything (and didn't).
Just remove this code, as hiding the editor while drag-resizing is not
the behaviour we want from the UI point of view anyhow. And, again,
removing it doesn't actually change anything in the current version of
the code.
This allows to fold the last DoSaveEditControlValue() call into this
function, so that it's only called from DoAcceptCellEditControl() or
from SaveEditControlValue() (which is public, and hence can't be
changed, even if its behaviour doesn't make much sense).
This commit means that m_cellEditCtrlEnabled is now reset to false when
AcceptCellEditControlIfShown() is called, which was not the case before,
but this seems to make sense, as we shouldn't be just hiding the editor
while leaving it enabled, and, also, doesn't really seem to change
anything as hiding the editor indirectly results in a call to
DisableCellEditControl(), via wxGrid::OnHideEditor(), and so it was
actually already reset before -- but now this happens slightly earlier
and more explicitly.
This is just another refactoring in order to avoid duplicating calls to
HideCellEditControl() and SaveEditControlValue() in several different
places.
Also call DoSaveEditControlValue() because if the editor is shown, it is
also necessarily enabled and there is no need to check for this.
No real changes, just simplify the code by using a single function to
retrieve the editor to use for the current cell.
This also allows to get rid of a few temporary variables, further
amplifying the simplification.
Pressing Esc while double clicking on the column separator in the native
header in wxGrid could result in a crash due to using invalid index when
calling GetColLeft(m_dragRowOrCol) in GetPositionForResizeEvent() called
from DoHeaderEndDragResizeCol() because m_dragRowOrCol had been already
reset to -1.
Guard against the crash with a check in GetPositionForResizeEvent()
itself and also add a check to DoHeaderDragResizeCol() to avoid calling
the former function in this case.
Reproducing the original problem is relatively simple as it's enough to
just keep double clicking a column separator while also pressing Esc,
but catching it under debugger is much more complicated and so it's not
really clear how exactly does this happen, but tracing shows that the
native control just decides to generate two HDN_ENDTRACK messages
without any intervening HDN_BEGINTRACK, so it doesn't seem like we can
do anything else than just silently ignore the unwanted HDN_ENDTRACK, as
it's done in this commit.
Define the common logic for positioning editors not taking the entire
cell area (i.e. basically anything other than wxGridCellTextEditor) in
the new DoPositionEditor() function.
Also use the cell and editor alignment to decide where to position the
control if it's smaller than the cell, as it looks better if e.g.
wxGridCellDateEditor appears near the place where the date is displayed
instead of being centered in the middle of a wide column.
Even when resizing rows by dragging their edges was disabled via
DisableDragRowSize(), it was still possible to try to resize them when
the mouse was over the cell corner.
Fix this and remove the special case for the corners entirely, it's not
necessary as the existing cases cover this one already.
Just rearrange them in the right order to prefer column resizing, as
this seems to be a much more commonly used operation than row resizing.
It is necessary to do it since the switch to double buffering wxGrid
painting in ebbadae09a (Double buffer wxGridWindow drawing, 2020-01-28)
as even a "full cell" editor such as wxGridCellTextEditor still doesn't
fill the entire cell, as there are margins around it, and the backing
bitmap could keep whatever junk happened to be there if we didn't erase
it, so do erase it now.
Remove the code doing the same thing from ShowCellEditControl(),
however, as it's redundant and doesn't do anything except creating some
flicker, and also doesn't work on the platforms not supporting the use
of wxClientDC anyhow.
This just looks very strange if the row has much bigger height than
default and it already isn't done for other editors, e.g. those using
wxSpinCtrl or wxDatePickerCtrl, for the same reason, so this is also
more consistent.
There is no need to check that the rectangle fits as it's done by wxGrid
itself, so just use a single wxRect::CenterIn() call instead of several
lines doing it manually.
No real changes.
Currently 1 argument for the constructor is only used in an #ifdef
block, and so some compilers give an unused parameter warning. Instead
use the parameter with a switch statement to avoid the warning.
This code never worked (as proved by the conversion in it which was
wrong by a factor of 1e12) and should never be needed anyhow.
Simplify configure and give an error, not warning, if neither
nanosleep() nor usleep() are available, as otherwise we'd just get a
build error later when compiling utilsunx.cpp later.
The length of a string in wxSTCListBoxD2D::OnDrawItemText was being
calculated twice - first when measured and again when drawn. Instead
store the length the first time it is calculated. Also, pass a copy of
the string in wx2stclen to allow the calculation to work in ASCII
builds.
To remove code duplication in the OnDrawItem in wxSTCListBox and
wxSTCListBoxD2D, move the code for drawing just the text to a new
virtual method named OnDrawItemText. Then have the OnDrawItem method
call the new function.
Due to a confusion between DIPs and Pts, the stc autocomp window was
a little larger than it should have been when Direct2D was used.
Instead use the methods defined in SurfaceD2D so the popup will be
measured and drawn the same way the main editor window is.
The stc autocomp popup is supposed to report the location at which text
is drawn with the wxSTCListBox::CaretFromEdge function. To return the
correct value, the popup needs to compute the largest width of any
bitmap used for icons in the popup since text is drawn to the right of
the popup's images.
Previously the wxSTCListBox tried to compute this largest width when
the listbox items were set. However, Scintilla actually calls
CaretFromEdge before setting the listbox items. Consequently the
CaretFromEdge was returning a value that assumed zero width for the
list's images since images had not been set yet.
Instead, keep a running tally of the widest image width when images are
registered. This means that this variable must be moved to the
wxSTCListBoxVisualData class since that is where image registration is
handled. Also track the largest image height since that is also needed.
On Retina display macs, those values can contain halves. If you round
them down, you end up cutting off content (e.g. cutting off the last
letter in a text label).
Closes https://github.com/wxWidgets/wxWidgets/pull/1905
GetPaths/GetFilenames() must be used instead when more than one file
could be selected: document this and assert if the wrong functions are
called.
Closes https://github.com/wxWidgets/wxWidgets/pull/1883
Don't make it larger than 150% than its normal width and also don't make
it larger than its normal width at all if it's not going to be large
enough to cover the entire cell anyhow -- this just looks strange, as
the editor is both too wide and not wide enough.
The existing logic for adjusting the editor window position by moving it
was flawed as it didn't take into account the fact that the editor could
decide to use a different (and usually bigger) rectangle than the one we
provided it with, if it doesn't fit into the given one. Fix it to ensure
that the editor window is fully inside the grid client area by moving it
only after letting it choose its own size.
The existing code was also inconsistent as CalcDimensions() didn't take
any adjustment to the cell rectangle done in ShowCellEditControl() into
account at all and always just blithely assumed it was positioned at the
cell top left corner, which resulted in wrong virtual size calculation
and could make scrollbars appear when starting editing, as happened in
the "Bugs table" example of the grid sample when showing any comboboxes
in the last grid row. Fix this code to use the actual editor rectangle
instead.
This is another attempt to get rid of the flicker when using the native
header control with wxGrid under MSW and avoid calling UpdateColumn(),
which is currently implemented in a very inefficient way in wxHeaderCtrl
under MSW, during interactive resizing.
See #18794.
Clicking on (or near) the grid column or row edges was handled specially
to allow dragging them in order to resize the column or row, but this
doesn't need to be done if drag-resizing the columns or rows is not
allowed in the first place and resulted in surprising user-visible
behaviour: e.g. when using row selection, clicking mostly anywhere in
the row selected it, except if the click happened to be between the two
columns, in which case it didn't.
Fix this and always select the row in such scenario now.
Unfortunately, doing this required adding yet more CanDragXXX()
functions in addition to the already impressive panoply of them in
wxGrid, but we need CanDragGridColEdges() as none of the existing
functions checked for m_useNativeHeader (there was instead an ad hoc
check for it directly in the mouse handling code) and the row version
had to be added for symmetry.
Although the native (single line) text control understands Alt-Backspace
as an accelerator for "Undo", using it was not really practical because
it resulted in an annoying beep due to Alt-anything trying to find an
item with matching mnemonic in the menu.
Work around this native (mis)feature by pretending to handle this
particular Alt-combination ourselves when the currently focused control
is text-like, as indicated by it overriding WXGetTextEntry() -- this is
not ideal, but seems to be the best we can currently do. An alternative
could be to just mark Alt-Backspace as handled unconditionally.
Gradually reduce the page increment in the case of a narrow range for
convenience and to limit possible EVT_SPIN_UP/EVT_SPIN_DOWN ambiguity
when wrapping is on.
Closes https://github.com/wxWidgets/wxWidgets/pull/1900