Qt 4.8
qcocoawindow.mm
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 #include "qcocoawindow.h"
42 #include "qnswindowdelegate.h"
43 #include "qcocoaautoreleasepool.h"
44 
45 #include <QWidget>
46 
47 #include <QtGui/QApplication>
48 
49 #include <QWindowSystemInterface>
50 
51 #include <QDebug>
52 
54  : QPlatformWindow(tlw)
55 {
57  const QRect geo = tlw->geometry();
58  NSRect frame = NSMakeRect(geo.x(), geo.y(), geo.width(), geo.height());
59 
60  m_nsWindow = [[NSWindow alloc] initWithContentRect:frame
61  styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask
62  backing:NSBackingStoreBuffered
63  defer:YES];
64 
65  QNSWindowDelegate *delegate = [[QNSWindowDelegate alloc] initWithQCocoaWindow:this];
66  [m_nsWindow setDelegate:delegate];
67 
68  [m_nsWindow makeKeyAndOrderFront:nil];
69  [m_nsWindow setAcceptsMouseMovedEvents:YES];
70 
71 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
72  if ([m_nsWindow respondsToSelector:@selector(setRestorable:)])
73  [m_nsWindow setRestorable: NO];
74 #endif
75 }
76 
78 {
79 }
80 
82 {
84 
85  NSRect bounds = NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height());
86  [[m_nsWindow contentView]setFrameSize:bounds.size];
87 }
88 
89 void QCocoaWindow::setVisible(bool visible)
90 {
91  Q_UNUSED(visible);
92 }
93 
95 {
96  return WId([m_nsWindow windowNumber]);
97 }
98 
100 {
101  return [m_nsWindow contentView];
102 }
103 
105 {
107 }
108 
110 {
111  //jlind: XXX This isn't ideal. Eventdispatcher does not run when resizing...
112  NSRect rect = [[m_nsWindow contentView]frame];
113  QRect geo(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
115 }
unsigned long WId
Definition: qwindowdefs.h:119
void setVisible(bool visible)
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false...
Definition: qcocoawindow.mm:89
virtual void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or the window is resized.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
NSWindow * m_nsWindow
Definition: qcocoawindow.h:69
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
NSView * contentView() const
Definition: qcocoawindow.mm:99
The QPlatformWindow class provides an abstraction for top-level windows.
void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or the window is resized.
Definition: qcocoawindow.mm:81
void windowDidResize()
QCocoaWindow(QWidget *tlw)
Definition: qcocoawindow.mm:53
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
static void handleGeometryChange(QWidget *w, const QRect &newRect)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
WId winId() const
Reimplement in subclasses to return a handle to the native window.
Definition: qcocoawindow.mm:94
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
void setContentView(NSView *contentView)
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.