| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 41 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 42 | **
|
|---|
| 43 | ****************************************************************************/
|
|---|
| 44 |
|
|---|
| 45 | #import <Cocoa/Cocoa.h>
|
|---|
| 46 | #import <private/qcocoaview_mac_p.h>
|
|---|
| 47 | #include "qmacnativewidget_mac.h"
|
|---|
| 48 | #include <private/qwidget_p.h>
|
|---|
| 49 |
|
|---|
| 50 | /*!
|
|---|
| 51 | \class QMacNativeWidget
|
|---|
| 52 | \since 4.5
|
|---|
| 53 | \brief The QMacNativeWidget class provides a widget for Mac OS X that provides a way to put Qt widgets into Carbon
|
|---|
| 54 | or Cocoa hierarchies depending on how Qt was configured.
|
|---|
| 55 |
|
|---|
| 56 | \ingroup advanced
|
|---|
| 57 |
|
|---|
| 58 | On Mac OS X, there is a difference between a window and view;
|
|---|
| 59 | normally expressed as widgets in Qt. Qt makes assumptions about its
|
|---|
| 60 | parent-child hierarchy that make it complex to put an arbitrary Qt widget
|
|---|
| 61 | into a hierarchy of "normal" views from Apple frameworks. QMacNativeWidget
|
|---|
| 62 | bridges the gap between views and windows and makes it possible to put a
|
|---|
| 63 | hierarchy of Qt widgets into a non-Qt window or view.
|
|---|
| 64 |
|
|---|
| 65 | QMacNativeWidget pretends it is a window (i.e. isWindow() will return true),
|
|---|
| 66 | but it cannot be shown on its own. It needs to be put into a window
|
|---|
| 67 | when it is created or later through a native call.
|
|---|
| 68 |
|
|---|
| 69 | QMacNativeWidget works for either Carbon or Cocoa depending on how Qt was configured. If Qt is
|
|---|
| 70 | using Carbon, QMacNativeWidget will embed into Carbon hierarchies. If Qt is
|
|---|
| 71 | using Cocoa, QMacNativeWidget embeds into Cocoa hierarchies.
|
|---|
| 72 |
|
|---|
| 73 | Here is an example of putting a QPushButton into a NSWindow:
|
|---|
| 74 |
|
|---|
| 75 | \snippet doc/src/snippets/qmacnativewidget/main.mm 0
|
|---|
| 76 |
|
|---|
| 77 | On Carbon, this would do the equivalent:
|
|---|
| 78 |
|
|---|
| 79 | \snippet doc/src/snippets/qmacnativewidget/main.mm 1
|
|---|
| 80 |
|
|---|
| 81 | Note that QMacNativeWidget requires knowledge of Carbon or Cocoa. All it
|
|---|
| 82 | does is get the Qt hierarchy into a window not owned by Qt. It is then up
|
|---|
| 83 | to the programmer to ensure it is placed correctly in the window and
|
|---|
| 84 | responds correctly to events.
|
|---|
| 85 | */
|
|---|
| 86 |
|
|---|
| 87 | QT_BEGIN_NAMESPACE
|
|---|
| 88 |
|
|---|
| 89 | class QMacNativeWidgetPrivate : public QWidgetPrivate
|
|---|
| 90 | {
|
|---|
| 91 | };
|
|---|
| 92 |
|
|---|
| 93 | extern OSViewRef qt_mac_create_widget(QWidget *widget, QWidgetPrivate *widgetPrivate, OSViewRef parent);
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 | /*!
|
|---|
| 97 | Create a QMacNativeWidget with \a parentView as its "superview" (i.e.,
|
|---|
| 98 | parent). The \a parentView is either an HIViewRef if Qt is using Carbon or
|
|---|
| 99 | a NSView pointer if Qt is using Cocoa.
|
|---|
| 100 | */
|
|---|
| 101 | QMacNativeWidget::QMacNativeWidget(void *parentView)
|
|---|
| 102 | : QWidget(*new QMacNativeWidgetPrivate, 0, Qt::Window)
|
|---|
| 103 | {
|
|---|
| 104 | Q_D(QMacNativeWidget);
|
|---|
| 105 | OSViewRef myView = qt_mac_create_widget(this, d, OSViewRef(parentView));
|
|---|
| 106 |
|
|---|
| 107 | d->topData()->embedded = true;
|
|---|
| 108 | create(WId(myView), false, false);
|
|---|
| 109 | setPalette(QPalette(Qt::transparent));
|
|---|
| 110 | setAttribute(Qt::WA_SetPalette, false);
|
|---|
| 111 | setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | /*!
|
|---|
| 115 | Destroy the QMacNativeWidget.
|
|---|
| 116 | */
|
|---|
| 117 | QMacNativeWidget::~QMacNativeWidget()
|
|---|
| 118 | {
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | /*!
|
|---|
| 122 | \reimp
|
|---|
| 123 | */
|
|---|
| 124 | QSize QMacNativeWidget::sizeHint() const
|
|---|
| 125 | {
|
|---|
| 126 | return QSize(200, 200);
|
|---|
| 127 | }
|
|---|
| 128 | /*!
|
|---|
| 129 | \reimp
|
|---|
| 130 | */
|
|---|
| 131 | bool QMacNativeWidget::event(QEvent *ev)
|
|---|
| 132 | {
|
|---|
| 133 | return QWidget::event(ev);
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | QT_END_NAMESPACE
|
|---|