Commit graph

1132 commits

Author SHA1 Message Date
Vadim Zeitlin
a89577e8a4 Deprecate useless wxWindow::GetDefaultBorderForControl()
This function was added back in a047aff270 (Added wxBORDER_THEME,
wxWindow::GetDefaultBorderForControl(), wxWindow::CanApplyThemeBorder(),
2007-08-07) but seems to have been made completely unnecessary by
dc797d8e1b (More border rationalisation. GetDefaultBorder is now mostly
defined in base class files., 2007-11-13) soon afterwards and never did
anything other than returning wxBORDER_THEME, with no explanation as to
when it might be useful to override it not to do it.

It also doesn't seem to be really used anywhere outside wxWidgets and
has never been documented, so make it non-virtual and deprecate it to
avoid confusion and simplify things.
2023-06-16 15:55:35 +01:00
Vadim Zeitlin
4c8ec0ed5d Revert "Add wxWindow::MSWAfterReparent() virtual function"
This reverts commit cd637663c8 (Add wxWindow::MSWAfterReparent() virtual
function, 2022-10-16) and removes wxListCtrl::MSWAfterReparent() added
in ff629f3853 (Fix drawing wxListCtrl since enabling double buffering by
default, 2022-10-16) which is not used any more now.
2023-06-05 14:30:56 +01:00
Vadim Zeitlin
ef93da3160 Add wxUxThemeHandle::DrawBackground() wrapper and use it
This is sightly shorter/more convenient to use than providing all the
parameters to ::DrawThemeBackground() every time.

Similarly to ca5f244f15 (Add wxUxThemeHandle::GetColour() replacing
MSWGetThemeColour(), 2022-12-09), this is just a refactoring which
shouldn't result in any changes in behaviour.
2023-06-03 19:18:57 +01:00
Maarten Bent
70c2ddeba3 Add support for wxBG_STYLE_TRANSPARENT to wxMSW
Allow using transparent background style under Windows by mapping it to
WS_EX_TRANSPARENT.

Closes #23412, #23498.
2023-05-11 22:42:13 +01:00
Vadim Zeitlin
62b6e1d0f9 Use wxRect::MakeCenteredIn() in DoSetClientSize()
No real changes, just make the code more clear by adding the new helper
function.
2023-05-10 00:13:35 +01:00
Vadim Zeitlin
072d581e87 Keep window on the same display in SetClientSize()
It was unexpected that changing the window client size could change the
display the window was on and, even worse, result in further size
changes because changing the display could change the DPI scaling used.
And, worst of all, if the window wxEVT_DPI_CHANGED handler called
SetClientSize(), possibly indirectly such as via wxSizer::Fit(), this
could result in an infinite recursion when moving the window to a high
definition display located to the left of the standard definition one
(the problem didn't happen for the reciprocal display arrangement
because increasing the window size couldn't change the window display
in that case).

So ensure that the window remains on the same display it is on now, by
keeping its center position unchanged, instead of keeping the position
of its top left corner as we did before.
2023-05-09 21:59:46 +01:00
Vadim Zeitlin
0f19c0a074 Pass wxDPIChangedEvent to the just added MSWBeforeDPIChangedEvent()
This is unusual, but this function may need to rescale some coordinates
and it's convenient to just call event.Scale() then.

So pass it the event that we are preparing to process to it instead of
passing it new and old DPI separately and forcing it to deal with them
itself (instead of using Scale()).
2023-05-01 17:21:03 +01:00
Vadim Zeitlin
7cee6d59c3 Fix updating wxFrame client size in wxEVT_DPI_CHANGED handler
This didn't work correctly when switching from higher to lower DPI if
the frame had a status bar because this status bar still had its old,
bigger height, by the time SetClientSize() was called from the event
handler, resulting in the frame size becoming too big.

It notably resulted in having an unwanted gap between the frame contents
and the status bar if the event handler called GetSizer()->Fit().

Fix this by calling PositionStatusBar(), which also updates the status
bar height to correspond to the new DPI as a side effect, from a new
virtual MSWBeforeDPIChangedEvent() function which had to be added to
allow wxFrame to customize DPI handling.

Adding this new virtual function just for this isn't great, but the only
alternatives seem even worse.
2023-05-01 17:21:03 +01:00
Vadim Zeitlin
16caa0630f Fix MSWDisableComposited() compilation in wxUniv/MSW
Don't hardcode wxWindow as type of "this", it's wxWindowBase in wxUniv.

