| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the demonstration applications of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 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 | ** 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 have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 | #include "macmainwindow.h"
|
|---|
| 42 | #import <Cocoa/Cocoa.h>
|
|---|
| 43 | #include <QtGui>
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | #ifdef Q_WS_MAC
|
|---|
| 47 |
|
|---|
| 48 | #include <Carbon/Carbon.h>
|
|---|
| 49 |
|
|---|
| 50 | #ifdef QT_MAC_USE_COCOA
|
|---|
| 51 |
|
|---|
| 52 | //![0]
|
|---|
| 53 | SearchWidget::SearchWidget(QWidget *parent)
|
|---|
| 54 | : QMacCocoaViewContainer(0, parent)
|
|---|
| 55 | {
|
|---|
| 56 | // Many Cocoa objects create temporary autorelease objects,
|
|---|
| 57 | // so create a pool to catch them.
|
|---|
| 58 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|---|
| 59 |
|
|---|
| 60 | // Create the NSSearchField, set it on the QCocoaViewContainer.
|
|---|
| 61 | NSSearchField *search = [[NSSearchField alloc] init];
|
|---|
| 62 | setCocoaView(search);
|
|---|
| 63 |
|
|---|
| 64 | // Use a Qt menu for the search field menu.
|
|---|
| 65 | QMenu *qtMenu = createMenu(this);
|
|---|
| 66 | NSMenu *nsMenu = qtMenu->macMenu(0);
|
|---|
| 67 | [[search cell] setSearchMenuTemplate:nsMenu];
|
|---|
| 68 |
|
|---|
| 69 | // Release our reference, since our super class takes ownership and we
|
|---|
| 70 | // don't need it anymore.
|
|---|
| 71 | [search release];
|
|---|
| 72 |
|
|---|
| 73 | // Clean up our pool as we no longer need it.
|
|---|
| 74 | [pool release];
|
|---|
| 75 | }
|
|---|
| 76 | //![0]
|
|---|
| 77 |
|
|---|
| 78 | SearchWidget::~SearchWidget()
|
|---|
| 79 | {
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | QSize SearchWidget::sizeHint() const
|
|---|
| 83 | {
|
|---|
| 84 | return QSize(150, 40);
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | #else
|
|---|
| 88 |
|
|---|
| 89 | // The SearchWidget class wraps a native HISearchField.
|
|---|
| 90 | SearchWidget::SearchWidget(QWidget *parent)
|
|---|
| 91 | :QWidget(parent)
|
|---|
| 92 | {
|
|---|
| 93 |
|
|---|
| 94 | // Create a native search field and pass its window id to QWidget::create.
|
|---|
| 95 | searchFieldText = CFStringCreateWithCString(0, "search", 0);
|
|---|
| 96 | HISearchFieldCreate(NULL/*bounds*/, kHISearchFieldAttributesSearchIcon | kHISearchFieldAttributesCancel,
|
|---|
| 97 | NULL/*menu ref*/, searchFieldText, &searchField);
|
|---|
| 98 | create(reinterpret_cast<WId>(searchField));
|
|---|
| 99 |
|
|---|
| 100 | // Use a Qt menu for the search field menu.
|
|---|
| 101 | QMenu *searchMenu = createMenu(this);
|
|---|
| 102 | MenuRef menuRef = searchMenu->macMenu(0);
|
|---|
| 103 | HISearchFieldSetSearchMenu(searchField, menuRef);
|
|---|
| 104 | setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | SearchWidget::~SearchWidget()
|
|---|
| 108 | {
|
|---|
| 109 | CFRelease(searchField);
|
|---|
| 110 | CFRelease(searchFieldText);
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | // Get the size hint from the search field.
|
|---|
| 114 | QSize SearchWidget::sizeHint() const
|
|---|
| 115 | {
|
|---|
| 116 | EventRef event;
|
|---|
| 117 | HIRect optimalBounds;
|
|---|
|
|---|