Unlike the traditional C functions, std::from_chars() doesn't skip
leading whitespace and doesn't accept the leading "+" sign, so we need
to skip them explicitly to preserve the behaviour of ToLong() in the
previous wxWidgets versions.
Do use std::from_chars<unsigned long>() in it as otherwise values
greater than LONG_MAX failed to parse.
Handle negative numbers explicitly to still parse them in this function
as well, as needs to be done for compatibility.
Add a test case for the previously failing numbers.
Closes#23957.
This reverts the frame synchronization logic that was recently added
with the purpose of avoiding performance issues due to `eglSwapBuffers`
blocking when the canvas is hidden or occluded.
This logic should be unnecessary after `eglSwapInterval(display, 0)`
is called, since `eglSwapBuffers` should never block anymore.
Furthermore, as it stands now, it causes the canvas to continuously
repaint itself at the refresh rate of the display, which is wasteful
for applications which do not need to continuously refresh.
Fixes#24012.
Closes#24017.
In the recent changes for handling map/unmap events on Wayland's
wxGLCanvasEGL, we use the following GTK widget signals:
* The "map-event" signal to create the canvas's subsurface.
The earlier "map" signal can not be used, as the associated toplevel
window's Wayland surface may not yet exist by the time we receive it.
* The "unmap" signal to destroy the canvas's subsurface.
Using the later "unmap-event" signal is problematic, due to other
resources we build upon being already destroyed by then.
Usually, the "map-event" signal comes before "unmap" and resources are
created and destroyed appropriately. However, there's an edge case:
If a canvas is shown and then immediately hidden (before wxWidgets can
pump from the event loop), "unmap" will come before "map-event".
This happens because signals like "map" and "unmap" are delivered
immediately (when calling e.g. `gtk_widget_hide`), while signals like
"map-event" and "unmap-event" are delivered later on the event loop.
For the same reason, showing a canvas, then immediately hiding it, then
immediately showing it again, will cause two "map-event"s to get
delivered enqueued without a "unmap" in between.
This condition can be hit quite easily when setting up a complex UIs,
and in particular it is triggered by Aegisub during startup, leading to
a crash (Wayland protocol error) when opening a video later, or when
specifying a video directly on the startup command line.
To avoid this breaking our resource management, add some checks to detect
those "map-event"s we shouldn't handle - either the ones that happen
after "unmap", or the duplicate ones without an "unmap" in between.
Fixes#23961.
Closes#23968.
If the wxGLCanvas is destroyed immediately (without hiding it first),
the GTKs widget's `unmap` signal which usually destroys the Wayland
resources is not emitted. Thus, we need to ensure they are destroyed
on the destructor instead.
This fixes an use-after-free issue, sometimes causing a crash, because
one of the leaked resources is the canvas's Wayland frame callback.
Fixes#24013.
Closes#24016.
Calling it from the frame callback might change the swap interval for
the wrong context if the active context got changed in the meanwhile,
but by the time SwapBuffers() is called the correct context must be set.
Doing it there also allows to unify X11 and Wayland code branches.
As documented, the value -1 is special which means no constraints will
be used.
In other words, we should use the Qt defaults if -1 was specified.
Closes#24008.
The Clear log and Exit buttons were not shown after the changes
in a69fabe (Fix using wxStaticBoxSizer in samples, 2023-10-22).
Fix this by creating them with the proper parent.
Closes#24005.
Closes#24007.
Since the changes of 194a7be33f (Improve wxGLCanvasEGL refresh logic
under Wayland, 2023-05-17, see #23554) drawing on wxGLCanvas from
wxEVT_IDLE handler without refreshing the window first didn't work any
longer because the "ready to draw" flag was always false in this case.
To make this work again, refresh the window ourselves to ensure that it
does get redrawn. This is less efficient than drawing on it from
wxEVT_PAINT because all the code executed by the application prior to
calling SwapBuffers() is just wasted, but better than not updating the
window at all.
The recommended way of doing things remains, just as it always was, to
draw from wxEVT_PAINT and call Refresh() in the application code when
the window needs to be updated.
See #23998.
Closes#23996.
When using non-integer scale factor, we need to round the result of the
multiplication by it instead of truncating it for consistency with the
behaviour of wxBitmap::CreateWithDIPSize() and the other places where we
do this, including wxOSX version of this function.
Add a simple unit test checking that this works correctly (it would fail
with wxGTK before).
No real changes, just don't put the test not using raw bitmap access
inside the section guarded by "#if wxHAS_RAW_BITMAP".
This commit is best viewed with Git --color-moved option.
Don't test for 2 unrelated conditions inside the single assert as this
makes it unclear which of them failed.
Separate the checks for bitmap and input parameter validity, just as it
was already done in wxGTK.
Add a note explaining that when creating a button sizer with this
method, one of the buttons will be usually made the default.
See #23992.
Closes#24001.
Include standard library <memory> header file explicitly in the files
where std::unique_ptr<> is used instead of relying it on getting
implicitly included from the other headers, as this doesn't happen when
wxUSE_INTL==0.
Closes#23999.
Since the changes of 4d76a87015 (Make wxSearchCtrl inherit from
wxTextEntry in all ports, 2023-07-09, see #23697) GetEditHWND() returned
null for wxSearchCtrl which was considered to be correct because all
wxTextEntry functions were supposed to be forwarded to wxSearchTextCtrl
anyhow.
This wasn't really correct, however, as GetEditHWND() was also called
from SetHint(), resulting in an assert failure and falling back on
generic hint implementation which, while mostly working, suffers from
some problems that the native implementation doesn't have.
So make this function return the actual HWND used by the associated text
entry to fix this and allow SetHint() to work as before and also
forestall any problems due to not having the right HWND in the future.
See #23983.
Closes#23975.
This should have been done back in f18b415ee3 (Don't crash on startup of
console programs in monolithic wxX11 build., 2011-05-03) when a related
crash on startup was fixed.
The memory leak fix in b52728a62a (Fix memory leak of wxClipboard data
on exit, 2023-06-21) was too eager and destroyed not just the currently
used selection (e.g. primary), but also the other one (secondary) when
Clear() was called, which was wrong and resulted in the loss of
clipboard contents when discarding the primary selection in wxSTC, for
example.
Fix this by only deleting the object corresponding to the selection
which we're clearing.
See #23661.
Closes#23988.
This is currently implemented for single line control only. But unfortunately the
wxEVT_TEXT_MAXLEN event is only emitted when the Qt version used is 5.12 or higher.
This method is needed to determine the sorted state of a control derived
from wxItemContainer without knowing the actual derived control class.
Closes#23971.
If a control is contained in a wxStaticBoxSizer or its child sizer,
wxStaticBoxSizer::GetStaticBox() should be used as the control's parent.
However, widgets and dialogs samples did not do that, which resulted in
flooding the message log in widgets sample with warnings about this; in
dialogs sample the warnings were shown in the debug output.
Fix this by always using the static box as the control's parent when the
control is contained (directly or indirectly) in a wxStaticBoxSizer.
Closes#23967.
To sort its items (files and folders) wxFileCtrl used simple string
compare and wxDirCtrl case-insensitive string compare.
However, the files and folders should be presented to the users in the
way they are used to, i.e., in the natural order. Therefore, use
wxCmpNatural() for file and folder names and wxStricmp() for file
extensions.
Closes#22054.
Closes#23962.
Having this line is not useful at all as it doesn't contain any
information and shouldn't be filled in the future as git-shortlog can
provide the information about people who changed the given file more
more reliably than consulting the comments in any case.
Keep the non-blank lines for historical purposes.