Just use "auto" to make it compile in all builds.
2023-04-22 16:39:42 +02:00
Vadim Zeitlin
5a7f86e4e6 Use unordered_map<> in wxMSW wxWindow implementation
Replace wx hash map with the standard container.
2023-04-12 18:15:46 +01:00
Vadim Zeitlin
82729cb93a Don't assert if HWND is invalid in wxWindow::DissociateHandle()
There was no safe way to prevent wxWindow from trying to destroy the
HWND again if it had been already destroyed, for whatever reason, as
UnsubclassWin() asserted if it was called and calling SetHWND(0) before
calling it as some (but not all) existing code did, resulted in not
removing the association using the old HWND as key.

Allow to use DissociateHandle() for safely detaching HWND from the
window, without assuming that it is valid.
2023-03-31 16:46:45 +01:00
Vadim Zeitlin
6f5703a885 Fix wxStaticBox drawing after disabling composition for parent
We need to switch to custom-drawing the box if we stop using
WS_EX_COMPOSITED as WS_EX_TRANSPARENT doesn't work correctly without it
(the background is not being painted correctly), so do this by
overriding the new MSWOnDisabledComposited() which is now called by
MSWDisableComposited() if/when it actually does disable it.
2023-02-21 18:53:11 +00:00
Vadim Zeitlin
ccaf5728f6 Restore the use of WS_EX_COMPOSITED by default
This was accidentally broken by b4dd25ee3f (Disable use of composition
for top most windows, 2022-12-25).

See #23079.

Co-Authored-By: Maarten Bent <MaartenBent@users.noreply.github.com>
2023-01-03 18:44:27 +01:00
Vadim Zeitlin
208142c14a Merge branch 'msw-dark-mode'
Add experimental support for dark mode for wxMSW.

See #23028.
2022-12-27 22:20:34 +01:00
Vadim Zeitlin
b4dd25ee3f Disable use of composition for top most windows
WS_EX_COMPOSITED seems to be incompatible with WS_EX_TOPMOST and breaks
(re)painting of such windows.

Closes #23076, #23078, #23079.
2022-12-27 22:16:22 +01:00
Vadim Zeitlin
a7b39f63b3 Send wxEVT_SYS_COLOUR_CHANGED on dark/light theme change in wxMSW
wxOSX already does it, so do it in wxMSW too for consistency and because
it seems useful to be able to react to the same event in all cases.

Update the drawing sample to refresh its system colours scheme whenever
the theme is changed.
2022-12-26 22:10:32 +00:00
Vadim Zeitlin
1f939fabec Allow using wxMSWDarkMode::PaintIfNecessary() with any HWND
We don't always have a wxWindow to pass to this function, so make it
more general at the cost of being slightly more inconvenient to use.

No real changes yet.
2022-12-25 19:45:53 +00:00
Vadim Zeitlin
f93fe96c9f Enable using dark scrollbars for all windows
Even non-native windows still need wxMSWDarkMode::AllowForWindow() to be
called in dark mode, as without it their scrollbars would use light
colours.
2022-12-25 19:45:53 +00:00
Vadim Zeitlin
252551fd26 Add wxMapWindowPoints() private helper function
This allows to avoid having to use casts from RECT to POINT in the rest
of the code by encapsulating this cast, and the comment explaining it,
in this function only.

No real changes.
2022-12-25 19:45:52 +00:00
Vadim Zeitlin
446f4c6afb Rename WindowHDC private helper class to ClientHDC
It was pretty confusing that WindowHDC actually used client HDC and not
the (full) window one.

Also add a helper AutoHDC class releasing the DC automatically in its
dtor and use it as the common base for ScreenHDC and ClientHDC.

No real changes, this is just a renaming/refactoring.
2022-12-25 19:45:52 +00:00
Vadim Zeitlin
ca5f244f15 Add wxUxThemeHandle::GetColour() replacing MSWGetThemeColour()
Add a helper function wrapping ::GetThemeColor() and use it in all
places where this function was used before, as it's more convenient.

Also remove wxWindow::MSWGetThemeColour() as it was only used in a
single place and doesn't seem to present any advantages compared to
using wxUxThemeHandle new method.

There should be no changes in behaviour, this is just a refactoring.
2022-12-25 19:45:52 +00:00
Vadim Zeitlin
cb85871831 Add MSWShouldUseAutoDarkMode() and use it for wxSpinButton
This control doesn't seem to support dark mode natively, whichever theme
is used for it, so paint it in dark mode ourselves simply by inverting
its colours -- this is not great, but passable and better than leaving
it with a light background.

As this probably won't be the only control which will need this,
implement it at wxWindow level and allow the derived classes to opt-in
this "automatic dark mode support" by simply overriding the new
MSWShouldUseAutoDarkMode() function.
2022-12-25 19:45:52 +00:00
Vadim Zeitlin
ce1ee46b0c Use wxRadioButton in MSW wxRadioBox implementation
For reasons lost in the mists of time, wxRadioBox created its own radio
buttons using Win32 API directly instead of just using wxRadioButton.

