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
131 WindowData() : hwnd(0) {}
133 Qt::WindowFlags flags;
135 QMargins frame; // Do not use directly for windows, see FrameDirty.
139 static WindowData create(const QWindow *w,
140 const WindowData ¶meters,
141 const QString &title);
144 QWindowsWindow(QWindow *window, const WindowData &data);
147 virtual QSurfaceFormat format() const { return m_format; }
148 virtual void setGeometry(const QRect &rect);
149 virtual QRect geometry() const { return m_data.geometry; }
151 virtual void setVisible(bool visible);
152 bool isVisible() const;
153 virtual Qt::WindowFlags setWindowFlags(Qt::WindowFlags flags);
154 virtual Qt::WindowState setWindowState(Qt::WindowState state);
156 HWND handle() const { return m_data.hwnd; }
158 virtual WId winId() const { return WId(m_data.hwnd); }
159 virtual void setParent(const QPlatformWindow *window);
161 virtual void setWindowTitle(const QString &title);
162 virtual void raise();
163 virtual void lower();
165 void windowEvent(QEvent *event);
167 virtual void propagateSizeHints();
168 virtual QMargins frameMargins() const;
170 virtual void setOpacity(qreal level);
171 qreal opacity() const { return m_opacity; }
172 virtual void requestActivateWindow();
174 virtual bool setKeyboardGrabEnabled(bool grab);
175 virtual bool setMouseGrabEnabled(bool grab);
177 virtual bool startSystemResize(const QPoint &pos, Qt::Corner corner);
179 Qt::WindowState windowState_sys() const;
180 Qt::WindowStates windowStates_sys() const;
182 #ifdef QT_OPENGL_ES_2
183 EGLSurface eglSurfaceHandle() const { return m_eglSurface;}
184 EGLSurface ensureEglSurfaceHandle(const QWindowsEGLStaticContextPtr &staticContext, EGLConfig config);
187 inline unsigned style() const
188 { return GetWindowLongPtr(m_data.hwnd, GWL_STYLE); }
189 void setStyle(unsigned s) const;
190 inline unsigned exStyle() const
191 { return GetWindowLongPtr(m_data.hwnd, GWL_EXSTYLE); }
192 void setExStyle(unsigned s) const;
194 bool handleWmPaint(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
197 void handleResized(int wParam);
201 static inline HWND handleOf(const QWindow *w);
202 static inline QWindowsWindow *baseWindowOf(const QWindow *w);
203 static QWindow *topLevelOf(QWindow *w);
204 static inline void *userDataOf(HWND hwnd);
205 static inline void setUserDataOf(HWND hwnd, void *ud);
209 #ifndef Q_OS_WINCE // maybe available on some SDKs revisit WM_GETMINMAXINFO
210 void getSizeHints(MINMAXINFO *mmi) const;
213 QWindowsWindowCursor cursor() const { return m_cursor; }
214 void setCursor(const QWindowsWindowCursor &c);
217 QWindowsWindow *childAt(const QPoint &clientPoint,
218 unsigned cwexflags = CWP_SKIPINVISIBLE) const;
219 QWindowsWindow *childAtScreenPoint(const QPoint &screenPoint,
220 unsigned cwexflags = CWP_SKIPINVISIBLE) const;
222 static QByteArray debugWindowFlags(Qt::WindowFlags wf);
224 inline bool testFlag(unsigned f) const { return (m_flags & f) != 0; }
225 inline void setFlag(unsigned f) const { m_flags |= f; }
226 inline void clearFlag(unsigned f) const { m_flags &= ~f; }
228 void setEnabled(bool enabled);
229 bool isEnabled() const;
232 void alertWindow(int durationMs = 0);
233 void stopAlertWindow();
237 inline void show_sys() const;
238 inline void hide_sys() const;
239 inline void setGeometry_sys(const QRect &rect) const;
240 inline QRect frameGeometry_sys() const;
241 inline QRect geometry_sys() const;
242 inline WindowData setWindowFlags_sys(Qt::WindowFlags wt, unsigned flags = 0) const;
243 inline void setWindowState_sys(Qt::WindowState newState);
244 inline void setParent_sys(const QPlatformWindow *parent) const;
245 inline void setMouseGrabEnabled_sys(bool grab);
246 void destroyWindow();
247 void registerDropSite();
248 void unregisterDropSite();
249 void handleGeometryChange();
250 void handleWindowStateChange(Qt::WindowState state);
252 mutable WindowData m_data;
253 mutable unsigned m_flags;
255 Qt::WindowState m_windowState;
258 QWindowsWindowCursor m_cursor;
259 QWindowsOleDropTarget *m_dropTarget;
260 unsigned m_savedStyle;
261 QRect m_savedFrameGeometry;
262 const QSurfaceFormat m_format;
263 #ifdef QT_OPENGL_ES_2
264 EGLSurface m_eglSurface;
265 QSharedPointer<QWindowsEGLStaticContext> m_staticEglContext;
269 // Conveniences for window frames.
270 inline QRect operator+(const QRect &r, const QMargins &m)
272 return r.adjusted(-m.left(), -m.top(), m.right(), m.bottom());
275 inline QRect operator-(const QRect &r, const QMargins &m)
277 return r.adjusted(m.left(), m.top(), -m.right(), -m.bottom());
281 QDebug operator<<(QDebug d, const RECT &r);
282 #ifndef Q_OS_WINCE // maybe available on some SDKs revisit WM_GETMINMAXINFO/WM_NCCALCSIZE
283 QDebug operator<<(QDebug d, const MINMAXINFO &i);
284 QDebug operator<<(QDebug d, const NCCALCSIZE_PARAMS &p);
287 // ---------- QWindowsGeometryHint inline functions.
288 QPoint QWindowsGeometryHint::mapToGlobal(HWND hwnd, const QPoint &qp)
290 POINT p = { qp.x(), qp.y() };
291 ClientToScreen(hwnd, &p);
292 return QPoint(p.x, p.y);
295 QPoint QWindowsGeometryHint::mapFromGlobal(const HWND hwnd, const QPoint &qp)
297 POINT p = { qp.x(), qp.y() };
298 ScreenToClient(hwnd, &p);
299 return QPoint(p.x, p.y);
302 QPoint QWindowsGeometryHint::mapToGlobal(const QWindow *w, const QPoint &p)
303 { return QWindowsGeometryHint::mapToGlobal(QWindowsWindow::handleOf(w), p); }
305 QPoint QWindowsGeometryHint::mapFromGlobal(const QWindow *w, const QPoint &p)
306 { return QWindowsGeometryHint::mapFromGlobal(QWindowsWindow::handleOf(w), p); }
309 // ---------- QWindowsBaseWindow inline functions.
311 QWindowsWindow *QWindowsWindow::baseWindowOf(const QWindow *w)
314 if (QPlatformWindow *pw = w->handle())
315 return static_cast<QWindowsWindow *>(pw);
319 HWND QWindowsWindow::handleOf(const QWindow *w)
321 if (const QWindowsWindow *bw = QWindowsWindow::baseWindowOf(w))
326 void *QWindowsWindow::userDataOf(HWND hwnd)
328 return (void *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
331 void QWindowsWindow::setUserDataOf(HWND hwnd, void *ud)
333 SetWindowLongPtr(hwnd, GWLP_USERDATA, LONG_PTR(ud));
338 #endif // QWINDOWSWINDOW_H