42 #import "private/qcocoawindowdelegate_mac_p.h" 43 #ifdef QT_MAC_USE_COCOA 44 #include <private/qwidget_p.h> 45 #include <private/qapplication_p.h> 46 #include <private/qt_cocoa_helpers_mac_p.h> 51 #include <QMainWindow> 53 #include <private/qmainwindowlayout_p.h> 54 #include <private/qpaintengine_mac_p.h> 70 static void cleanupCocoaWindowDelegate()
72 [sharedCocoaWindowDelegate release];
75 @implementation QT_MANGLE_NAMESPACE(QCocoaWindowDelegate)
89 sharedCocoaWindowDelegate = nil;
91 while (windowIt != m_windowHash->constEnd()) {
92 [windowIt.key() setDelegate:nil];
97 while (drawerIt != m_drawerHash->constEnd()) {
98 [drawerIt.key() setDelegate:nil];
105 + (id)allocWithZone:(NSZone *)zone
107 @
synchronized(
self) {
108 if (sharedCocoaWindowDelegate == nil) {
109 sharedCocoaWindowDelegate = [
super allocWithZone:zone];
110 return sharedCocoaWindowDelegate;
119 @
synchronized(
self) {
120 if (sharedCocoaWindowDelegate == nil)
123 return [[sharedCocoaWindowDelegate retain] autorelease];
126 -(void)syncSizeForWidget:(
QWidget *)qwidget toSize:(const
QSize &)newSize fromSize:(const
QSize &)oldSize
131 [view setFrameSize:NSMakeSize(newSize.width(), newSize.height())];
145 - (void)dumpMaximizedStateforWidget:(
QWidget*)qwidget window:(NSWindow *)window
157 - (NSSize)closestAcceptableSizeForWidget:(
QWidget *)qwidget window:(NSWindow *)window
158 withNewSize:(NSSize)proposedSize
160 [
self dumpMaximizedStateforWidget:qwidget window:window];
162 QSize(proposedSize.width, proposedSize.height));
163 return [NSWindow frameRectForContentRect:
164 NSMakeRect(0., 0., newSize.width(), newSize.height())
165 styleMask:[window styleMask]].size;
168 - (NSSize)windowWillResize:(NSWindow *)windowToResize toSize:(NSSize)proposedFrameSize
170 QWidget *qwidget = m_windowHash->value(windowToResize);
171 return [
self closestAcceptableSizeForWidget:qwidget window:windowToResize
172 withNewSize:[NSWindow contentRectForFrameRect:
174 proposedFrameSize.width,
175 proposedFrameSize.height)
176 styleMask:[windowToResize styleMask]].size];
179 - (NSSize)drawerWillResizeContents:(NSDrawer *)sender toSize:(NSSize)contentSize
181 QWidget *qwidget = m_drawerHash->value(sender);
182 return [
self closestAcceptableSizeForWidget:qwidget window:nil withNewSize:contentSize];
185 -(void)windowDidMiniaturize:(NSNotification*)notification
187 QWidget *qwidget = m_windowHash->value([notification
object]);
199 - (void)windowDidResize:(NSNotification *)notification
201 NSWindow *window = [notification object];
202 QWidget *qwidget = m_windowHash->value(window);
215 NSRect rect = [[window contentView] frame];
216 const QSize newSize(rect.size.width, rect.size.height);
218 if (newSize != oldSize) {
219 QWidgetPrivate::qt_mac_update_sizer(qwidget);
220 [
self syncSizeForWidget:qwidget toSize:newSize fromSize:oldSize];
225 if ([[window contentView] inLiveResize]) {
234 for (
int i = 0; i < toolbarList.size(); ++i) {
242 - (void)windowDidMove:(NSNotification *)notification
247 NSWindow *window = [notification object];
248 NSRect newRect = [window frame];
249 QWidget *qwidget = m_windowHash->value(window);
251 newRect.origin.y + newRect.size.height)).
toPoint();
254 if (qtPoint.
x() != oldRect.
x() || qtPoint.
y() != oldRect.
y()) {
259 widgetData->
crect.
moveTo(qtPoint.
x() + fStrut.
left(), qtPoint.y() + fStrut.top());
269 -(BOOL)windowShouldClose:(
id)windowThatWantsToClose
271 QWidget *qwidget = m_windowHash->value(windowThatWantsToClose);
276 -(void)windowDidDeminiaturize:(NSNotification *)notification
278 QWidget *qwidget = m_windowHash->value([notification
object]);
280 Qt::WindowStates currState = Qt::WindowStates(widgetData->
window_state);
281 Qt::WindowStates newState = currState;
286 if (newState != currState) {
295 -(void)windowDidBecomeMain:(NSNotification*)notification
297 QWidget *qwidget = m_windowHash->value([notification
object]);
302 -(void)windowDidResignMain:(NSNotification*)notification
304 QWidget *qwidget = m_windowHash->value([notification
object]);
311 -(void)windowDidBecomeKey:(NSNotification*)notification
313 QWidget *qwidget = m_windowHash->value([notification
object]);
318 -(void)windowDidResignKey:(NSNotification*)notification
320 QWidget *qwidget = m_windowHash->value([notification
object]);
325 -(
QWidget *)qt_qwidgetForWindow:(NSWindow *)window
327 return m_windowHash->value(window);
330 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
334 QWidget *qwidget = m_windowHash->value(window);
339 widgetPrivate->
topData()->wasMaximized =
false;
346 widgetPrivate->
topData()->wasMaximized =
true;
352 - (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)defaultFrame
354 NSRect frameToReturn = defaultFrame;
355 QWidget *qwidget = m_windowHash->value(window);
357 NSRect windowFrameRect = [window frame];
358 NSRect viewFrameRect = [[window contentView] frame];
360 frameToReturn.size.
width = qMin<CGFloat>(frameToReturn.size.width,
361 size.
width()+(windowFrameRect.size.width - viewFrameRect.size.width));
362 frameToReturn.size.
height = qMin<CGFloat>(frameToReturn.size.height,
363 size.
height()+(windowFrameRect.size.height - viewFrameRect.size.height));
364 return frameToReturn;
367 - (void)becomeDelegateForWindow:(NSWindow *)window widget:(
QWidget *)widget
369 m_windowHash->insert(window, widget);
370 [window setDelegate:self];
373 - (void)resignDelegateForWindow:(NSWindow *)window
375 [window setDelegate:nil];
376 m_windowHash->remove(window);
379 - (void)becomeDelegateForDrawer:(NSDrawer *)drawer widget:(
QWidget *)widget
381 m_drawerHash->insert(drawer, widget);
382 [drawer setDelegate:self];
383 NSWindow *window = [[drawer contentView] window];
384 [
self becomeDelegateForWindow:window widget:widget];
387 - (void)resignDelegateForDrawer:(NSDrawer *)drawer
389 QWidget *widget = m_drawerHash->value(drawer);
390 [drawer setDelegate:nil];
392 [
self resignDelegateForWindow:[[drawer contentView] window]];
393 m_drawerHash->remove(drawer);
396 - (void)windowDidChangeScreen:(NSNotification*)notification
398 QWidget *qwidget = m_windowHash->value([notification
object]);
402 - (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu
405 QWidget *qwidget = m_windowHash->value(window);
412 - (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event
413 from:(
NSPoint)dragImageLocation
414 withPasteboard:(NSPasteboard *)pasteboard
419 QWidget *qwidget = m_windowHash->value(window);
426 - (void)syncContentViewFrame: (NSNotification *)notification
428 NSView *cView = [notification object];
430 NSWindow *window = [cView window];
431 QWidget *qwidget = m_windowHash->value(window);
434 NSRect rect = [cView frame];
435 const QSize newSize(rect.size.width, rect.size.height);
437 if (newSize != oldSize) {
438 [
self syncSizeForWidget:qwidget toSize:newSize fromSize:oldSize];
446 #endif// QT_MAC_USE_COCOA T qobject_cast(QObject *object)
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
#define QT_END_NAMESPACE
This macro expands to.
void qAddPostRoutine(QtCleanUpFunction p)
qreal width() const
Returns the width.
qreal height() const
Returns the height.
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
QPointF flipPoint(const NSPoint &p)
The QHash class is a template class that provides a hash-table-based dictionary.
The QObject class is the base class of all Qt objects.
static QSize closestAcceptableSize(const QWidget *w, const QSize &s)
Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is ...
The QSizeF class defines the size of a two-dimensional object using floating point precision...
int width() const
Returns the width.
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QMoveEvent class contains event parameters for move events.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QSize size() const
Returns the size of the rectangle.
void onApplicationWindowChangedActivation(QWidget *widget, bool activated)
The QResizeEvent class contains event parameters for resize events.
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
static void clearColorSpace(QWidget *w)
QList< QToolBar * > qtoolbarsInUnifiedToolbarList
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QShowEvent class provides an event that is sent when a widget is shown.
The QWindowStateChangeEvent class provides the window state before a window state change...
int y() const
Returns the y-coordinate of the rectangle's top edge.
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
#define QT_MANGLE_NAMESPACE(name)
int x() const
Returns the x-coordinate of the rectangle's left edge.
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
The QPoint class defines a point in the plane using integer precision.
The QMainWindow class provides a main application window.
The QRect class defines a rectangle in the plane using integer precision.
OSViewRef qt_mac_nativeview_for(const QWidget *)
int y() const
Returns the y coordinate of this point.
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
The QSize class defines the size of a two-dimensional object using integer point precision.
int x() const
Returns the x coordinate of this point.
The QEvent class is the base class of all event classes.
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
The QList class is a template class that provides lists.
QPoint topLeft() const
Returns the position of the rectangle's top-left corner.