Finally change this now as this significantly simplifies the code and
makes it shorter and more clear. Notably, we now can just add the
buttons to the sizer and let it manage them instead of having to do it
manually.

It also makes an ugly wxRadioBox-specific workaround in wxWindow
unnecessary. Unfortunately we still need to keep wxSubwindows stuff
because wxSlider still uses it, but this will make it easier to get rid
of it in the future, when wxSlider is changed to use wxWindows too.

This will also make the radio box appear correctly in the dark mode too,
as a nice side effect.
2022-12-25 00:39:56 +01:00
Vadim Zeitlin
c2f3a3db01 Always use wxDynamicLibrary in wxMSW and remove checks for it
Force wxUSE_DYNLIB_CLASS to be 1 when using wxMSW and remove checks for
it being 0 from the code.

No real changes.
2022-12-04 02:12:22 +00:00
Vadim Zeitlin
20bbc43a20 Redefine wxTRANSPARENT_WINDOW as 0 and stop using it
This style never did anything useful in wxMSW and did nothing at all in
all the other ports, so always was rather useless, but became actively
harmful not that WS_EX_COMPOSITED is used in wxMSW because using it and
WS_EX_TRANSPARENT, enabled by wxTRANSPARENT_WINDOW, together doesn't
work and results in an endless stream of WM_PAINT messages being sent to
the _siblings_ of the window with wxTRANSPARENT_WINDOW style.
2022-11-28 19:04:56 +00:00
Vadim Zeitlin
a4ebfbb773 Force wxFULL_REPAINT_ON_RESIZE for windows using WS_EX_COMPOSITED
Without this style drawing windows using WS_EX_COMPOSITED doesn't work
correctly as the system can't blit the window to the screen if we don't
draw it entirely, resulting in very visible redraw problems when
resizing and repositioning a window at the same time that can be seen by
just putting 2 plain wxWindow objects in a box sizer with non-zero
proportions and expand style.
2022-11-28 19:04:36 +00:00
Vadim Zeitlin
3259d1e2d9 Don't try to clear WS_EX_COMPOSITED for TLWs
This style is never set for them anyhow, so this doesn't really change
anything right now -- but could in the future if we do set it at this
level.
2022-11-28 19:04:36 +00:00
Vadim Zeitlin
d9734baed5 Add msw.window.no-composited system option
For some applications turning off double buffering for individual
windows may be infeasible, so allow doing it globally using this system
option.

Note that wxAutoBufferedPaintDC still does no buffering in wxMSW now,
even when this option is set, so setting it will result in flickering in
any code using it. The solution is to use wxBufferedPaintDC directly in
the programs that use this option.

Closes #22953.
2022-11-12 17:51:27 +01:00
Vadim Zeitlin
4519d8e08a Remove wxUSE_UNICODE checks as they're always true now
Also remove all code guarded by "#if !wxUSE_UNICODE".
2022-10-27 19:43:30 +02:00
Vadim Zeitlin
9f46e67eec Merge branch 'nullptr'
Use nullptr instead of NULL in the code, comments and the documentation.

See #22881.
2022-10-18 18:34:07 +02:00
Vadim Zeitlin
4f4c5fcfdf Use nullptr instead of NULL in the code and documentation
This is a combination of running clang-tidy with modernize-use-nullptr
check for some ports (GTK, X11, OSX) and manual changes to the ports for
which it couldn't be used easily (MSW, DFB) and also manually updating
the docs.

Also replace NULL with null or nullptr in the comments as this is more
consistent with the use of nullptr in the code and makes it simpler to
grep for the remaining occurrences of NULL itself.

And also use null in the assert messages.

Only a few occurrences of "NULL" are still left in non-C files, mostly
corresponding to unclear comments or string output which it might not be
safe to change.
2022-10-18 01:25:25 +02:00
Vadim Zeitlin
b5d434dc91 Move wxListCtrl::MSWResetParentComposited() to wxWindow
This function will need to be used from other places too, so make it
available in the base class itself.

Also disable WS_EX_COMPOSITED for this window itself too.
2022-10-17 13:31:28 +01:00
Vadim Zeitlin
cd637663c8 Add wxWindow::MSWAfterReparent() virtual function
Refactor the existing code to extract the part of Reparent() updating
the new parent style to an overridable virtual function.

No real changes yet.
2022-10-16 21:16:13 +01:00
Vadim Zeitlin
ecf321924e Merge branch 'cxx11'
Require C++11 compiler and start using some C++ features in the code.

