X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ffa561cf92d311e435dc48c92ec6b33a90962960..9a35701127e3e8d2c7fb433d85c7b3954ccbfc9f:/src/mac/carbon/fontdlg.cpp diff --git a/src/mac/carbon/fontdlg.cpp b/src/mac/carbon/fontdlg.cpp index a97a58f1d8..892d0df454 100644 --- a/src/mac/carbon/fontdlg.cpp +++ b/src/mac/carbon/fontdlg.cpp @@ -9,25 +9,55 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// =========================================================================== +// declarations +// =========================================================================== + +// --------------------------------------------------------------------------- +// headers +// --------------------------------------------------------------------------- + #ifdef __GNUG__ #pragma implementation "fontdlg.h" #endif -#include "wx/mac/fontdlg.h" -#include "wx/cmndata.h" +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif +#ifndef WX_PRECOMP + #include "wx/cmndata.h" +#endif + +#include "wx/mac/fontdlg.h" + #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) #endif #include "wx/mac/private.h" +//Mac OSX 10.2+ only #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 ) #include #include "wx/msgdlg.h" +//color isn't working in carbon impl +#define ISCOLORWORKING 0 + +// ============================================================================ +// implementation +// ============================================================================ + +// --------------------------------------------------------------------------- +// Carbon event callback(s) +// --------------------------------------------------------------------------- + pascal OSStatus wxFontDialogEventHandler( EventHandlerCallRef inHandlerCallRef, EventRef event, void* pData) { @@ -36,11 +66,12 @@ pascal OSStatus wxFontDialogEventHandler( EventHandlerCallRef inHandlerCallRef, OSStatus status = noErr; - ATSUFontID fontid; - Fixed fontsize; - RGBColor fontcolor; - FMFontStyle fontstyle; FMFontFamily fontfamily; + FMFontStyle fontstyle; + FMFontSize fontsize; +#if ISCOLORWORKING + RGBColor fontcolor; +#endif status = GetEventParameter (event, kEventParamFMFontFamily, typeFMFontFamily, NULL, @@ -54,84 +85,35 @@ pascal OSStatus wxFontDialogEventHandler( EventHandlerCallRef inHandlerCallRef, NULL, &(fontstyle)); check_noerr (status); - status = GetEventParameter (event, kEventParamATSUFontID, - typeATSUFontID, NULL, - sizeof (ATSUFontID), - NULL, &(fontid)); - check_noerr (status); - - status = GetEventParameter (event, kEventParamATSUFontSize, - typeATSUSize, NULL, - sizeof (Fixed), + status = GetEventParameter (event, kEventParamFMFontSize, + typeFMFontSize, NULL, + sizeof (FMFontSize), NULL, &(fontsize)); check_noerr (status); +#if ISCOLORWORKING status = GetEventParameter (event, kEventParamFontColor, typeRGBColor, NULL, sizeof( RGBColor ), NULL, &fontcolor); check_noerr (status); +#endif - //TODO: - //TODO: Make a utility function for converting ATSU to WX font (what we're doing :)) - //TODO: - //now do the conversion to the wx font data wxFontData theFontData; wxFont theFont; - - //first, the easy part - set the color + +#if ISCOLORWORKING + //set color wxColour theColor; theColor.Set(&(WXCOLORREF&)fontcolor); theFontData.SetColour(theColor); +#endif + + //set size + theFont.SetPointSize(fontsize); - // - //now the hard part - convert the atsu font to a wx font - // - - //point size - fixed, but straight conversion, I think - theFont.SetPointSize(fontsize >> 16); - - //font name - first get length, then allocate/copy/deallocate name buffer - FontNameCode theNameCode; - FontPlatformCode thePlatformCode; - FontScriptCode theScriptCode; - FontLanguageCode theLanguageCode; - //the above have types in SFNTTypes.h - - ByteCount theActualLength; - ItemCount numFontFaces; - -/* - ATSUCountFontNames(fontid, - &numFontFaces); - - ATSUGetIndFontName(fontid, - numFontFaces-1, //first font in index array - 0, //need to get length first - NULL, //nothin' - &theActualLength, - &theNameCode, - &thePlatformCode, - &theScriptCode, - &theLanguageCode); - - Ptr szBuffer = NewPtr(theActualLength); - ATSUGetIndFontName(fontid, - numFontFaces-1, //first font in index array - theActualLength, - szBuffer, - &theActualLength, - &theNameCode, - &thePlatformCode, - &theScriptCode, - &theLanguageCode); - - //its unicode - convert it to wx's char value and put it in there - theFont.SetFaceName(wxConvLocal.cMB2WX((char*)szBuffer)); - DisposePtr(szBuffer); -*/ - + //set name Str255 theFontName; GetFontName(fontfamily, theFontName); theFont.SetFaceName(wxMacMakeStringFromPascal(theFontName)); @@ -139,15 +121,11 @@ pascal OSStatus wxFontDialogEventHandler( EventHandlerCallRef inHandlerCallRef, //TODOTODO: Get font family - mayby by the script code? theFont.SetFamily(wxDEFAULT); - //TODOTODO: Get other styles? Font weight? + //TODOTODO: Get other styles? theFont.SetStyle(((fontstyle & italic) ? wxFONTSTYLE_ITALIC : 0)); theFont.SetWeight((fontstyle & bold) ? wxBOLD : wxNORMAL); theFont.SetUnderlined(((fontstyle & underline) ? true : false)); - - //for debugging - //wxPrintf(wxT("FaceName:%s\nSize:%i\nStyle:%i\n"), theFont.GetFaceName().c_str(), theFont.GetPointSize(), - //theFont.GetStyle()); - + //phew!! We're done - set the chosen font theFontData.SetChosenFont(theFont); ((wxFontDialog*)pData)->SetData(theFontData); @@ -157,9 +135,9 @@ pascal OSStatus wxFontDialogEventHandler( EventHandlerCallRef inHandlerCallRef, DEFINE_ONE_SHOT_HANDLER_GETTER( wxFontDialogEventHandler ); -//--------------------------- -// Class implementation -//--------------------------- +// --------------------------------------------------------------------------- +// wxFontDialog +// --------------------------------------------------------------------------- wxFontDialog::wxFontDialog() : m_dialogParent(NULL), m_pEventHandlerRef(NULL) @@ -255,13 +233,18 @@ int wxFontDialog::ShowModal() status = ATSUDisposeStyle(theStyle); check_noerr(status); + //in case the user doesn't choose anything - + //if he doesn't we'll get a bad font with red text + m_fontData.SetChosenFont(m_fontData.GetInitialFont()); + m_fontData.SetColour(wxColour(0,0,0)); + //finally, show the font dialog if( (status = FPShowHideFontPanel()) == noErr) { while(FPIsFontPanelVisible()) { //yeild so we can get events - ::wxSafeYield(m_dialogParent, false); + wxTheApp->Yield(false); } } else @@ -274,10 +257,9 @@ int wxFontDialog::ShowModal() #else //10.2+ only - -// -// no native implementation -// +// --------------------------------------------------------------------------- +// wxFontDialog stub for mac OS's without a native font dialog +// --------------------------------------------------------------------------- wxFontDialog::wxFontDialog() {