4#ifndef QWINDOWSWINDOW_H
5#define QWINDOWSWINDOW_H
7#include <QtCore/qt_windows.h>
8#include <QtCore/qpointer.h>
12#include <qpa/qplatformwindow.h>
13#include <qpa/qplatformwindow_p.h>
16#include "qwindowsvulkaninstance.h"
23class QWindowsOleDropTarget;
31 static QMargins frame(
const QWindow *w, DWORD style, DWORD exStyle, qreal dpi);
32 static QMargins frame(
const QWindow *w, HWND hwnd, DWORD style, DWORD exStyle);
34 static QMargins frame(
const QWindow *w,
const QRect &geometry,
35 DWORD style, DWORD exStyle);
36 static bool handleCalculateSize(
const QWindow *window,
const QMargins &customMargins,
const MSG &msg, LRESULT *result);
38 const QMargins &margins, MINMAXINFO *mmi);
41 static void frameSizeConstraints(
const QWindow *w,
const QScreen *screen,
42 const QMargins &margins,
43 QSize *minimumSize, QSize *maximumSize);
55 const QRect &geometryIn,
const QRect &geometry,
56 const QMargins &customMargins,
57 DWORD style, DWORD exStyle);
91 const QString &title);
104 WId winId()
const override {
return WId(handle()); }
122 unsigned style()
const {
return GetWindowLongPtr(handle(), GWL_STYLE); }
123 unsigned exStyle()
const {
return GetWindowLongPtr(handle(), GWL_EXSTYLE); }
170 void setParent(
const QPlatformWindow *window)
override;
171 void setGeometry(
const QRect &rect)
override { setGeometry_sys(rect); }
175 void setWindowTitle(
const QString &title)
override { setWindowTitle_sys(title); }
183 DWORD m_topLevelStyle;
237 bool isAncestorOf(
const QPlatformWindow *child)
const override;
245 void setParent(
const QPlatformWindow *window)
override;
263 void setMask(
const QRegion ®ion)
override;
293 bool handleWmPaint(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result);
312 static bool setWindowLayered(HWND hwnd, Qt::WindowFlags flags,
bool hasAlpha, qreal opacity);
325 void setCursor(
const CursorHandlePtr &c);
328 inline bool testFlag(
unsigned f)
const {
return (m_flags & f) != 0; }
329 inline void setFlag(
unsigned f)
const { m_flags |= f; }
330 inline void clearFlag(
unsigned f)
const { m_flags &= ~f; }
336 void *
surface(
void *nativeConfig,
int *err);
366 inline void show_sys()
const;
367 inline QWindowsWindowData setWindowFlags_sys(Qt::WindowFlags wt,
unsigned flags = 0)
const;
368 inline bool isFullScreen_sys()
const;
369 inline void setWindowState_sys(Qt::WindowStates newState);
370 inline void setParent_sys(
const QPlatformWindow *parent);
371 inline void updateTransientParent()
const;
372 void destroyWindow();
373 inline bool isDropSiteEnabled()
const {
return m_dropTarget !=
nullptr; }
374 void setDropSiteEnabled(
bool enabled);
375 void updateDropSite(
bool topLevel);
376 void handleGeometryChange();
377 void handleWindowStateChange(Qt::WindowStates state);
378 inline void destroyIcon();
379 void fireExpose(
const QRegion ®ion,
bool force=
false);
380 void fireFullExpose(
bool force=
false);
381 void calculateFullFrameMargins();
382 void correctWindowPlacement(WINDOWPLACEMENT &windowPlacement);
385 QPointer<QWindowsMenuBar> m_menuBar;
389 QString m_windowTitle;
392 CursorHandlePtr m_cursor;
395 unsigned m_savedStyle = 0;
396 QRect m_savedFrameGeometry;
397 HICON m_iconSmall =
nullptr;
398 HICON m_iconBig =
nullptr;
399 void *m_surface =
nullptr;
402 static bool m_screenForGLInitialized;
408 static bool m_borderInFullScreenDefault;
409 static bool m_inSetgeometry;
411 qsizetype m_vsyncServiceCallbackId = 0;
412 QAtomicInt m_vsyncUpdatePending;
415#ifndef QT_NO_DEBUG_STREAM
416QDebug operator<<(QDebug d,
const RECT &r);
417QDebug operator<<(QDebug d,
const POINT &);
418QDebug operator<<(QDebug d,
const MINMAXINFO &i);
419QDebug operator<<(QDebug d,
const NCCALCSIZE_PARAMS &p);
420QDebug operator<<(QDebug d,
const WINDOWPLACEMENT &);
421QDebug operator<<(QDebug d,
const WINDOWPOS &);
422QDebug operator<<(QDebug d,
const GUID &guid);
427 if (QWindowsBaseWindow::isRtlLayout(hwnd)) {
429 GetClientRect(hwnd, &clientArea);
430 wP->x = clientArea.right - wP->x;
432 ClientToScreen(hwnd, wP);
437 ScreenToClient(hwnd, wP);
438 if (QWindowsBaseWindow::isRtlLayout(hwnd)) {
440 GetClientRect(hwnd, &clientArea);
441 wP->x = clientArea.right - wP->x;
448 POINT p = { qp.x(), qp.y() };
449 clientToScreen(hwnd, &p);
450 return QPoint(p.x, p.y);
455 POINT p = { qp.x(), qp.y() };
456 screenToClient(hwnd, &p);
457 return QPoint(p.x, p.y);
461 {
return QWindowsGeometryHint::mapToGlobal(QWindowsWindow::handleOf(w), p); }
464 {
return QWindowsGeometryHint::mapFromGlobal(QWindowsWindow::handleOf(w), p); }
471 if (!w || !w->handle() || w->handle()->isForeignWindow())
479 return reinterpret_cast<
void *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
484 SetWindowLongPtr(hwnd, GWLP_USERDATA, LONG_PTR(ud));
490 DestroyIcon(m_iconBig);
494 DestroyIcon(m_iconSmall);
495 m_iconSmall =
nullptr;
501 return GetWindowLongPtr(m_data.hwnd, GWL_EXSTYLE) & WS_EX_LAYERED;
506Q_DECLARE_METATYPE(QMargins)
Base class for QWindowsForeignWindow, QWindowsWindow.
virtual bool isTopLevel() const
QMargins frameMargins_sys() const
bool isTopLevel_sys() const
void setHasBorderInFullScreen(bool border) override
QMargins customMargins() const override
bool windowEvent(QEvent *event) override
Reimplement this method to be able to do any platform specific event handling.
bool hasBorderInFullScreen() const override
static QWindowsBaseWindow * baseWindowOf(const QWindow *w)
bool hasMaximumWidth() const
virtual QMargins fullFrameMargins() const
QRect geometry() const override
Returns the current geometry of a window.
std::optional< TouchWindowTouchTypes > touchWindowTouchTypes_sys() const
static HWND handleOf(const QWindow *w)
QPoint mapToGlobal(const QPoint &pos) const override
Translates the window coordinate pos to global screen coordinates using native methods.
QMargins frameMargins() const override
QWindowsBaseWindow(QWindow *window)
bool hasMaximumHeight() const
static bool isRtlLayout(HWND hwnd)
QRect frameGeometry_sys() const
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
QRect geometry_sys() const
virtual HWND handle() const =0
QPoint mapFromGlobal(const QPoint &pos) const override
Translates the global screen coordinate pos to window coordinates using native methods.
void setCustomMargins(const QMargins &margins) override
void setGeometry_sys(const QRect &rect) const
bool hasMaximumSize() const
void setWindowTitle_sys(const QString &title)
Platform cursor implementation.
Window wrapping GetDesktopWindow not allowing any manipulation.
HWND handle() const override
QMargins frameMargins() const override
QWindowsDesktopWindow(QWindow *window)
bool isTopLevel() const override
Window wrapping a foreign native window.
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
bool isForeignWindow() const override
HWND handle() const override
void lower() override
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
void setParent(const QPlatformWindow *window) override
This function is called to enable native child window in QPA.
void setWindowTitle(const QString &title) override
Reimplement to set the window title to title.
QWindowsForeignWindow(QWindow *window, HWND hwnd)
void raise() override
Reimplement to be able to let Qt raise windows to the top of the desktop.
static QWindowsStaticOpenGLContext * staticOpenGLContext()
Provides access to native handles.
void * nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) override
void * nativeResourceForWindow(const QByteArray &resource, QWindow *window) override
void * nativeResourceForCursor(const QByteArray &resource, const QCursor &cursor) override
void * nativeResourceForScreen(const QByteArray &resource, QScreen *screen) override
Implementation of IDropTarget.
virtual void * moduleHandle() const =0
bool handleNonClientHitTest(const QPoint &globalPos, LRESULT *result) const
void alertWindow(int durationMs=0)
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
void setCustomMargins(const QMargins &m) override
Sets custom margins to be added to the default margins determined by the windows style in the handlin...
void setMenuBar(QWindowsMenuBar *mb)
static QWindowsWindow * windowsWindowOf(const QWindow *w)
void invalidateSurface() override
Invalidates the window's surface by releasing its surface buffers.
HDC getDC()
Allocates a HDC for the window or returns the temporary one obtained from WinAPI BeginPaint within a ...
QMargins fullFrameMargins() const override
void initialize() override
Called as part of QWindow::create(), after constructing the window.
void handleDpiChangedAfterParent(HWND hwnd)
static void setHasBorderInFullScreenStatic(QWindow *window, bool border)
void checkForScreenChanged(ScreenChangeMode mode=FromGeometryChange)
void requestUpdate() override
Requests an QEvent::UpdateRequest event.
bool testFlag(unsigned f) const
static QString formatWindowTitle(const QString &title)
void setFlag(unsigned f) const
void clearFlag(unsigned f) const
void setFrameStrutEventsEnabled(bool enabled) override
Reimplement this method to set whether frame strut events should be sent to enabled.
static void settingsChanged()
static bool handleGeometryChangingMessage(MSG *message, const QWindow *qWindow, const QMargins &marginsDp)
void getSizeHints(MINMAXINFO *mmi) const
static void setHasBorderInFullScreenDefault(bool border)
~QWindowsWindow() override
bool handleWmPaint(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result)
void setParent(const QPlatformWindow *window) override
This function is called to enable native child window in QPA.
static bool hasNoNativeFrame(HWND hwnd, Qt::WindowFlags flags)
QRect restoreGeometry() const
static void * userDataOf(HWND hwnd)
bool setMouseGrabEnabled(bool grab) override
void propagateSizeHints() override
Reimplement to propagate the size hints of the QWindow.
static void setUserDataOf(HWND hwnd, void *ud)
void applyCursor()
Applies to cursor property set on the window to the global cursor.
bool isExposed() const override
Returns if this window is exposed in the windowing system.
bool handleGeometryChanging(MSG *message) const
bool isActive() const override
Returns true if the window should appear active from a style perspective.
void setStyle(unsigned s) const
static QScreen * forcedScreenForGLWindow(const QWindow *w)
QString windowTitle() const override
Reimplement to return the actual window title used in the underlying windowing system unless the titl...
static void displayChanged()
bool setKeyboardGrabEnabled(bool grab) override
static bool setWindowLayered(HWND hwnd, Qt::WindowFlags flags, bool hasAlpha, qreal opacity)
void raise() override
Reimplement to be able to let Qt raise windows to the top of the desktop.
bool windowEvent(QEvent *event) override
Reimplement this method to be able to do any platform specific event handling.
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
void setEnabled(bool enabled)
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
QSurfaceFormat format() const override
Returns the actual surface format of the window.
static const char * embeddedNativeParentHandleProperty
QWindowsMenuBar * menuBar() const
void handleDpiChanged(HWND hwnd, WPARAM wParam, LPARAM lParam)
void registerTouchWindow()
QMargins frameMargins() const override
void setWindowIcon(const QIcon &icon) override
Reimplement to set the window icon to icon.
bool isClientAreaExpanded() const
void handleResized(int wParam, LPARAM lParam)
void setOpacity(qreal level) override
Reimplement to be able to let Qt set the opacity level of a window.
bool isEmbedded() const override
Returns true if the window is a child of a non-Qt window.
QMargins customMargins() const override
bool handleNonClientActivate(LRESULT *result) const
bool isAncestorOf(const QPlatformWindow *child) const override
Returns true if the window is an ancestor of the given child.
QRect normalGeometry() const override
Returns the geometry of a window in 'normal' state (neither maximized, fullscreen nor minimized) for ...
void setExStyle(unsigned s) const
qreal dpiRelativeScale(const UINT dpi) const
QMargins safeAreaMargins() const override
The safe area margins of a window represent the area that is safe to place content within,...
void setSavedDpi(int dpi)
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
static QWindow * topLevelOf(QWindow *w)
void handleDpiScaledSize(WPARAM wParam, LPARAM lParam, LRESULT *result)
static bool setDarkBorderToWindow(HWND hwnd, bool d)
void updateFullFrameMargins()
QRect geometry() const override
Returns the current geometry of a window.
bool frameStrutEventsEnabled() const override
Reimplement this method to return whether frame strut events are enabled.
@ SynchronousGeometryChangeEvent
@ OpenGlPixelFormatInitialized
@ WithinSetParent
Automatic mouse capture on button press.
@ DisableNonClientScaling
@ FrameStrutEventsEnabled
QPoint mapToGlobal(const QPoint &pos) const override
Translates the window coordinate pos to global screen coordinates using native methods.
static const char * hasBorderInFullScreenProperty
bool startSystemMove() override
Reimplement this method to start a system move operation if the system supports it and return true to...
bool isTopLevel() const override
void releaseDC()
Releases the HDC for the window or does nothing in case it was obtained from WinAPI BeginPaint within...
void lower() override
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
void updateRestoreGeometry()
void setWindowState(Qt::WindowStates state) override
Requests setting the window state of this surface to type.
void setCursor(const CursorHandlePtr &c)
void updateCustomTitlebar()
bool hasBorderInFullScreen() const override
bool hasMouseCapture() const
void * surface(void *nativeConfig, int *err)
void setHasBorderInFullScreen(bool border) override
QPoint mapFromGlobal(const QPoint &pos) const override
Translates the global screen coordinate pos to window coordinates using native methods.
CursorHandlePtr cursor() const
void handleCompositionSettingsChanged()
void setWindowTitle(const QString &title) override
Reimplement to set the window title to title.
void setDarkBorder(bool d)
QWindowsWindow(QWindow *window, const QWindowsWindowData &data)
bool startSystemResize(Qt::Edges edges) override
Reimplement this method to start a system resize operation if the system supports it and return true ...
void setFullFrameMargins(const QMargins &newMargins)
void setMask(const QRegion ®ion) override
Reimplement to be able to let Qt set the mask of a window.
void setAlertState(bool enabled) override
Reimplement this method to set whether the window demands attention (for example, by flashing the tas...
HWND handle() const override
bool isAlertState() const override
Reimplement this method return whether the window is in an alert state.
static void clientToScreen(HWND hwnd, POINT *wP)
static void screenToClient(HWND hwnd, POINT *wP)
Active Context for creating windows.
QWindowCreationContext(const QWindow *w, const QScreen *s, const QRect &geometryIn, const QRect &geometry, const QMargins &customMargins, DWORD style, DWORD exStyle)
void applyToMinMaxInfo(MINMAXINFO *mmi) const
QRect requestedGeometryIn
Stores geometry constraints and provides utility functions.
static QMargins frameOnPrimaryScreen(const QWindow *w, DWORD style, DWORD exStyle)
static QMargins frame(const QWindow *w, HWND hwnd)
static QMargins frame(const QWindow *w, const QRect &geometry, DWORD style, DWORD exStyle)
static QMargins frameOnPrimaryScreen(const QWindow *w, HWND hwnd)
static bool positionIncludesFrame(const QWindow *w)
static bool handleCalculateSize(const QWindow *window, const QMargins &customMargins, const MSG &msg, LRESULT *result)
static QPoint mapToGlobal(const QWindow *w, const QPoint &)
static QMargins frame(const QWindow *w, DWORD style, DWORD exStyle, qreal dpi)
static QPoint mapToGlobal(HWND hwnd, const QPoint &)
static QPoint mapFromGlobal(const HWND hwnd, const QPoint &)
static QPoint mapFromGlobal(const QWindow *w, const QPoint &)
static void applyToMinMaxInfo(const QWindow *w, const QMargins &margins, MINMAXINFO *mmi)
static void applyToMinMaxInfo(const QWindow *w, const QScreen *screen, const QMargins &margins, MINMAXINFO *mmi)
QMargins fullFrameMargins
static QWindowsWindowData create(const QWindow *w, const QWindowsWindowData ¶meters, const QString &title)