+wxFontDialog::~wxFontDialog()
+{
+}
+
+bool wxFontDialog::Create(wxWindow *WXUNUSED(parent), const wxFontData& data)
+{
+ m_fontData = data;
+ return true ;
+}
+
+int wxFontDialog::ShowModal()
+{
+ OSStatus err ;
+ wxFont font = *wxNORMAL_FONT ;
+ if ( m_fontData.m_initialFont.Ok() )
+ {
+ font = m_fontData.m_initialFont ;
+ }
+
+ bool setup = false;
+#if wxMAC_USE_CORE_TEXT
+ if ( UMAGetSystemVersion() >= 0x1050 )
+ {
+ CTFontDescriptorRef descr = (CTFontDescriptorRef)font.MacGetCTFontDescriptor();
+ err = SetFontInfoForSelection (kFontSelectionCoreTextType,1, &descr , NULL);
+ setup = true;
+ }
+#endif
+#if wxMAC_USE_ATSU_TEXT
+ if ( !setup )
+ {
+ ATSUStyle style = (ATSUStyle)font.MacGetATSUStyle();
+ err = SetFontInfoForSelection (kFontSelectionATSUIType,1, &style , NULL);
+ setup = true;
+ }
+#endif
+ // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
+ // that field is already correct
+ m_fontData.m_chosenFont = font ;
+
+ EventHandlerRef handler ;
+
+ err = InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList), eventList, this , &handler );
+
+ if ( !FPIsFontPanelVisible() )
+ FPShowHideFontPanel();
+
+ int retval = RunMixedFontDialog(this);
+
+ ::RemoveEventHandler(handler);
+
+ return retval ;
+}
+
+#else
+
+#if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
+
+#undef wxFontDialog
+
+#include "wx/mac/fontdlg.h"
+
+#include "wx/fontenum.h"
+#include "wx/colordlg.h"
+#include "wx/spinctrl.h"
+
+// ---------------------------------------------------------------------------
+// wxFontDialog stub for mac OS's without a native font dialog
+// ---------------------------------------------------------------------------
+
+static const wxChar *FontFamilyIntToString(int family);
+static int FontFamilyStringToInt(const wxChar *family);
+
+
+//-----------------------------------------------------------------------------
+// helper class - wxFontPreviewCtrl
+//-----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxFontPreviewCtrl : public wxWindow
+{
+public:
+ wxFontPreviewCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = 0) :
+ wxWindow(parent, id, pos, sz, style)
+ {
+ SetBackgroundColour(*wxWHITE);
+ }
+
+private:
+ void OnPaint(wxPaintEvent& event);
+ DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(wxFontPreviewCtrl, wxWindow)
+ EVT_PAINT(wxFontPreviewCtrl::OnPaint)
+END_EVENT_TABLE()
+
+void wxFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
+{
+ wxPaintDC dc(this);
+
+ wxSize size = GetSize();
+ wxFont font = GetFont();
+
+ if ( font.Ok() )
+ {
+ dc.SetFont(font);
+ // Calculate vertical centre
+ long w = 0, h = 0;
+ dc.GetTextExtent( wxT("X"), &w, &h);
+ dc.SetTextForeground(GetForegroundColour());
+ dc.SetClippingRegion(2, 2, size.x-4, size.y-4);
+ dc.DrawText(_("ABCDEFGabcdefg12345"),
+ 10, size.y/2 - h/2);
+ dc.DestroyClippingRegion();
+ }
+}
+
+/*
+ * A control for displaying a small preview of a colour or bitmap
+ */
+
+class wxFontColourSwatchCtrl: public wxControl
+{
+ DECLARE_CLASS(wxFontColourSwatchCtrl)
+public:
+ wxFontColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
+ virtual ~wxFontColourSwatchCtrl();
+
+ void OnPaint(wxPaintEvent& event);
+ void OnMouseEvent(wxMouseEvent& event);
+
+ void SetColour(const wxColour& colour) { m_colour = colour; SetBackgroundColour(m_colour); }
+
+ wxColour& GetColour() { return m_colour; }
+
+ virtual wxSize DoGetBestSize() const { return GetSize(); }
+
+protected:
+ wxColour m_colour;
+
+DECLARE_EVENT_TABLE()
+};
+
+/*
+ * A control for displaying a small preview of a colour or bitmap
+ */
+
+BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl, wxControl)
+ EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent)
+END_EVENT_TABLE()
+
+IMPLEMENT_CLASS(wxFontColourSwatchCtrl, wxControl)
+
+wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
+ wxControl(parent, id, pos, size, style)
+{
+ SetColour(* wxWHITE);
+ SetBackgroundStyle(wxBG_STYLE_COLOUR);
+}
+
+wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
+{
+}
+
+void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent& event)
+{
+ if (event.LeftDown())
+ {
+ wxWindow* parent = GetParent();
+ while (parent != NULL && !parent->IsKindOf(CLASSINFO(wxDialog)) && !parent->IsKindOf(CLASSINFO(wxFrame)))
+ parent = parent->GetParent();
+
+ wxColourData data;
+ data.SetChooseFull(true);
+ data.SetColour(m_colour);
+ wxColourDialog *dialog = new wxColourDialog(parent, &data);
+ // Crashes on wxMac (no m_peer)
+#ifndef __WXMAC__
+ dialog->SetTitle(_("Background colour"));
+#endif
+ if (dialog->ShowModal() == wxID_OK)
+ {
+ wxColourData retData = dialog->GetColourData();
+ m_colour = retData.GetColour();
+ SetBackgroundColour(m_colour);
+ }
+ dialog->Destroy();
+ Refresh();
+
+ wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
+ HandleWindowEvent(event);
+ }
+}
+
+/*!
+ * wxFontDialog type definition
+ */
+
+IMPLEMENT_DYNAMIC_CLASS( wxFontDialog, wxDialog )
+
+/*!
+ * wxFontDialog event table definition
+ */
+
+BEGIN_EVENT_TABLE( wxFontDialog, wxDialog )
+ EVT_LISTBOX( wxID_FONTDIALOG_FACENAME, wxFontDialog::OnFontdialogFacenameSelected )
+ EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE, wxFontDialog::OnFontdialogFontsizeUpdated )
+ EVT_TEXT( wxID_FONTDIALOG_FONTSIZE, wxFontDialog::OnFontdialogFontsizeTextUpdated )
+ EVT_CHECKBOX( wxID_FONTDIALOG_BOLD, wxFontDialog::OnFontdialogBoldClick )
+ EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC, wxFontDialog::OnFontdialogItalicClick )
+ EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED, wxFontDialog::OnFontdialogUnderlinedClick )
+ EVT_BUTTON( wxID_OK, wxFontDialog::OnOkClick )
+ EVT_BUTTON(wxID_FONTDIALOG_COLOUR, wxFontDialog::OnColourChanged)
+END_EVENT_TABLE()
+
+/*!
+ * wxFontDialog constructors
+ */
+
+wxFontDialog::wxFontDialog( )
+{
+ m_dialogParent = NULL;
+}
+
+wxFontDialog::wxFontDialog(wxWindow* parent, const wxFontData& fontData)
+{
+ m_dialogParent = NULL;
+
+ Create(parent, fontData);
+}
+