Commit Graph

442 Commits

Author SHA1 Message Date
iwbnwif
472aec2d7e Add support for using native spell checking in wxTextCtrl
Add wxTextCtrl::EnableSpellCheck() and implement it for wxMSW and
wxGTK3.

Closes #17544.
2021-08-23 14:15:38 +02:00
Vadim Zeitlin
1799922d0e Implement EmptyUndoBuffer() for wxTextCtrl in wxMSW too
The relevant code was already present in MSWCreateText(), so just
extract it into its own function.
2021-08-20 16:58:38 +01:00
Vadim Zeitlin
8004002e5e Fix handling keys also used as accelerators in wxMSW wxComboBox
wxComboBox::MSWShouldPreProcessMessage() didn't take into account many
keys that must be handled in wxComboBox even if they're used as
accelerators, including plain (i.e. without Ctrl modifier) Delete, Home
and End that are used by the embedded text control, if there is one.

Fix this by reusing wxTextCtrl::MSWShouldPreProcessMessage() which
already handled these keys correctly, by moving it to wxTextEntry, which
can be used from both classes.

Also add a check for wxCB_READONLY to prevent overriding the
accelerators using the keys that the combobox doesn't need when there is
no text control in it.

Closes #19227.
2021-07-24 12:41:49 +01:00
Vadim Zeitlin
f31a745909 Remove unnecessary c_str() from wx var arg functions arguments
Using c_str() for arguments to wxString::Printf(), Format() and
wxLogXXX() is useless since wx 2.9 days, so simply remove them.

No real changes, this is just a (long due) cleanup.
2021-07-04 15:08:13 +01:00
Vadim Zeitlin
1248829802 Implement support for Ctrl+Backspace in plain EDIT controls
This shortcut is undocumented, but works in rich edit controls and even
in plain ones if they use SHAutoComplete(), so support it in all
controls because this is what people expect.
2021-04-08 00:26:41 +01:00
Vadim Zeitlin
0d04792116 Show full text in single line MSW wxTextCtrl if possible
A single line MSW wxTextCtrl created with a value too long to fit into
it continued showing the value only partially even if its size was
subsequently increased to allow the entire value to be shown.

This apparently happens because changing the native EDIT control size
doesn't affect its (horizontal) scroll offset. Moreover, there doesn't
seem to be any way to explicitly tell the control to update it neither,
except for changing its text.

