1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the plugins of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
42
#ifndef QCOCOAWINDOW_H
43
#define QCOCOAWINDOW_H
45
#include <Cocoa/Cocoa.h>
47
#include <qpa/qplatformwindow.h>
50
#include "qcocoaglcontext.h"
52
class QT_PREPEND_NAMESPACE(QCocoaWindow);
54
@interface QNSWindow : NSWindow {
55
@public QCocoaWindow *m_cocoaPlatformWindow;
58
- (void)clearPlatformWindow;
59
- (BOOL)canBecomeKeyWindow;
62
@interface QNSPanel : NSPanel {
63
@public QT_PREPEND_NAMESPACE(QCocoaWindow) *m_cocoaPlatformWindow;
65
- (void)clearPlatformWindow;
66
- (BOOL)canBecomeKeyWindow;
69
@class QNSWindowDelegate;
74
// QCocoaWindow is an NSView (not an NSWindow!) in the sense
75
// that it relies on a NSView for all event handling and
76
// graphics output and does not require a NSWindow, except for
77
// for the window-related functions like setWindowTitle.
79
// As a consequence of this it is possible to embed the QCocoaWindow
80
// in an NSView hierarchy by getting a pointer to the "backing"
81
// NSView and not calling QCocoaWindow::show():
83
// QWindow *qtWindow = new MyWindow();
84
// qtWindow->create();
85
// QPlatformNativeInterface *platformNativeInterface = QGuiApplication::platformNativeInterface();
86
// NSView *qtView = (NSView *)platformNativeInterface->nativeResourceForWindow("nsview", qtWindow);
87
// [parentView addSubview:qtView];
89
// See the qt_on_cocoa manual tests for a working example, located
90
// in tests/manual/cocoa at the time of writing.
94
class QCocoaWindow : public QPlatformWindow
97
QCocoaWindow(QWindow *tlw);
100
void setGeometry(const QRect &rect);
101
void setCocoaGeometry(const QRect &rect);
102
void setVisible(bool visible);
103
void setWindowFlags(Qt::WindowFlags flags);
104
void setWindowState(Qt::WindowState state);
105
void setWindowTitle(const QString &title);
106
void setWindowFilePath(const QString &filePath);
107
void setWindowIcon(const QIcon &icon);
110
void propagateSizeHints();
111
void setOpacity(qreal level);
112
void setMask(const QRegion ®ion);
113
bool setKeyboardGrabEnabled(bool grab);
114
bool setMouseGrabEnabled(bool grab);
115
QMargins frameMargins() const;
118
void setParent(const QPlatformWindow *window);
120
NSView *contentView() const;
122
void windowWillMove();
123
void windowDidMove();
124
void windowDidResize();
125
void windowWillClose();
126
bool windowIsPopupType(Qt::WindowType type = Qt::Widget) const;
128
NSInteger windowLevel(Qt::WindowFlags flags);
129
NSUInteger windowStyleMask(Qt::WindowFlags flags);
130
void setWindowShadow(Qt::WindowFlags flags);
132
void setCurrentContext(QCocoaGLContext *context);
133
QCocoaGLContext *currentContext() const;
135
bool setWindowModified(bool modified) Q_DECL_OVERRIDE;
137
void setFrameStrutEventsEnabled(bool enabled);
138
bool frameStrutEventsEnabled() const
139
{ return m_frameStrutEventsEnabled; }
141
void setMenubar(QCocoaMenuBar *mb);
142
QCocoaMenuBar *menubar() const;
144
qreal devicePixelRatio() const;
146
// NSWindow handling. The QCocoaWindow/QNSView can either be displayed
147
// in an existing NSWindow or in one created by Qt.
148
void recreateWindow(const QPlatformWindow *parentWindow);
149
NSWindow *createNSWindow();
150
void setNSWindow(NSWindow *window);
151
void clearNSWindow(NSWindow *window);
153
QRect windowGeometry() const;
154
QCocoaWindow *parentCocoaWindow() const;
155
void syncWindowState(Qt::WindowState newState);
158
public: // for QNSView
159
friend class QCocoaBackingStore;
160
friend class QCocoaNativeInterface;
162
QNSView *m_contentView;
163
NSWindow *m_nsWindow;
164
QNSWindowDelegate *m_nsWindowDelegate;
165
Qt::WindowFlags m_windowFlags;
166
Qt::WindowState m_synchedWindowState;
167
Qt::WindowModality m_windowModality;
168
QPointer<QWindow> m_activePopupWindow;
170
bool m_inConstructor;
171
QCocoaGLContext *m_glContext;
172
QCocoaMenuBar *m_menubar;
174
bool m_hasModalSession;
175
bool m_frameStrutEventsEnabled;
180
#endif // QCOCOAWINDOW_H