See #22684, #22854.
2022-10-15 18:14:55 +02:00
PB
88d526660f Replace wxOVERRIDE and wxNOEXCEPT with override and noexcept
Don't use deprecated macros in wxWidgets itself.
2022-10-15 18:10:45 +02:00
Vadim Zeitlin
cd15602378 Enable double buffering for all generic windows in wxMSW
Turn on WS_EX_COMPOSITED for child windows, as this is not supposed to
result in any bad effects and double buffers drawing, avoiding flicker.
2022-10-06 02:19:32 +01:00
Vadim Zeitlin
179629205d Allow passing NULL to wxWindow::CreateUsingMSWClass()
Instead of calling GetMSWClassName() in wxWindow::Create() itself, just
use NULL there and interpret this as meaning to use the default wxWindow
class in CreateUsingMSWClass(), as it will allow it to distinguish
between creating generic windows and native controls.

No real changes yet.
2022-10-06 02:17:48 +01:00
s-murphree
2e9b78c832 Fix return value of wxZoomGestureEvent::GetZoomFactor() in wxMSW
Although fingerDistance parameter is passed as a DWORD, it is actually
a signed integer which can be negative, so handle consistently handle it
as such to ensure that zoomFactor is computed correctly, as a ratio of 2
integers.

See #22818, #22819.
2022-09-24 15:11:07 +02:00
Lauri Nurmi
66916c74a3 Fix double negatives used with 'neither' in docs and comments
In many cases it should be 'either', and 'nor' should be 'or'
accordingly.

No changes to actual code.

Closes #22723.
2022-08-19 16:22:21 +02:00
Vadim Zeitlin
f0ea00cd35 Let application determine TLW size after DPI change
Don't change the window size automatically if the application handled
wxEVT_DPI_CHANGED event to allow it to choose a better size than what is
suggested by MSW itself.

Closes #19152.
2022-06-24 02:49:34 +01:00
Vadim Zeitlin
37950c1421 Make changing popup menu items in wxEVT_MENU_OPEN work again
Set up popup menu bitmaps after executing wxEVT_MENU_OPEN handler, so
that any changes to the menu item bitmaps done in it are taken into
account, as this only happens when SetupBitmaps() is called.

Closes #22530.
2022-06-16 01:09:43 +01:00
Paul Cornett
f576b21366 Fix object identifier comparison for 64-bit in WM_GETOBJECT handler
LPARAM is a signed 64-bit type, and OBJID_CLIENT is defined as ((LONG)0xFFFFFFFC),
so converting to LPARAM will sign-extend and the comparison will always fail.
Fixed by comparing as DWORD, as the Microsoft documentation recommends.
2022-06-10 07:34:02 -07:00
Vadim Zeitlin
caac3a4f19 Load SetThreadDpiAwarenessContext() function pointer only once
A small optimization to avoid resolving this function dynamically every
time it is needed and just do it once, on first use.
2022-04-16 17:49:09 +01:00
Vadim Zeitlin
1c33294cf5 Add debugging check for using possibly incorrect DPI in wxMSW
When calling GetDPI() for a window which is not created itself yet and
doesn't have any valid top level parent neither, we have no choice but
to fall back on using the screen DPI, but this doesn't always work
correctly for the systems using multiple monitors with different DPIs,
so warn when this happens -- any situations when it does indicate a
potential bug that should be fixed.

See #22193.
2022-03-19 22:56:07 +01:00
Vadim Zeitlin
a00b0336a1 Don't adjust the font to DPI if the window isn't created yet
This is at best useless, as we can't get the correct DPI to use before
the window is created anyhow.

See #22193.
2022-03-19 22:56:07 +01:00
Vadim Zeitlin
f54ebf3261 Add wxGetDPIofHDC() helper function and use it in wxMSW code
No real changes, just replace several pairs of calls to GetDeviceCaps()
with a single helper function call.
2022-03-19 22:56:06 +01:00
Alexander Koshelev
27be2ed641 wxBitmapBundle for wxMenuItem on MSW 2022-02-04 15:45:49 +03:00
Vadim Zeitlin
2f0bce2979 Replace old Trac links with GitHub ones
Also update a couple of links to SF.
2022-01-13 16:52:58 +01:00
Dummy
006fd1a511 Fix sending show events when hiding frozen windows in wxMSW
Send these events ourselves because MSW itself doesn't generate them for
frozen windows. This makes wxMSW more consistent with the other ports.

Add unit tests to verify that the behaviour is really as expected for
both normal and frozen windows, at least under MSW -- under GTK these
events are not sent at all for the notebook pages.

Closes #19216.
2022-01-08 22:14:04 +01:00
Vadim Zeitlin
a8c05945b4 Log the length of the window label if creating it fails in wxMSW
This can be useful in case of unexpected window creation failure, so log
it because it doesn't cost much for something that is supposed to
practically never happen anyhow.
2021-10-27 21:38:41 +01:00