1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFontDialog class for carbon 10.2+.
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "fontdlg.h"
16 #include "wx/mac/fontdlg.h"
17 #include "wx/cmndata.h"
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
23 #include "wx/mac/private.h"
25 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
27 #include <ATSUnicode.h>
29 #include "wx/msgdlg.h"
31 pascal OSStatus
wxFontDialogEventHandler( EventHandlerCallRef inHandlerCallRef
,
32 EventRef event
, void* pData
)
34 wxASSERT(GetEventClass(event
) == kEventClassFont
&&
35 GetEventKind(event
) == kEventFontSelection
);
37 OSStatus status
= noErr
;
39 FMFontFamily fontfamily
;
40 FMFontStyle fontstyle
;
44 status
= GetEventParameter (event
, kEventParamFMFontFamily
,
45 typeFMFontFamily
, NULL
,
46 sizeof (FMFontFamily
),
50 status
= GetEventParameter (event
, kEventParamFMFontStyle
,
51 typeFMFontStyle
, NULL
,
56 status
= GetEventParameter (event
, kEventParamFMFontSize
,
63 status
= GetEventParameter (event
, kEventParamFontColor
,
65 sizeof( RGBColor
), NULL
, &fontcolor
);
68 //now do the conversion to the wx font data
69 wxFontData theFontData
;
74 theColor
.Set(&(WXCOLORREF
&)fontcolor
);
75 theFontData
.SetColour(theColor
);
78 theFont
.SetPointSize(fontsize
);
82 GetFontName(fontfamily
, theFontName
);
83 theFont
.SetFaceName(wxMacMakeStringFromPascal(theFontName
));
85 //TODOTODO: Get font family - mayby by the script code?
86 theFont
.SetFamily(wxDEFAULT
);
88 //TODOTODO: Get other styles?
89 theFont
.SetStyle(((fontstyle
& italic
) ? wxFONTSTYLE_ITALIC
: 0));
90 theFont
.SetWeight((fontstyle
& bold
) ? wxBOLD
: wxNORMAL
);
91 theFont
.SetUnderlined(((fontstyle
& underline
) ? true : false));
93 //phew!! We're done - set the chosen font
94 theFontData
.SetChosenFont(theFont
);
95 ((wxFontDialog
*)pData
)->SetData(theFontData
);
100 DEFINE_ONE_SHOT_HANDLER_GETTER( wxFontDialogEventHandler
);
102 //---------------------------
103 // Class implementation
104 //---------------------------
106 wxFontDialog::wxFontDialog() :
107 m_dialogParent(NULL
), m_pEventHandlerRef(NULL
)
111 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
113 Create(parent
, data
);
116 wxFontDialog::~wxFontDialog()
118 if (m_pEventHandlerRef
)
119 ::RemoveEventHandler((EventHandlerRef
&)m_pEventHandlerRef
);
122 void wxFontDialog::SetData(wxFontData
& fontdata
)
124 m_fontData
= fontdata
;
127 bool wxFontDialog::Create(wxWindow
*parent
, const wxFontData
& data
)
129 m_dialogParent
= parent
;
132 //Register the events that will return this dialog
133 EventTypeSpec ftEventList
[] = { { kEventClassFont
, kEventFontSelection
} };
135 OSStatus err
= noErr
;
137 //FIXMEFIXME: Why doesn't it recieve events if there's a parent?
140 // err = InstallWindowEventHandler(
141 // MAC_WXHWND(parent->GetHandle()),
142 // GetwxFontDialogEventHandlerUPP(),
143 // GetEventTypeCount(ftEventList), ftEventList,
144 // this, (&(EventHandlerRef&)m_pEventHandlerRef));
147 // else //no parent - send to app
149 err
= InstallApplicationEventHandler(
150 GetwxFontDialogEventHandlerUPP(),
151 GetEventTypeCount(ftEventList
), ftEventList
,
152 this, (&(EventHandlerRef
&)m_pEventHandlerRef
));
158 bool wxFontDialog::IsShown() const
160 return FPIsFontPanelVisible();
163 int wxFontDialog::ShowModal()
165 wxASSERT(!FPIsFontPanelVisible());
167 //set up initial font
168 wxFont theInitialFont
= m_fontData
.GetInitialFont();
172 OSStatus status
= ATSUCreateStyle(&theStyle
);
175 //put stuff into the style - we don't need kATSUColorTag
176 ATSUFontID fontid
= theInitialFont
.MacGetATSUFontID();
177 Fixed fontsize
= theInitialFont
.MacGetFontSize() << 16;
178 ATSUAttributeTag theTags
[2] = { kATSUFontTag
, kATSUSizeTag
};
179 ByteCount theSizes
[2] = { sizeof(ATSUFontID
), sizeof(Fixed
) };
180 ATSUAttributeValuePtr theValues
[2] = { &fontid
,
183 //set the stuff for the ATSU style
184 verify_noerr (ATSUSetAttributes (theStyle
, 2, theTags
, theSizes
, theValues
) );
186 //they set us up the bomb! Set the initial font of the dialog
187 SetFontInfoForSelection(kFontSelectionATSUIType
,
192 GetWindowEventTarget(MAC_WXHWND(m_dialogParent
->GetHandle())) :
193 GetApplicationEventTarget())
196 //dispose of the style
197 status
= ATSUDisposeStyle(theStyle
);
200 //in case the user doesn't choose anything -
201 //if he doesn't we'll get a bad font with red text
202 m_fontData
.SetChosenFont(m_fontData
.GetInitialFont());
203 m_fontData
.SetColour(wxColour(0,0,0));
205 //finally, show the font dialog
206 if( (status
= FPShowHideFontPanel()) == noErr
)
208 while(FPIsFontPanelVisible())
210 //yeild so we can get events
211 ::wxSafeYield(m_dialogParent
, false);
226 // no native implementation
229 wxFontDialog::wxFontDialog()
231 m_dialogParent
= NULL
;
234 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
236 Create(parent
, data
);
239 void wxFontDialog::SetData(wxFontData
& fontdata
)
241 m_fontData
= fontdata
;
244 bool wxFontDialog::Create(wxWindow
*parent
, const wxFontData
& data
)
246 m_dialogParent
= parent
;
250 // TODO: you may need to do dialog creation here, unless it's
251 // done in ShowModal.
255 bool wxFontDialog::IsShown() const
260 int wxFontDialog::ShowModal()
262 // TODO: show (maybe create) the dialog