So do change its text every time its width changes, as long as it is not
visible (because visible jumps in the visible text position could be an
even worse problem than the one we're trying to solve here). This fixes
the originally reported bug at the cost of a bunch of extra calls to
DoWriteText() which should hopefully be not too expensive for single
line controls that don't typically contain that much text.

Closes #18268.
2021-01-30 20:43:14 +01:00
Vadim Zeitlin
247bb98d07 Generate Enter/Tab events even in readonly MSW wxTextCtrl
Respect wxTE_PROCESS_TAB and wxTE_PROCESS_ENTER flags even for readonly
text controls. Previously there were ignored for them due to the changes
of 080c709f70 (fix for handling TAB presses in readonly text controls,
2002-09-07), but there doesn't seem to be any good reason to do this, so
revert the changes of that commit by removing IsEditable() check from
our WM_GETDLGCODE handler.

We also need to avoid inserting TABs into readonly controls ourselves in
the default wxEVT_CHAR handler, so add a check for IsEditable() there to
compensate for the fact that these events are now received even for the
readonly controls.

This commit is best viewed ignoring whitespace-only changes.

Closes #19064.
2021-01-30 20:42:52 +01:00
Artur Wieczorek
31ae1f8094 Fix build with wxUSE_OLE==0 2021-01-02 10:20:12 +01:00
Vadim Zeitlin
ef9161861d Fix invalid memory read in wxMSW wxTextCtrl::GetLineText()
Don't read before the start of the buffer when getting the text of an
empty line, this was (correctly) flagged as heap error by address
sanitizer.
2020-11-28 16:35:03 +01:00
PB
f57f214122 Remove BCC-specific hdrstop pragma from everywhere 2020-10-12 21:58:37 +02:00
Andreas Falkenhahn
a59901f8f1 Fix bug in CanUndo() returning true after wxTextCtrl creation
For wxMSW text controls with wxTE_RICH2 style, calling SetFont() counts
as an undoable operation, resulting in CanUndo() returning true even if
no "real" changes have been made yet.

Fix this by resetting the undo stack after creating the control using
ITextDocument::Undo().

Unfortunately this interface is not available in MinGW-32, so this fix
can't be used with it.

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

Closes #17524.
2020-08-25 18:10:20 +02:00
Maarten Bent
abb2eb9ed0 Fix -Wmicrosoft-exception-spec warning 2020-04-27 00:33:01 +02:00
Paul Cornett
896512c732 Change fractional point size from float to double
There doesn't seem to be any compelling reason to use float. Using double
is simpler, and avoids otherwise unnecessary float<->double conversions.
2020-04-21 09:00:04 -07:00
Maarten Bent
57d054cf95 Fix font size of rich wxTextCtrl when created on display with non-system DPI
Apply a zoom factor based on the active DPI and the system DPI. On the first
DPI change, revert the scaling factor.
2019-11-08 20:46:47 +01:00
Maarten Bent
4340e46b72 Fix height of rich wxTextCtrl after DPI change
The font of rich controls is not adjusted when the DPI changes, so do it here.
2019-11-05 22:07:04 +01:00
Maarten Bent
05e0fad687 Resolve some recently introduced warnings 2019-10-13 08:34:30 -07:00
Vadim Zeitlin
efc2a9da2d Fix pasting long strings in wxTextCtrl under MSW
Adjust the length limit before pasting to ensure that all text on
clipboard will be successfully pasted, instead of only pasting the part
of it which fits.

Add a unit test checking that this works.

Closes #4646.
2019-10-09 14:40:53 +02:00
Vadim Zeitlin
7a9e969dca Send clipboard events for Ctrl/Shift-{Ins,Del} in rich edit too
The corresponding wxClipboardTextEvent was generated for Ctrl-{C,V,X}
key combinations, but not Shift-{Ins,Del} or Ctrl-Ins ones, which are
also handled by the native control by default.
2019-10-09 01:01:18 +02:00
Vadim Zeitlin
0aaa05ae3a Override Ctrl-A accelerator when wxTextCtrl has focus in wxMSW
This key combination is used for selecting all text, while it's also
relatively common to use it as an accelerator for some menu item.

Resolve the conflict in favour of wxTextCtrl, i.e. let it have this key
when it has focus, while still allowing to use it as an accelerator
otherwise.
2019-09-30 00:20:06 +02:00
Vadim Zeitlin
37be4adec6 Don't change RICHEDIT control font on DPI change
The control seems to somehow react to DPI changes on its own (which is
rather mysterious as we don't forward WM_DPICHANGED to it, so it's not
really clear how does it do it, but it does) and changing its font is
worse than useless, as it's not just redundant, but also resets all the
styles used inside the control and so is really undesirable.

Hence override the just added MSWUpdateFontOnDPIChange() to do nothing
for rich edit controls, while still updating the font for the plain EDIT
ones (which is required as they don't scale correctly on their own).
2019-09-28 23:37:01 +02:00
Vadim Zeitlin
0146c47a7f Generate wxEVT_TEXT_ENTER for Enter key on Numpad too in wxMSW
Handle WXK_NUMPAD_ENTER in the same way as we already handle WXK_RETURN.

Closes #18504.
2019-09-15 14:31:42 +02:00
Vadim Zeitlin
9bab9d8da8 Don't activate default button on Enter in multiline wxTextCtrl
Restore behaviour until c43e0fa123 and let
Enter presses in multiline text controls perform their default function
in the control instead of closing the dialog.

Make the unit test more discerning to check for this.
2019-09-10 18:48:20 +02:00
Vadim Zeitlin
84f29ce472 Don't send EVT_TEXT_ENTER to controls without wxTE_PROCESS_ENTER
wxMSW always sent this event to multiline text controls, even when they
didn't have wxTE_PROCESS_ENTER style, contrary to what was documented.

Avoid sending this event unless wxTE_PROCESS_ENTER is used and add unit
tests checking that multiline text controls don't get it without this
style (but still do get it with it).
2019-09-10 18:48:20 +02:00
Maarten Bent
13cb9d41d8 Require wxWindow parameter for wxNativeFontInfo constructor in MSW
Use the DPI of the window to determine the correct font pointSize.

To not break user code, add a default argument when not building the library.
2019-09-05 23:14:25 +02:00
Vadim Zeitlin
8dc3c38fad Set event object in wxMSW wxTE_RICH control wxContextMenuEvent
Add forgotten SetEventObject() call.

Closes #18460.
2019-08-22 12:44:09 +02:00
Vadim Zeitlin
fb2c17c193 Merge remote-tracking branch 'sunset/process-enter'
Fix wxTE_PROCESS_ENTER logic for wxMSW and wxGTK too.

See https://github.com/wxWidgets/wxWidgets/pull/1415

Closes #18273.
2019-07-26 18:02:08 +02:00
Vadim Zeitlin
3d970a9c08 Merge branch 'underline-improvements' of https://github.com/MaartenBent/wxWidgets
Add support for different underline types and colour to wxTextCtrl.

See https://github.com/wxWidgets/wxWidgets/pull/1406

Closes #17124.
2019-07-19 23:45:38 +02:00
Maarten Bent
cd7e21ad2b Apply wxTextCtrl underline review suggestions 2019-07-19 21:06:10 +02:00
Maarten Bent
d2d11dc205 Use array to look-up wxMSW underline colours
Remove previously added colours from wxColourDatabase.
2019-07-19 21:06:07 +02:00
Maarten Bent
f74d756ca5 Use DPI Aware wxGetSystemMetrics
If no wxWindow is known, use wxTheApp->GetTopWindow().
Also use a wxWindow for all wxSystemSettings::GetMetric calls.
2019-07-15 00:00:18 +02:00
Vadim Zeitlin
c43e0fa123 Move WM_CHAR handling inside the switch in wxTextCtrl code
No real changes, just check for WM_CHAR inside the existing "switch"
instead of writing a separate "if" statement just for it.

Note that removing HasFlag(wxTE_PROCESS_ENTER) test shouldn't matter as
we should be only getting WM_CHAR for VK_RETURN when this flag is used.
2019-07-14 01:58:48 +02:00
Vadim Zeitlin
17f9a71586 Don't mark WM_CHAR for VK_RETURN as processed if it wasn't
This doesn't seem to change anything in practice, but it's more logical
to not pretend that we processed the message if we didn't do anything at
all with it.
2019-07-14 01:37:32 +02:00
Vadim Zeitlin
8746da90fe Add wxTextEntry::ClickDefaultButtonIfPossible() to wxMSW
Factor out this function from wxTextCtrl to allow its reuse in
wxComboBox in the upcoming commit.

No real changes, this is a pure refactoring.
2019-07-14 01:37:32 +02:00
Vadim Zeitlin
fe0d81a376 Merge branch 'msw-font-dpi'
Various wxFont-related fixes and refactorings in preparation for adding
per-monitor DPI support.

Closes https://github.com/wxWidgets/wxWidgets/pull/1408
2019-07-12 18:53:24 +02:00
Vadim Zeitlin
63c118f186 Fix DPI used in wxTextCtrl::GetStyle()
Using the window DPI resulted in returning a twice bigger size in points
than the size really used for the windows on high-DPI monitors as,
apparently, RichEdit always uses DPI of 96 internally (tested with both
wxTE_RICH and wxTE_RICH2 in 192 DPI under Windows 10.0.16299.785).
2019-07-12 18:48:03 +02:00
Vadim Zeitlin
69586bb03b Reuse wxNativeFontInfo::GetLogFontHeightAtPPI()
Instead of calling ::MulDiv() directly, reuse GetLogFontHeightAtPPI()
as it is more readable.
2019-07-12 18:48:03 +02:00
Vadim Zeitlin
72a225924d Remove wxCreateFontFromLogFont() and wxFillLogFont()
These functions are not really useful as converting between wxFont and
LOGFONT can be done trivially by passing via wxNativeFontInfo and, in
fact, wxCreateFontFromLogFont() managed to do the conversion wrongly by
forgetting to update wxNativeFontInfo::pointSize member when changing
wxNativeFontInfo::lf.

This fixes one unit test failure after the latest changes, although not
yet the other one, see the upcoming commit for this.
2019-07-12 18:48:03 +02:00
Maarten Bent
f5b3b6a84d Determine underline type and colour in wxTextCtrl::GetStyle 2019-07-11 00:50:38 +02:00
Maarten Bent
4afea28aab Improve underline changes of wxTextCtrl
Get rid of m_fontUnderlined, use m_fontUnderlineType instead.
Bugfixes in wxMSW, wxGTK and wxOSX code.
Show more underline usage in the text sample.
2019-07-11 00:34:27 +02:00
Igor Korot
f99ae84d7c Implement different underline styles for wxTextCtrl 2019-07-11 00:23:18 +02:00
Andreas Falkenhahn
c3ce5244e3 Return -1 from GetLineLength() if line number is out of range
Make wxTextCtrl behaviour in all ports consistent with the documentation
and also update wxStyledTextCtrl to behave accordingly.

Closes #18431.
2019-07-07 03:35:21 +02:00
Vadim Zeitlin
ee771c51aa Fix TAB handling for controls with wxTE_PROCESS_ENTER in wxMSW
When this style is specified, TAB has to be handled manually as well and
we do it by calling our Navigate() method explicitly. But for it to work
correctly we need to pretend that it's called in response to a real TAB
press by specifying FromTab flag and the code forgot to do this -- just
add the missing flag to fix it now.

In particular, this ensures that the special code handling radio buttons
in wxControlContainer::HandleOnNavigationKey() is really executed and
fixes a bug with pressing TAB on a wxTextCtrl with wxTE_PROCESS_ENTER
before a radio button group would select the first radio button of this
group instead of jumping to the currently selected button.

Closes #18392.
2019-04-25 18:32:50 +02:00
Maarten Bent
eb23d4735c Fix unannotated fall-through warnings 2018-11-25 21:29:37 +01:00
Vadim Zeitlin
a38176c67a Make wxTextCtrl horizontal margins proportional to DPI
Add more FromDIP() calls.
2018-07-09 20:36:16 +02:00
Vadim Zeitlin
950b1a9d51 Merge branch 'replace-connect-bind'
Replace almost all occurrences of wxEvtHandler::Connect() with Bind().

See https://github.com/wxWidgets/wxWidgets/pull/820
2018-06-01 18:31:59 +02:00
Václav Slavík
dcac98d7e8 Fix cursor flicker after popup menu in rich wxTextCtrl
After bd650ec and cad2b9c, showing a popup menu in wxTextCtrl with
wxTE_RICH2 and then dismissing it without choosing a command would
result in the cursor flickering between arrow and beam cursors until
another context menu was shown.

See https://github.com/vslavik/poedit/issues/483

Fixed by checking if the popup menu is still valid (and so shown) in
the cursor handling code.
2018-06-01 10:10:43 +02:00
Vadim Zeitlin
d4f380e16e Use Bind() instead of Connect() in wxWidgets code
Use more modern function which allows to avoid wxXXXEventHandler()
macros use.

No real changes.
2018-05-30 13:06:20 +02:00
Vadim Zeitlin
44a089b295 Fix handling TAB in wxSearchCtrl in wxMSW
Check whether wxTextCtrl has focus using Win32 ::GetFocus() instead of
by comparing FindFocus() with "this" pointer, as the latter fails when
wxTextCtrl is part of a composite control, such as wxSearchCtrl.

This is enough to make pressing TAB in wxSearchCtrl correctly go to the
next control instead of just beeping.

Note that we could also use DoFindFocus() here, but this would be
needlessly less efficient as we don't really need to find wxWindow
corresponding to the focused HWND, as that function does. But we can't
use HasFocus() here as it wouldn't work correctly here when the focus is
on another sub-window of a composite control also containing this
wxTextCtrl.
2018-01-27 15:58:14 +01:00
Vadim Zeitlin
5a949efc5c Fix sending wxEVT_TEXT_ENTER when using auto-completion in wxMSW
We need to explicitly generate this event from the char hook handler as
we don't get the normal WM_CHAR for it, it is apparently intercepted by
the window proc installed by the auto-completing code, so check if
wxTE_PROCESS_ENTER is used for the text entry and call a special new
MSWProcessSpecialKey() method to do the right thing if it is.

Similarly, handle Tab presses correctly if wxTE_PROCESS_TAB is used.

Closes #12613.
2017-12-25 19:29:25 +01:00
Artur Wieczorek
c51dd81db6 Optimize wxTextCtrl::GetLastPosition()
It's better to call one API instead of four.
2017-09-01 11:17:50 +02:00