// 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/mac/fontdlg.h"
+ #include "wx/cmndata.h"
+#endif
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
#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 <ATSUnicode.h>
#include "wx/msgdlg.h"
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ---------------------------------------------------------------------------
+// Carbon event callback(s)
+// ---------------------------------------------------------------------------
+
pascal OSStatus wxFontDialogEventHandler( EventHandlerCallRef inHandlerCallRef,
EventRef event, void* pData)
{
OSStatus status = noErr;
- ATSUFontID fontid;
- Fixed fontsize;
- RGBColor fontcolor;
+ FMFontFamily fontfamily;
FMFontStyle fontstyle;
+ FMFontSize fontsize;
+ RGBColor fontcolor;
+ status = GetEventParameter (event, kEventParamFMFontFamily,
+ typeFMFontFamily, NULL,
+ sizeof (FMFontFamily),
+ NULL, &(fontfamily));
+ check_noerr (status);
+
status = GetEventParameter (event, kEventParamFMFontStyle,
typeFMFontStyle, NULL,
sizeof (FMFontStyle),
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);
sizeof( RGBColor ), NULL, &fontcolor);
check_noerr (status);
- //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
+ //set color
wxColour theColor;
theColor.Set(&(WXCOLORREF&)fontcolor);
theFontData.SetColour(theColor);
+
+ //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;
- ATSUGetIndFontName(fontid,
- 0, //first font in index array
- 0, //need to get length first
- NULL, //nothin'
- &theActualLength,
- &theNameCode,
- &thePlatformCode,
- &theScriptCode,
- &theLanguageCode);
-
- Ptr szBuffer = new wxChar[theActualLength];
- ATSUGetIndFontName(fontid,
- 0, //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.cWC2WX((wchar_t*)szBuffer));
- delete[] szBuffer;
-
+ //set name
+ Str255 theFontName;
+ GetFontName(fontfamily, theFontName);
+ theFont.SetFaceName(wxMacMakeStringFromPascal(theFontName));
+
//TODOTODO: Get font family - mayby by the script code?
theFont.SetFamily(wxDEFAULT);
- //TODOTODO: Get other styles? Font weight?
- theFont.SetStyle(0 +
- ((fontstyle & bold) ? wxFONTFLAG_BOLD : 0) +
- ((fontstyle & italic) ? wxFONTFLAG_ITALIC : 0) +
- ((fontstyle & underline) ? wxFONTFLAG_UNDERLINED : 0)
- );
+ //TODOTODO: Get other styles?
+ theFont.SetStyle(((fontstyle & italic) ? wxFONTSTYLE_ITALIC : 0));
theFont.SetWeight((fontstyle & bold) ? wxBOLD : wxNORMAL);
-
- //for debugging
- //wxPrintf(wxT("FaceName:%s\nSize:%i\n"), theFont.GetFaceName().c_str(), theFont.GetPointSize());
-
+ theFont.SetUnderlined(((fontstyle & underline) ? true : false));
+
//phew!! We're done - set the chosen font
theFontData.SetChosenFont(theFont);
((wxFontDialog*)pData)->SetData(theFontData);
DEFINE_ONE_SHOT_HANDLER_GETTER( wxFontDialogEventHandler );
-//---------------------------
-// Class implementation
-//---------------------------
+// ---------------------------------------------------------------------------
+// wxFontDialog
+// ---------------------------------------------------------------------------
wxFontDialog::wxFontDialog() :
m_dialogParent(NULL), m_pEventHandlerRef(NULL)
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)
{
#else
//10.2+ only
-
-//
-// no native implementation
-//
+// ---------------------------------------------------------------------------
+// wxFontDialog stub for mac OS's without a native font dialog
+// ---------------------------------------------------------------------------
wxFontDialog::wxFontDialog()
{