~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/plugins/platforms/cocoa/qcocoawindow.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the plugins of the Qt Toolkit.
 
7
**
 
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.
 
16
**
 
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.
 
24
**
 
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.
 
28
**
 
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.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef QCOCOAWINDOW_H
 
43
#define QCOCOAWINDOW_H
 
44
 
 
45
#include <Cocoa/Cocoa.h>
 
46
 
 
47
#include <qpa/qplatformwindow.h>
 
48
#include <QRect>
 
49
 
 
50
#include "qcocoaglcontext.h"
 
51
#include "qnsview.h"
 
52
class QT_PREPEND_NAMESPACE(QCocoaWindow);
 
53
 
 
54
@interface QNSWindow : NSWindow {
 
55
    @public QCocoaWindow *m_cocoaPlatformWindow;
 
56
}
 
57
 
 
58
- (void)clearPlatformWindow;
 
59
- (BOOL)canBecomeKeyWindow;
 
60
@end
 
61
 
 
62
@interface QNSPanel : NSPanel {
 
63
    @public QT_PREPEND_NAMESPACE(QCocoaWindow) *m_cocoaPlatformWindow;
 
64
}
 
65
- (void)clearPlatformWindow;
 
66
- (BOOL)canBecomeKeyWindow;
 
67
@end
 
68
 
 
69
@class QNSWindowDelegate;
 
70
 
 
71
QT_BEGIN_NAMESPACE
 
72
// QCocoaWindow
 
73
//
 
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.
 
78
//
 
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():
 
82
//
 
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];
 
88
//
 
89
// See the qt_on_cocoa manual tests for a working example, located
 
90
// in tests/manual/cocoa at the time of writing.
 
91
 
 
92
class QCocoaMenuBar;
 
93
 
 
94
class QCocoaWindow : public QPlatformWindow
 
95
{
 
96
public:
 
97
    QCocoaWindow(QWindow *tlw);
 
98
    ~QCocoaWindow();
 
99
 
 
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);
 
108
    void raise();
 
109
    void lower();
 
110
    void propagateSizeHints();
 
111
    void setOpacity(qreal level);
 
112
    void setMask(const QRegion &region);
 
113
    bool setKeyboardGrabEnabled(bool grab);
 
114
    bool setMouseGrabEnabled(bool grab);
 
115
    QMargins frameMargins() const;
 
116
 
 
117
    WId winId() const;
 
118
    void setParent(const QPlatformWindow *window);
 
119
 
 
120
    NSView *contentView() const;
 
121
 
 
122
    void windowWillMove();
 
123
    void windowDidMove();
 
124
    void windowDidResize();
 
125
    void windowWillClose();
 
126
    bool windowIsPopupType(Qt::WindowType type = Qt::Widget) const;
 
127
 
 
128
    NSInteger windowLevel(Qt::WindowFlags flags);
 
129
    NSUInteger windowStyleMask(Qt::WindowFlags flags);
 
130
    void setWindowShadow(Qt::WindowFlags flags);
 
131
 
 
132
    void setCurrentContext(QCocoaGLContext *context);
 
133
    QCocoaGLContext *currentContext() const;
 
134
 
 
135
    bool setWindowModified(bool modified) Q_DECL_OVERRIDE;
 
136
 
 
137
    void setFrameStrutEventsEnabled(bool enabled);
 
138
    bool frameStrutEventsEnabled() const
 
139
        { return m_frameStrutEventsEnabled; }
 
140
 
 
141
    void setMenubar(QCocoaMenuBar *mb);
 
142
    QCocoaMenuBar *menubar() const;
 
143
 
 
144
    qreal devicePixelRatio() const;
 
145
protected:
 
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);
 
152
 
 
153
    QRect windowGeometry() const;
 
154
    QCocoaWindow *parentCocoaWindow() const;
 
155
    void syncWindowState(Qt::WindowState newState);
 
156
 
 
157
// private:
 
158
public: // for QNSView
 
159
    friend class QCocoaBackingStore;
 
160
    friend class QCocoaNativeInterface;
 
161
 
 
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;
 
169
 
 
170
    bool m_inConstructor;
 
171
    QCocoaGLContext *m_glContext;
 
172
    QCocoaMenuBar *m_menubar;
 
173
 
 
174
    bool m_hasModalSession;
 
175
    bool m_frameStrutEventsEnabled;
 
176
};
 
177
 
 
178
QT_END_NAMESPACE
 
179
 
 
180
#endif // QCOCOAWINDOW_H
 
181