Fix ignoring close events on OSX

QNSWindowDelegate was not handling windowShouldClose, which is how you
can tell Cocoa that your window should not close if the close button is
pressed. This change moves the close handling from windowWillClose to
windowShouldClose, and adds an optional "accepted" pointer to
QWindowSystemInterface::handleCloseEvent so that QNSWindowDelegate can
return a true/false value for whether the window should actually close

Task-number: QTBUG-28965
Change-Id: I67c6296ad42cbeeb71413e05411467d4e558adb4
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
This commit is contained in:
Josh Faust 2013-03-14 15:13:34 -07:00 committed by The Qt Project
parent e12d384d7b
commit c90d9b697f
8 changed files with 20 additions and 10 deletions

View File

@ -1740,6 +1740,9 @@ void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::Cl
QCloseEvent event;
QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
if (e->accepted) {
*(e->accepted) = !event.isAccepted();
}
}
void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)

View File

@ -140,11 +140,11 @@ void QWindowSystemInterface::handleGeometryChange(QWindow *tlw, const QRect &new
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
void QWindowSystemInterface::handleCloseEvent(QWindow *tlw)
void QWindowSystemInterface::handleCloseEvent(QWindow *tlw, bool *accepted)
{
if (tlw) {
QWindowSystemInterfacePrivate::CloseEvent *e =
new QWindowSystemInterfacePrivate::CloseEvent(tlw);
new QWindowSystemInterfacePrivate::CloseEvent(tlw, accepted);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
}

View File

@ -131,7 +131,7 @@ public:
static void handleTouchCancelEvent(QWindow *w, ulong timestamp, QTouchDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier);
static void handleGeometryChange(QWindow *w, const QRect &newRect);
static void handleCloseEvent(QWindow *w);
static void handleCloseEvent(QWindow *w, bool *accepted = 0);
static void handleEnterEvent(QWindow *w, const QPointF &local = QPointF(), const QPointF& global = QPointF());
static void handleLeaveEvent(QWindow *w);
static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local = QPointF(), const QPointF& global = QPointF());

View File

@ -105,9 +105,11 @@ public:
class CloseEvent : public WindowSystemEvent {
public:
explicit CloseEvent(QWindow *w)
: WindowSystemEvent(Close), window(w) { }
explicit CloseEvent(QWindow *w, bool *a = 0)
: WindowSystemEvent(Close), window(w), accepted(a)
{ }
QPointer<QWindow> window;
bool *accepted;
};
class GeometryChangeEvent : public WindowSystemEvent {

View File

@ -132,7 +132,7 @@ public:
void windowWillMove();
void windowDidMove();
void windowDidResize();
void windowWillClose();
bool windowShouldClose();
bool windowIsPopupType(Qt::WindowType type = Qt::Widget) const;
NSInteger windowLevel(Qt::WindowFlags flags);

View File

@ -684,10 +684,12 @@ void QCocoaWindow::windowDidResize()
[m_qtView updateGeometry];
}
void QCocoaWindow::windowWillClose()
bool QCocoaWindow::windowShouldClose()
{
QWindowSystemInterface::handleCloseEvent(window());
bool accepted = false;
QWindowSystemInterface::handleCloseEvent(window(), &accepted);
QWindowSystemInterface::flushWindowSystemEvents();
return accepted;
}
bool QCocoaWindow::windowIsPopupType(Qt::WindowType type) const

View File

@ -56,6 +56,7 @@
- (void)windowDidResize:(NSNotification *)notification;
- (void)windowDidMove:(NSNotification *)notification;
- (void)windowWillClose:(NSNotification *)notification;
- (BOOL)windowShouldClose:(NSNotification *)notification;
@end

View File

@ -80,12 +80,14 @@
}
}
- (void)windowWillClose:(NSNotification *)notification
- (BOOL)windowShouldClose:(NSNotification *)notification
{
Q_UNUSED(notification);
if (m_cocoaWindow) {
m_cocoaWindow->windowWillClose();
return m_cocoaWindow->windowShouldClose();
}
return YES;
}
@end