| 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 QtGui module 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 |
|
|---|
| 42 | #include "qfontdialog_p.h"
|
|---|
| 43 | #if !defined(QT_NO_FONTDIALOG) && defined(Q_WS_MAC)
|
|---|
| 44 | #include <qapplication.h>
|
|---|
| 45 | #include <qdialogbuttonbox.h>
|
|---|
| 46 | #include <qlineedit.h>
|
|---|
| 47 | #include <private/qapplication_p.h>
|
|---|
| 48 | #include <private/qfont_p.h>
|
|---|
| 49 | #include <private/qfontengine_p.h>
|
|---|
| 50 | #include <private/qt_cocoa_helpers_mac_p.h>
|
|---|
| 51 | #include <private/qt_mac_p.h>
|
|---|
| 52 | #include <qabstracteventdispatcher.h>
|
|---|
| 53 | #include <qdebug.h>
|
|---|
| 54 | #import <AppKit/AppKit.h>
|
|---|
| 55 | #import <Foundation/Foundation.h>
|
|---|
| 56 |
|
|---|
| 57 | #if !CGFLOAT_DEFINED
|
|---|
| 58 | typedef float CGFloat; // Should only not be defined on 32-bit platforms
|
|---|
| 59 | #endif
|
|---|
| 60 |
|
|---|
| 61 | QT_BEGIN_NAMESPACE
|
|---|
| 62 |
|
|---|
| 63 | extern void macStartInterceptNSPanelCtor();
|
|---|
| 64 | extern void macStopInterceptNSPanelCtor();
|
|---|
| 65 | extern NSButton *macCreateButton(const char *text, NSView *superview);
|
|---|
| 66 | extern bool qt_mac_is_macsheet(const QWidget *w); // qwidget_mac.mm
|
|---|
| 67 |
|
|---|
| 68 | QT_END_NAMESPACE
|
|---|
| 69 | QT_USE_NAMESPACE
|
|---|
| 70 |
|
|---|
| 71 | // should a priori be kept in sync with qcolordialog_mac.mm
|
|---|
| 72 | const CGFloat ButtonMinWidth = 78.0;
|
|---|
| 73 | const CGFloat ButtonMinHeight = 32.0;
|
|---|
| 74 | const CGFloat ButtonSpacing = 0.0;
|
|---|
| 75 | const CGFloat ButtonTopMargin = 0.0;
|
|---|
| 76 | const CGFloat ButtonBottomMargin = 7.0;
|
|---|
| 77 | const CGFloat ButtonSideMargin = 9.0;
|
|---|
| 78 |
|
|---|
| 79 | // looks better with some margins
|
|---|
| 80 | const CGFloat DialogTopMargin = 7.0;
|
|---|
| 81 | const CGFloat DialogSideMargin = 9.0;
|
|---|
| 82 |
|
|---|
| 83 | const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask;
|
|---|
| 84 |
|
|---|
| 85 | @class QT_MANGLE_NAMESPACE(QCocoaFontPanelDelegate);
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5
|
|---|
| 89 |
|
|---|
| 90 | @protocol NSWindowDelegate <NSObject>
|
|---|
| 91 | - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
|
|---|
| 92 | @end
|
|---|
| 93 |
|
|---|
| 94 | #endif
|
|---|
| 95 |
|
|---|
| 96 | @interface QT_MANGLE_NAMESPACE(QCocoaFontPanelDelegate) : NSObject <NSWindowDelegate> {
|
|---|
| 97 | NSFontPanel *mFontPanel;
|
|---|
| 98 | NSView *mStolenContentView;
|
|---|
| 99 | NSButton *mOkButton;
|
|---|
| 100 | NSButton *mCancelButton;
|
|---|
| 101 | QFontDialogPrivate *mPriv;
|
|---|
| 102 | QFont *mQtFont;
|
|---|
| 103 | BOOL mPanelHackedWithButtons;
|
|---|
| 104 | CGFloat mDialogExtraWidth;
|
|---|
| 105 | CGFloat mDialogExtraHeight;
|
|---|
| 106 | int mReturnCode;
|
|---|
| 107 | BOOL mAppModal;
|
|---|
| 108 | }
|
|---|
| 109 | - (id)initWithFontPanel:(NSFontPanel *)panel
|
|---|
| 110 | stolenContentView:(NSView *)stolenContentView
|
|---|
| 111 | okButton:(NSButton *)okButton
|
|---|
| 112 | cancelButton:(NSButton *)cancelButton
|
|---|
| 113 | priv:(QFontDialogPrivate *)priv
|
|---|
| 114 | extraWidth:(CGFloat)extraWidth
|
|---|
| 115 | extraHeight:(CGFloat)extraHeight;
|
|---|
| 116 | - (void)showModelessPanel;
|
|---|
| 117 | - (void)showWindowModalSheet:(QWidget *)docWidget;
|
|---|
| 118 | - (void)runApplicationModalPanel;
|
|---|
| 119 | - (BOOL)isAppModal;
|
|---|
| 120 | - (void)changeFont:(id)sender;
|
|---|
| 121 | - (void)changeAttributes:(id)sender;
|
|---|
| 122 | - (BOOL)windowShouldClose:(id)window;
|
|---|
| 123 | - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
|
|---|
| 124 | - (void)relayout;
|
|---|
| 125 | - (void)relayoutToContentSize:(NSSize)frameSize;
|
|---|
| 126 | - (void)onOkClicked;
|
|---|
| 127 | - (void)onCancelClicked;
|
|---|
| 128 | - (NSFontPanel *)fontPanel;
|
|---|
| 129 | - (NSWindow *)actualPanel;
|
|---|
| 130 | - (NSSize)dialogExtraSize;
|
|---|
| 131 | - (void)setQtFont:(const QFont &)newFont;
|
|---|
| 132 | - (QFont)qtFont;
|
|---|
| 133 | - (void)finishOffWithCode:(NSInteger)result;
|
|---|
| 134 | - (void)cleanUpAfterMyself;
|
|---|
| 135 | - (void)setSubwindowStacking;
|
|---|
| 136 | @end
|
|---|
| 137 |
|
|---|
| 138 | static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont)
|
|---|
| 139 | {
|
|---|
| 140 | QFont newFont;
|
|---|
| 141 | if (cocoaFont) {
|
|---|
| 142 | int pSize = qRound([cocoaFont pointSize]);
|
|---|
| 143 | QString family(qt_mac_NSStringToQString([cocoaFont familyName]));
|
|---|
| 144 | QString typeface(qt_mac_NSStringToQString([cocoaFont fontName]));
|
|---|
| 145 |
|
|---|
| 146 | int hyphenPos = typeface.indexOf(QLatin1Char('-'));
|
|---|
| 147 | if (hyphenPos != -1) {
|
|---|
| 148 | typeface.remove(0, hyphenPos + 1);
|
|---|
| 149 | } else {
|
|---|
| 150 | typeface = QLatin1String("Normal");
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | newFont = QFontDatabase().font(family, typeface, pSize);
|
|---|
| 154 | newFont.setUnderline(resolveFont.underline());
|
|---|
|
|---|