1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QWINDOWSWINDOW_H
43 #define QWINDOWSWINDOW_H
45 #include "qtwindows_additional.h"
47 # include "qplatformfunctions_wince.h"
49 #include "qwindowscursor.h"
51 #include <qpa/qplatformwindow.h>
54 # include <QtCore/QSharedPointer>
60 class QWindowsOleDropTarget;
64 class QWindowsEGLStaticContext;
67 struct QWindowsGeometryHint
69 QWindowsGeometryHint() {}
70 explicit QWindowsGeometryHint(const QWindow *w);
71 static QMargins frame(DWORD style, DWORD exStyle);
72 #ifndef Q_OS_WINCE //MinMax maybe define struct if not available
73 void applyToMinMaxInfo(DWORD style, DWORD exStyle, MINMAXINFO *mmi) const;
74 void applyToMinMaxInfo(HWND hwnd, MINMAXINFO *mmi) const;
76 bool validSize(const QSize &s) const;
78 static inline QPoint mapToGlobal(HWND hwnd, const QPoint &);
79 static inline QPoint mapToGlobal(const QWindow *w, const QPoint &);
80 static inline QPoint mapFromGlobal(const HWND hwnd, const QPoint &);
81 static inline QPoint mapFromGlobal(const QWindow *w, const QPoint &);
83 static bool positionIncludesFrame(const QWindow *w);
89 struct QWindowCreationContext
91 QWindowCreationContext(const QWindow *w, const QRect &r,
92 DWORD style, DWORD exStyle);
93 #ifndef Q_OS_WINCE //MinMax maybe define struct if not available
94 void applyToMinMaxInfo(MINMAXINFO *mmi) const
95 { geometryHint.applyToMinMaxInfo(style, exStyle, mmi); }
98 QWindowsGeometryHint geometryHint;
101 QRect requestedGeometry;
102 QRect obtainedGeometry;
104 int frameX; // Passed on to CreateWindowEx(), including frame.
110 class QWindowsWindow : public QPlatformWindow
113 #ifdef QT_OPENGL_ES_2
114 typedef QSharedPointer<QWindowsEGLStaticContext> QWindowsEGLStaticContextPtr;
119 DCFromBeginPaint = 0x1,
120 WithinSetParent = 0x2,
121 FrameDirty = 0x4, //! Frame outdated by setStyle, recalculate in next query.
122 OpenGLSurface = 0x10,
123 OpenGLDoubleBuffered = 0x20,
124 OpenGlPixelFormatInitialized = 0x40,
125 BlockedByModal = 0x80,
126 SizeGripOperation = 0x100,
127 FrameStrutEventsEnabled = 0x200
132 WindowData() : hwnd(0) {}
134 Qt::WindowFlags flags;
136 QMargins frame; // Do not use directly for windows, see FrameDirty.
140 static WindowData create(const QWindow *w,
141 const WindowData ¶meters,
142 const QString &title);
145 QWindowsWindow(QWindow *window, const WindowData &data);
148 virtual QSurfaceFormat format() const { return m_format; }
149 virtual void setGeometry(const QRect &rect);
150 virtual QRect geometry() const { return m_data.geometry; }
152 virtual void setVisible(bool visible);
153 bool isVisible() const;
154 virtual bool isActive() const;
155 virtual Qt::WindowFlags setWindowFlags(Qt::WindowFlags flags);
156 virtual Qt::WindowState setWindowState(Qt::WindowState state);
158 HWND handle() const { return m_data.hwnd; }
160 virtual WId winId() const { return WId(m_data.hwnd); }
161 virtual void setParent(const QPlatformWindow *window);
163 virtual void setWindowTitle(const QString &title);
164 virtual void raise();
165 virtual void lower();
167 void windowEvent(QEvent *event);
169 virtual void propagateSizeHints();
170 virtual QMargins frameMargins() const;
172 virtual void setOpacity(qreal level);
173 virtual void setMask(const QRegion ®ion);
174 qreal opacity() const { return m_opacity; }
175 virtual void requestActivateWindow();
177 virtual bool setKeyboardGrabEnabled(bool grab);
178 virtual bool setMouseGrabEnabled(bool grab);
180 virtual bool startSystemResize(const QPoint &pos, Qt::Corner corner);
182 void setFrameStrutEventsEnabled(bool enabled);
183 bool frameStrutEventsEnabled() const { return testFlag(FrameStrutEventsEnabled); }
185 Qt::WindowState windowState_sys() const;
186 Qt::WindowStates windowStates_sys() const;
188 #ifdef QT_OPENGL_ES_2
189 EGLSurface eglSurfaceHandle() const { return m_eglSurface;}
190 EGLSurface ensureEglSurfaceHandle(const QWindowsEGLStaticContextPtr &staticContext, EGLConfig config);
193 inline unsigned style() const
194 { return GetWindowLongPtr(m_data.hwnd, GWL_STYLE); }
195 void setStyle(unsigned s) const;
196 inline unsigned exStyle() const
197 { return GetWindowLongPtr(m_data.hwnd, GWL_EXSTYLE); }
198 void setExStyle(unsigned s) const;
200 bool handleWmPaint(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
203 void handleResized(int wParam);
207 static inline HWND handleOf(const QWindow *w);
208 static inline QWindowsWindow *baseWindowOf(const QWindow *w);
209 static QWindow *topLevelOf(QWindow *w);
210 static inline void *userDataOf(HWND hwnd);
211 static inline void setUserDataOf(HWND hwnd, void *ud);
215 #ifndef Q_OS_WINCE // maybe available on some SDKs revisit WM_GETMINMAXINFO
216 void getSizeHints(MINMAXINFO *mmi) const;
219 QWindowsWindowCursor cursor() const { return m_cursor; }
220 void setCursor(const QWindowsWindowCursor &c);
223 QWindowsWindow *childAt(const QPoint &clientPoint,
224 unsigned cwexflags = CWP_SKIPINVISIBLE) const;
225 QWindowsWindow *childAtScreenPoint(const QPoint &screenPoint,
226 unsigned cwexflags = CWP_SKIPINVISIBLE) const;
228 static QByteArray debugWindowFlags(Qt::WindowFlags wf);
230 inline bool testFlag(unsigned f) const { return (m_flags & f) != 0; }
231 inline void setFlag(unsigned f) const { m_flags |= f; }
232 inline void clearFlag(unsigned f) const { m_flags &= ~f; }
234 void setEnabled(bool enabled);
235 bool isEnabled() const;
238 void alertWindow(int durationMs = 0);
239 void stopAlertWindow();
243 inline void show_sys() const;
244 inline void hide_sys() const;
245 inline void setGeometry_sys(const QRect &rect) const;
246 inline QRect frameGeometry_sys() const;
247 inline QRect geometry_sys() const;
248 inline WindowData setWindowFlags_sys(Qt::WindowFlags wt, unsigned flags = 0) const;
249 inline bool isFullScreen_sys() const;
250 inline void setWindowState_sys(Qt::WindowState newState);
251 inline void setParent_sys(const QPlatformWindow *parent) const;
252 inline void setMouseGrabEnabled_sys(bool grab);
253 void destroyWindow();
254 void registerDropSite();
255 void unregisterDropSite();
256 void handleGeometryChange();
257 void handleWindowStateChange(Qt::WindowState state);
259 mutable WindowData m_data;
260 mutable unsigned m_flags;
262 Qt::WindowState m_windowState;
265 QWindowsWindowCursor m_cursor;
266 QWindowsOleDropTarget *m_dropTarget;
267 unsigned m_savedStyle;
268 QRect m_savedFrameGeometry;
269 const QSurfaceFormat m_format;
270 #ifdef QT_OPENGL_ES_2
271 EGLSurface m_eglSurface;
272 QSharedPointer<QWindowsEGLStaticContext> m_staticEglContext;
276 // Conveniences for window frames.
277 inline QRect operator+(const QRect &r, const QMargins &m)
279 return r.adjusted(-m.left(), -m.top(), m.right(), m.bottom());
282 inline QRect operator-(const QRect &r, const QMargins &m)
284 return r.adjusted(m.left(), m.top(), -m.right(), -m.bottom());
288 QDebug operator<<(QDebug d, const RECT &r);
289 #ifndef Q_OS_WINCE // maybe available on some SDKs revisit WM_GETMINMAXINFO/WM_NCCALCSIZE
290 QDebug operator<<(QDebug d, const MINMAXINFO &i);
291 QDebug operator<<(QDebug d, const NCCALCSIZE_PARAMS &p);
294 // ---------- QWindowsGeometryHint inline functions.
295 QPoint QWindowsGeometryHint::mapToGlobal(HWND hwnd, const QPoint &qp)
297 POINT p = { qp.x(), qp.y() };
298 ClientToScreen(hwnd, &p);
299 return QPoint(p.x, p.y);
302 QPoint QWindowsGeometryHint::mapFromGlobal(const HWND hwnd, const QPoint &qp)
304 POINT p = { qp.x(), qp.y() };
305 ScreenToClient(hwnd, &p);
306 return QPoint(p.x, p.y);
309 QPoint QWindowsGeometryHint::mapToGlobal(const QWindow *w, const QPoint &p)
310 { return QWindowsGeometryHint::mapToGlobal(QWindowsWindow::handleOf(w), p); }
312 QPoint QWindowsGeometryHint::mapFromGlobal(const QWindow *w, const QPoint &p)
313 { return QWindowsGeometryHint::mapFromGlobal(QWindowsWindow::handleOf(w), p); }
316 // ---------- QWindowsBaseWindow inline functions.
318 QWindowsWindow *QWindowsWindow::baseWindowOf(const QWindow *w)
321 if (QPlatformWindow *pw = w->handle())
322 return static_cast<QWindowsWindow *>(pw);
326 HWND QWindowsWindow::handleOf(const QWindow *w)
328 if (const QWindowsWindow *bw = QWindowsWindow::baseWindowOf(w))
333 void *QWindowsWindow::userDataOf(HWND hwnd)
335 return (void *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
338 void QWindowsWindow::setUserDataOf(HWND hwnd, void *ud)
340 SetWindowLongPtr(hwnd, GWLP_USERDATA, LONG_PTR(ud));
345 #endif // QWINDOWSWINDOW_H