- (BOOL)canBecomeKeyWindow
{
// Most panels can be come the key window. Exceptions are:
- if (m_cocoaPlatformWindow->window()->windowType() == Qt::ToolTip)
+ if (m_cocoaPlatformWindow->window()->type() == Qt::ToolTip)
return NO;
- if (m_cocoaPlatformWindow->window()->windowType() == Qt::SplashScreen)
+ if (m_cocoaPlatformWindow->window()->type() == Qt::SplashScreen)
return NO;
return YES;
}
QCocoaWindow::QCocoaWindow(QWindow *tlw)
: QPlatformWindow(tlw)
, m_nsWindow(0)
+ , m_nsWindowDelegate(0)
, m_synchedWindowState(Qt::WindowActive)
, m_windowModality(Qt::NonModal)
, m_inConstructor(true)
clearNSWindow(m_nsWindow);
[m_contentView release];
[m_nsWindow release];
+ [m_nsWindowDelegate release];
}
void QCocoaWindow::setGeometry(const QRect &rect)
#endif
if (visible) {
// We need to recreate if the modality has changed as the style mask will need updating
- if (m_windowModality != window()->windowModality())
+ if (m_windowModality != window()->modality())
recreateWindow(parent());
QCocoaWindow *parentCocoaWindow = 0;
if (window()->transientParent()) {
// Register popup windows so that the parent window can
// close them when needed.
- if (window()->windowType() == Qt::Popup) {
- // qDebug() << "transientParent and popup" << window()->windowType() << Qt::Popup << (window()->windowType() & Qt::Popup);
+ if (window()->type() == Qt::Popup) {
+ // qDebug() << "transientParent and popup" << window()->type() << Qt::Popup << (window()->type() & Qt::Popup);
parentCocoaWindow->m_activePopupWindow = window();
}
syncWindowState(window()->windowState());
if (window()->windowState() != Qt::WindowMinimized) {
- if ((window()->windowModality() == Qt::WindowModal
- || window()->windowType() == Qt::Sheet)
+ if ((window()->modality() == Qt::WindowModal
+ || window()->type() == Qt::Sheet)
&& parentCocoaWindow) {
// show the window as a sheet
[NSApp beginSheet:m_nsWindow modalForWindow:parentCocoaWindow->m_nsWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
- } else if (window()->windowModality() != Qt::NonModal) {
+ } else if (window()->modality() != Qt::NonModal) {
// show the window as application modal
QCocoaEventDispatcher *cocoaEventDispatcher = qobject_cast<QCocoaEventDispatcher *>(QGuiApplication::instance()->eventDispatcher());
Q_ASSERT(cocoaEventDispatcher != 0);
}
// We want the events to properly reach the popup
- if (window()->windowType() == Qt::Popup)
+ if (window()->type() == Qt::Popup)
[(NSPanel *)m_nsWindow setWorksWhenModal:YES];
}
}
Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint;
if (flags == Qt::Window) {
styleMask = (NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTitledWindowMask);
- } else if ((flags & Qt::Dialog) && (window()->windowModality() != Qt::NonModal)) {
+ } else if ((flags & Qt::Dialog) && (window()->modality() != Qt::NonModal)) {
styleMask = NSTitledWindowMask;
} else if (!(flags & Qt::FramelessWindowHint)) {
if (flags & Qt::WindowMaximizeButtonHint)
[m_nsWindow setHasShadow:(keepShadow ? YES : NO)];
}
-Qt::WindowFlags QCocoaWindow::setWindowFlags(Qt::WindowFlags flags)
+void QCocoaWindow::setWindowFlags(Qt::WindowFlags flags)
{
if (m_nsWindow) {
NSUInteger styleMask = windowStyleMask(flags);
}
m_windowFlags = flags;
- return m_windowFlags;
}
-Qt::WindowState QCocoaWindow::setWindowState(Qt::WindowState state)
+void QCocoaWindow::setWindowState(Qt::WindowState state)
{
if ([m_nsWindow isVisible])
syncWindowState(state); // Window state set for hidden windows take effect when show() is called.
-
- return state;
}
void QCocoaWindow::setWindowTitle(const QString &title)
[m_nsWindow setRepresentedFilename: fi.exists() ? QCFString::toNSString(filePath) : @""];
}
+void QCocoaWindow::setWindowIcon(const QIcon &icon)
+{
+ QCocoaAutoReleasePool pool;
+
+ NSButton *iconButton = [m_nsWindow standardWindowButton:NSWindowDocumentIconButton];
+ if (iconButton == nil) {
+ NSString *title = QCFString::toNSString(window()->title());
+ [m_nsWindow setRepresentedURL:[NSURL fileURLWithPath:title]];
+ iconButton = [m_nsWindow standardWindowButton:NSWindowDocumentIconButton];
+ }
+ if (icon.isNull()) {
+ [iconButton setImage:nil];
+ } else {
+ QPixmap pixmap = icon.pixmap(QSize(22, 22));
+ NSImage *image = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap));
+ [iconButton setImage:image];
+ [image release];
+ }
+}
+
void QCocoaWindow::raise()
{
//qDebug() << "raise" << this;
[m_nsWindow setAlphaValue:level];
}
+void QCocoaWindow::setMask(const QRegion ®ion)
+{
+ if (m_nsWindow) {
+ [m_nsWindow setOpaque:NO];
+ [m_nsWindow setBackgroundColor:[NSColor clearColor]];
+ }
+
+ [m_contentView setMaskRegion:®ion];
+}
+
bool QCocoaWindow::setKeyboardGrabEnabled(bool grab)
{
if (!m_nsWindow)
bool QCocoaWindow::windowIsPopupType(Qt::WindowType type) const
{
if (type == Qt::Widget)
- type = window()->windowType();
+ type = window()->type();
if (type == Qt::Tool)
return false; // Qt::Tool has the Popup bit set but isn't, at least on Mac.
[m_nsWindow close];
[m_nsWindow release];
m_nsWindow = 0;
+ [m_nsWindowDelegate release];
+ m_nsWindowDelegate = 0;
}
if (!parentWindow) {
// QPlatformWindow subclasses must sync up with QWindow on creation:
propagateSizeHints();
- setWindowFlags(window()->windowFlags());
- setWindowTitle(window()->windowTitle());
+ setWindowFlags(window()->flags());
+ setWindowTitle(window()->title());
setWindowState(window()->windowState());
} else {
// Child windows have no NSWindow, link the NSViews instead.
NSRect frame = qt_mac_flipRect(window()->geometry(), window());
- Qt::WindowType type = window()->windowType();
- Qt::WindowFlags flags = window()->windowFlags();
+ Qt::WindowType type = window()->type();
+ Qt::WindowFlags flags = window()->flags();
NSUInteger styleMask = windowStyleMask(flags);
NSWindow *createdWindow = 0;
NSInteger level = windowLevel(flags);
[createdWindow setLevel:level];
- m_windowModality = window()->windowModality();
+ m_windowModality = window()->modality();
return createdWindow;
}
void QCocoaWindow::setNSWindow(NSWindow *window)
{
- QNSWindowDelegate *delegate = [[QNSWindowDelegate alloc] initWithQCocoaWindow:this];
- [window setDelegate:delegate];
+ m_nsWindowDelegate = [[QNSWindowDelegate alloc] initWithQCocoaWindow:this];
+ [window setDelegate:m_nsWindowDelegate];
[window setAcceptsMouseMovedEvents:YES];
// Prevent Cocoa from releasing the window on close. Qt
name:nil // Get all notifications
object:m_nsWindow];
- // ### Accept touch events by default.
- // Beware that enabling touch events has a negative impact on the overall performance.
- // We probably need a QWindowSystemInterface API to enable/disable touch events.
- [m_contentView setAcceptsTouchEvents:YES];
-
[window setContentView:m_contentView];
}
void QCocoaWindow::clearNSWindow(NSWindow *window)
{
+ [window setContentView:nil];
[window setDelegate:nil];
[window clearPlatformWindow];
[[NSNotificationCenter defaultCenter] removeObserver:m_contentView];