638 |
643 |
639 [mgr setSelectedFont:nsFont isMultiple:NO]; |
644 [mgr setSelectedFont:nsFont isMultiple:NO]; |
640 [static_cast<QCocoaFontPanelDelegate *>(delegate) setQtFont:font]; |
645 [static_cast<QCocoaFontPanelDelegate *>(delegate) setQtFont:font]; |
641 } |
646 } |
642 |
647 |
|
648 void *QFontDialogPrivate::_q_constructNativePanel() |
|
649 { |
|
650 QMacCocoaAutoReleasePool pool; |
|
651 |
|
652 bool sharedFontPanelExisted = [NSFontPanel sharedFontPanelExists]; |
|
653 NSFontPanel *sharedFontPanel = [NSFontPanel sharedFontPanel]; |
|
654 [sharedFontPanel setHidesOnDeactivate:false]; |
|
655 |
|
656 // hack to ensure that QCocoaApplication's validModesForFontPanel: |
|
657 // implementation is honored |
|
658 if (!sharedFontPanelExisted) { |
|
659 [sharedFontPanel makeKeyAndOrderFront:sharedFontPanel]; |
|
660 [sharedFontPanel close]; |
|
661 } |
|
662 |
|
663 NSPanel *ourPanel = 0; |
|
664 NSView *stolenContentView = 0; |
|
665 NSButton *okButton = 0; |
|
666 NSButton *cancelButton = 0; |
|
667 |
|
668 CGFloat dialogExtraWidth = 0.0; |
|
669 CGFloat dialogExtraHeight = 0.0; |
|
670 |
|
671 // compute dialogExtra{Width,Height} |
|
672 dialogExtraWidth = 2.0 * DialogSideMargin; |
|
673 dialogExtraHeight = DialogTopMargin + ButtonTopMargin + ButtonMinHeight |
|
674 + ButtonBottomMargin; |
|
675 |
|
676 // compute initial contents rectangle |
|
677 NSRect contentRect = [sharedFontPanel contentRectForFrameRect:[sharedFontPanel frame]]; |
|
678 contentRect.size.width += dialogExtraWidth; |
|
679 contentRect.size.height += dialogExtraHeight; |
|
680 |
|
681 // create the new panel |
|
682 ourPanel = [[NSPanel alloc] initWithContentRect:contentRect |
|
683 styleMask:StyleMask |
|
684 backing:NSBackingStoreBuffered |
|
685 defer:YES]; |
|
686 [ourPanel setReleasedWhenClosed:YES]; |
|
687 |
|
688 stolenContentView = [sharedFontPanel contentView]; |
|
689 |
|
690 // steal the font panel's contents view |
|
691 [stolenContentView retain]; |
|
692 [sharedFontPanel setContentView:0]; |
|
693 |
|
694 { |
|
695 // create a new content view and add the stolen one as a subview |
|
696 NSRect frameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } }; |
|
697 NSView *ourContentView = [[NSView alloc] initWithFrame:frameRect]; |
|
698 [ourContentView addSubview:stolenContentView]; |
|
699 |
|
700 // create OK and Cancel buttons and add these as subviews |
|
701 okButton = macCreateButton("&OK", ourContentView); |
|
702 cancelButton = macCreateButton("Cancel", ourContentView); |
|
703 |
|
704 [ourPanel setContentView:ourContentView]; |
|
705 [ourPanel setDefaultButtonCell:[okButton cell]]; |
|
706 } |
|
707 // create a delegate and set it |
|
708 QCocoaFontPanelDelegate *delegate = |
|
709 [[QCocoaFontPanelDelegate alloc] initWithFontPanel:sharedFontPanel |
|
710 stolenContentView:stolenContentView |
|
711 okButton:okButton |
|
712 cancelButton:cancelButton |
|
713 priv:this |
|
714 extraWidth:dialogExtraWidth |
|
715 extraHeight:dialogExtraHeight]; |
|
716 [ourPanel setDelegate:delegate]; |
|
717 [[NSFontManager sharedFontManager] setDelegate:delegate]; |
|
718 #ifdef QT_MAC_USE_COCOA |
|
719 [[NSFontManager sharedFontManager] setTarget:delegate]; |
|
720 #endif |
|
721 setFont(delegate, QApplication::font()); |
|
722 |
|
723 { |
|
724 // hack to get correct initial layout |
|
725 NSRect frameRect = [ourPanel frame]; |
|
726 frameRect.size.width += 1.0; |
|
727 [ourPanel setFrame:frameRect display:NO]; |
|
728 frameRect.size.width -= 1.0; |
|
729 frameRect.size = [delegate windowWillResize:ourPanel toSize:frameRect.size]; |
|
730 [ourPanel setFrame:frameRect display:NO]; |
|
731 [ourPanel center]; |
|
732 } |
|
733 NSString *title = @"Select font"; |
|
734 [ourPanel setTitle:title]; |
|
735 |
|
736 [delegate setModalSession:[NSApp beginModalSessionForWindow:ourPanel]]; |
|
737 return delegate; |
|
738 } |
|
739 |
|
740 void QFontDialogPrivate::mac_nativeDialogModalHelp() |
|
741 { |
|
742 // Copied from QFileDialogPrivate |
|
743 // Do a queued meta-call to open the native modal dialog so it opens after the new |
|
744 // event loop has started to execute (in QDialog::exec). Using a timer rather than |
|
745 // a queued meta call is intentional to ensure that the call is only delivered when |
|
746 // [NSApp run] runs (timers are handeled special in cocoa). If NSApp is not |
|
747 // running (which is the case if e.g a top-most QEventLoop has been |
|
748 // interrupted, and the second-most event loop has not yet been reactivated (regardless |
|
749 // if [NSApp run] is still on the stack)), showing a native modal dialog will fail. |
|
750 if (nativeDialogInUse) { |
|
751 Q_Q(QFontDialog); |
|
752 QTimer::singleShot(1, q, SLOT(_q_macRunNativeAppModalPanel())); |
|
753 } |
|
754 } |
|
755 |
|
756 // The problem with the native font dialog is that OS X does not |
|
757 // offer a proper dialog, but a panel (i.e. without Ok and Cancel buttons). |
|
758 // This means we need to "construct" a native dialog by taking the panel |
|
759 // and "adding" the buttons. |
|
760 void QFontDialogPrivate::_q_macRunNativeAppModalPanel() |
|
761 { |
|
762 QBoolBlocker nativeDialogOnTop(QApplicationPrivate::native_modal_dialog_active); |
|
763 Q_Q(QFontDialog); |
|
764 QCocoaFontPanelDelegate *delegate = (QCocoaFontPanelDelegate *)_q_constructNativePanel(); |
|
765 NSWindow *ourPanel = [delegate actualPanel]; |
|
766 [ourPanel retain]; |
|
767 int rval = [NSApp runModalForWindow:ourPanel]; |
|
768 QAbstractEventDispatcher::instance()->interrupt(); |
|
769 [ourPanel release]; |
|
770 [delegate cleanUpAfterMyself]; |
|
771 [delegate release]; |
|
772 bool isOk = (rval == NSOKButton); |
|
773 if(isOk) |
|
774 rescode = QDialog::Accepted; |
|
775 else |
|
776 rescode = QDialog::Rejected; |
|
777 } |
|
778 |
|
779 bool QFontDialogPrivate::setVisible_sys(bool visible) |
|
780 { |
|
781 Q_Q(QFontDialog); |
|
782 if (!visible == q->isHidden()) |
|
783 return false; |
|
784 return visible; |
|
785 } |
|
786 |
643 QT_END_NAMESPACE |
787 QT_END_NAMESPACE |
644 |
788 |
645 #endif |
789 #endif |