X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/489468feaa08b8f504735eecca522fb8d0f825d2..47e175a24f862aa8b7ca7dd4a2bb5957991e7f2d:/src/osx/carbon/fontdlg.cpp?ds=inline diff --git a/src/osx/carbon/fontdlg.cpp b/src/osx/carbon/fontdlg.cpp index e7892ad542..d9f1f99ede 100644 --- a/src/osx/carbon/fontdlg.cpp +++ b/src/osx/carbon/fontdlg.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/fontdlg.cpp +// Name: src/osx/carbon/fontdlg.cpp // Purpose: wxFontDialog class for carbon 10.2+. // Author: Ryan Norton // Modified by: @@ -41,17 +41,21 @@ #endif #include "wx/fontdlg.h" +#include "wx/fontutil.h" +#include "wx/testing.h" -#if wxMAC_USE_EXPERIMENTAL_FONTDIALOG +#if wxOSX_USE_EXPERIMENTAL_FONTDIALOG IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) -#include "wx/mac/uma.h" +#include "wx/osx/private.h" // --------------------------------------------------------------------------- // wxFontDialog // --------------------------------------------------------------------------- +#if wxOSX_USE_CARBON + static const EventTypeSpec eventList[] = { { kEventClassFont, kEventFontSelection } , @@ -73,20 +77,22 @@ wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler), case kEventFontSelection : { bool setup = false ; -#if wxMAC_USE_CORE_TEXT - if ( UMAGetSystemVersion() >= 0x1050 ) +#if wxOSX_USE_CORE_TEXT + if ( !setup ) { CTFontDescriptorRef descr; if ( cEvent.GetParameter( kEventParamCTFontDescriptor, typeCTFontDescriptorRef, &descr ) == noErr ) { wxFont font; - font.MacCreateFromCTFontDescriptor(descr); + wxNativeFontInfo fontinfo; + fontinfo.Init(descr); + font.Create(fontinfo); fontdata.SetChosenFont( font ) ; setup = true; } } #endif -#if wxMAC_USE_ATSU_TEXT +#if wxOSX_USE_ATSU_TEXT ATSUFontID fontId = 0 ; if ( !setup && (cEvent.GetParameter(kEventParamATSUFontID, &fontId) == noErr) ) { @@ -98,7 +104,7 @@ wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler), FMFontFamily fontFamily = cEvent.GetParameter(kEventParamFMFontFamily); ATSFontFamilyRef atsfontfamilyref = FMGetATSFontFamilyRefFromFontFamily( fontFamily ) ; OSStatus err = ATSFontFamilyGetName( atsfontfamilyref , kATSOptionFlagsDefault , &cfName ) ; - if ( err == noErr ) + if ( err != noErr ) { wxFAIL_MSG("ATSFontFamilyGetName failed"); } @@ -142,7 +148,7 @@ wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler), fontdata.m_chosenFont.SetWeight(fontStyle & bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL); } } -#endif // wxMAC_USE_ATSU_TEXT +#endif // wxOSX_USE_ATSU_TEXT // retrieving the color RGBColor fontColor ; @@ -191,11 +197,17 @@ wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler), } DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler ) +#endif wxFontDialog::wxFontDialog() { } +wxFontDialog::wxFontDialog(wxWindow *parent) +{ + Create(parent); +} + wxFontDialog::wxFontDialog(wxWindow *parent, const wxFontData& data) { Create(parent, data); @@ -205,31 +217,41 @@ wxFontDialog::~wxFontDialog() { } -bool wxFontDialog::Create(wxWindow *WXUNUSED(parent), const wxFontData& data) +bool wxFontDialog::Create(wxWindow *WXUNUSED(parent)) { - m_fontData = data; return true ; } +bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data) +{ + m_fontData = data; + return Create(parent) ; +} + int wxFontDialog::ShowModal() { + WX_TESTING_SHOW_MODAL_HOOK(); + +#if wxOSX_USE_CARBON + OSStatus err ; wxFont font = *wxNORMAL_FONT ; - if ( m_fontData.m_initialFont.Ok() ) + if ( m_fontData.m_initialFont.IsOk() ) { font = m_fontData.m_initialFont ; } bool setup = false; -#if wxMAC_USE_CORE_TEXT - if ( UMAGetSystemVersion() >= 0x1050 ) +#if wxOSX_USE_CORE_TEXT + if ( !setup ) { - CTFontDescriptorRef descr = (CTFontDescriptorRef)font.MacGetCTFontDescriptor(); + CTFontDescriptorRef descr = (CTFontDescriptorRef) CTFontCopyFontDescriptor( (CTFontRef) font.OSXGetCTFont() ); err = SetFontInfoForSelection (kFontSelectionCoreTextType,1, &descr , NULL); + CFRelease( descr ); setup = true; } #endif -#if wxMAC_USE_ATSU_TEXT +#if wxOSX_USE_ATSU_TEXT if ( !setup ) { ATSUStyle style = (ATSUStyle)font.MacGetATSUStyle(); @@ -247,10 +269,13 @@ int wxFontDialog::ShowModal() if ( !FPIsFontPanelVisible() ) FPShowHideFontPanel(); - +#endif + wxDialog::OSXBeginModalDialog(); int retval = RunMixedFontDialog(this); - + wxDialog::OSXEndModalDialog(); +#if wxOSX_USE_CARBON ::RemoveEventHandler(handler); +#endif return retval ; } @@ -261,7 +286,7 @@ int wxFontDialog::ShowModal() #undef wxFontDialog -#include "wx/mac/fontdlg.h" +#include "wx/osx/fontdlg.h" #include "wx/fontenum.h" #include "wx/colordlg.h" @@ -304,7 +329,7 @@ void wxFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) wxSize size = GetSize(); wxFont font = GetFont(); - if ( font.Ok() ) + if ( font.IsOk() ) { dc.SetFont(font); // Calculate vertical centre @@ -492,7 +517,7 @@ void wxFontDialog::CreateControls() itemFlexGridSizer4->Add(itemStaticText5, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5); wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxVERTICAL); - itemFlexGridSizer4->Add(itemBoxSizer6, 0, wxGROW|wxGROW, 5); + itemFlexGridSizer4->Add(itemBoxSizer6, 0, wxGROW, 5); wxString* m_facenameCtrlStrings = NULL; m_facenameCtrl = new wxListBox( itemDialog1, wxID_FONTDIALOG_FACENAME, wxDefaultPosition, wxSize(320, 100), 0, m_facenameCtrlStrings, wxLB_SINGLE ); @@ -501,7 +526,7 @@ void wxFontDialog::CreateControls() wxStaticText* itemStaticText8 = new wxStaticText( itemDialog1, wxID_STATIC, _("Size:"), wxDefaultPosition, wxDefaultSize, 0 ); itemFlexGridSizer4->Add(itemStaticText8, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5); - m_sizeCtrl = new wxSpinCtrl( itemDialog1, wxID_FONTDIALOG_FONTSIZE, _T("12"), wxDefaultPosition, wxSize(60, -1), wxSP_ARROW_KEYS, 1, 300, 12 ); + m_sizeCtrl = new wxSpinCtrl( itemDialog1, wxID_FONTDIALOG_FONTSIZE, wxT("12"), wxDefaultPosition, wxSize(60, -1), wxSP_ARROW_KEYS, 1, 300, 12 ); m_sizeCtrl->SetHelpText(_("The font size in points.")); if (ShowToolTips()) m_sizeCtrl->SetToolTip(_("The font size in points.")); @@ -577,7 +602,7 @@ void wxFontDialog::CreateControls() wxFontEnumerator enumerator; enumerator.EnumerateFacenames(); wxArrayString facenames = enumerator.GetFacenames(); - if (facenames) + if (!facenames.empty()) { facenames.Add(_("")); facenames.Add(_("")); @@ -592,7 +617,7 @@ void wxFontDialog::CreateControls() InitializeControls(); m_previewCtrl->SetFont(m_dialogFont); - if (m_fontData.GetColour().Ok()) + if (m_fontData.GetColour().IsOk()) { m_previewCtrl->SetForegroundColour(m_fontData.GetColour()); } @@ -688,7 +713,7 @@ void wxFontDialog::InitializeFont() bool fontUnderline = false; wxString fontName; - if (m_fontData.m_initialFont.Ok()) + if (m_fontData.m_initialFont.IsOk()) { fontFamily = m_fontData.m_initialFont.GetFamily(); fontWeight = m_fontData.m_initialFont.GetWeight(); @@ -726,7 +751,7 @@ void wxFontDialog::InitializeControls() } m_facenameCtrl->SetStringSelection(facename); - if (m_colourCtrl && m_fontData.GetColour().Ok()) + if (m_colourCtrl && m_fontData.GetColour().IsOk()) { m_colourCtrl->SetColour(m_fontData.GetColour()); m_colourCtrl->Refresh(); @@ -823,6 +848,6 @@ int FontFamilyStringToInt(const wxChar *family) #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX -#endif // wxMAC_USE_EXPERIMENTAL_FONTDIALOG +#endif // wxOSX_USE_EXPERIMENTAL_FONTDIALOG #endif // wxUSE_FONTDLG