src/gui/kernel/qcocoapanel_mac.mm
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #import <private/qcocoapanel_mac_p.h>
       
    43 #ifdef QT_MAC_USE_COCOA
       
    44 #import <private/qt_cocoa_helpers_mac_p.h>
       
    45 #import <private/qcocoawindow_mac_p.h>
       
    46 #import <private/qcocoawindowdelegate_mac_p.h>
       
    47 #import <private/qcocoaview_mac_p.h>
       
    48 #import <private/qcocoawindowcustomthemeframe_mac_p.h>
       
    49 
       
    50 #include <QtGui/QWidget>
       
    51 
       
    52 QT_FORWARD_DECLARE_CLASS(QWidget);
       
    53 QT_BEGIN_NAMESPACE
       
    54 extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm
       
    55 QT_END_NAMESPACE
       
    56 QT_USE_NAMESPACE
       
    57 
       
    58 
       
    59 @interface NSWindow (QtCoverForHackWithCategory)
       
    60 + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask;
       
    61 @end
       
    62 
       
    63 
       
    64 @implementation QT_MANGLE_NAMESPACE(QCocoaPanel)
       
    65 
       
    66 - (BOOL)canBecomeKeyWindow
       
    67 {
       
    68     QWidget *widget = [self QT_MANGLE_NAMESPACE(qt_qwidget)];
       
    69 
       
    70     bool isToolTip = (widget->windowType() == Qt::ToolTip);
       
    71     bool isPopup = (widget->windowType() == Qt::Popup);
       
    72     return !(isPopup || isToolTip);
       
    73 }
       
    74 
       
    75 /***********************************************************************
       
    76   BEGIN Copy and Paste between QCocoaWindow and QCocoaPanel
       
    77   This is a bit unfortunate, but thanks to the dynamic dispatch we
       
    78   have to duplicate this code or resort to really silly forwarding methods
       
    79 **************************************************************************/
       
    80 
       
    81 /*
       
    82     The methods keyDown, keyUp, and flagsChanged... These really shouldn't ever
       
    83     get hit. We automatically say we can be first responder if we are a window.
       
    84     So, the handling should get handled by the view. This is here more as a
       
    85     last resort (i.e., this is code that can potentially be removed).
       
    86  */
       
    87 
       
    88 - (void)toggleToolbarShown:(id)sender
       
    89 {
       
    90     macSendToolbarChangeEvent([self QT_MANGLE_NAMESPACE(qt_qwidget)]);
       
    91     [super toggleToolbarShown:sender];
       
    92 }
       
    93 
       
    94 - (void)keyDown:(NSEvent *)theEvent
       
    95 {
       
    96     bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]);
       
    97     if (!keyOK)
       
    98         [super keyDown:theEvent];
       
    99 }
       
   100 
       
   101 - (void)keyUp:(NSEvent *)theEvent
       
   102 {
       
   103     bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]);
       
   104     if (!keyOK)
       
   105         [super keyUp:theEvent];
       
   106 }
       
   107 
       
   108 - (void)flagsChanged:(NSEvent *)theEvent
       
   109 {
       
   110     qt_dispatchModifiersChanged(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]);
       
   111     [super flagsChanged:theEvent];
       
   112 }
       
   113 
       
   114 
       
   115 - (void)tabletProximity:(NSEvent *)tabletEvent
       
   116 {
       
   117     qt_dispatchTabletProximityEvent(tabletEvent);
       
   118 }
       
   119 
       
   120 - (void)sendEvent:(NSEvent *)event
       
   121 {
       
   122     QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self];
       
   123 
       
   124     // Cocoa can hold onto the window after we've disavowed its knowledge. So,
       
   125     // if we get sent an event afterwards just have it go through the super's
       
   126     // version and don't do any stuff with Qt.
       
   127     if (!widget) {
       
   128         [super sendEvent:event];
       
   129         return;
       
   130     }
       
   131     [self retain];
       
   132     QT_MANGLE_NAMESPACE(QCocoaView) *view = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(qt_mac_nativeview_for(widget));
       
   133     Qt::MouseButton mouseButton = cocoaButton2QtButton([event buttonNumber]);
       
   134 
       
   135     // sometimes need to redirect mouse events to the popup.
       
   136     QWidget *popup = qAppInstance()->activePopupWidget();
       
   137     if (popup && popup != widget) {
       
   138         switch([event type])
       
   139         {
       
   140         case NSLeftMouseDown:
       
   141             qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton);
       
   142             // Don't call super here. This prevents us from getting the mouseUp event,
       
   143             // which we need to send even if the mouseDown event was not accepted.
       
   144             // (this is standard Qt behavior.)
       
   145             break;
       
   146         case NSRightMouseDown:
       
   147         case NSOtherMouseDown:
       
   148             if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton))
       
   149                 [super sendEvent:event];
       
   150             break;
       
   151         case NSLeftMouseUp:
       
   152         case NSRightMouseUp:
       
   153         case NSOtherMouseUp:
       
   154             if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonRelease, mouseButton))
       
   155                 [super sendEvent:event];
       
   156             break;
       
   157         case NSMouseMoved:
       
   158             qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, Qt::NoButton);
       
   159             break;
       
   160         case NSLeftMouseDragged:
       
   161         case NSRightMouseDragged:
       
   162         case NSOtherMouseDragged:
       
   163             [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->view = view;
       
   164             [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->theEvent = event;
       
   165             if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, mouseButton))
       
   166                 [super sendEvent:event];
       
   167             break;
       
   168         default:
       
   169             [super sendEvent:event];
       
   170             break;
       
   171         }
       
   172     } else {
       
   173         [super sendEvent:event];
       
   174     }
       
   175     qt_mac_dispatchNCMouseMessage(self, event, [self QT_MANGLE_NAMESPACE(qt_qwidget)], leftButtonIsRightButton);
       
   176 
       
   177 
       
   178     [self release];
       
   179 }
       
   180 
       
   181 - (BOOL)makeFirstResponder:(NSResponder *)responder
       
   182 {
       
   183     // For some reason Cocoa wants to flip the first responder
       
   184     // when Qt doesn't want to, sorry, but "No" :-)
       
   185     if (responder == nil && qApp->focusWidget())
       
   186         return NO;
       
   187     return [super makeFirstResponder:responder];
       
   188 }
       
   189 
       
   190 /***********************************************************************
       
   191   END Copy and Paste between QCocoaWindow and QCocoaPanel
       
   192 ***********************************************************************/
       
   193 + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask
       
   194 {
       
   195     if (styleMask & QtMacCustomizeWindow)
       
   196         return [QT_MANGLE_NAMESPACE(QCocoaWindowCustomThemeFrame) class];
       
   197     return [super frameViewClassForStyleMask:styleMask];
       
   198 }
       
   199 
       
   200 @end
       
   201 #endif