1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFontDialog class for carbon 10.2+.
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "fontdlg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/cmndata.h"
35 #include "wx/mac/fontdlg.h"
37 #if !USE_SHARED_LIBRARY
38 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
41 #include "wx/mac/private.h"
44 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
46 #include <ATSUnicode.h>
48 #include "wx/msgdlg.h"
50 //color isn't working in carbon impl
51 #define ISCOLORWORKING 0
53 // ============================================================================
55 // ============================================================================
57 // ---------------------------------------------------------------------------
58 // Carbon event callback(s)
59 // ---------------------------------------------------------------------------
61 pascal OSStatus
wxFontDialogEventHandler( EventHandlerCallRef inHandlerCallRef
,
62 EventRef event
, void* pData
)
64 wxASSERT(GetEventClass(event
) == kEventClassFont
&&
65 GetEventKind(event
) == kEventFontSelection
);
67 OSStatus status
= noErr
;
69 FMFontFamily fontfamily
;
70 FMFontStyle fontstyle
;
76 status
= GetEventParameter (event
, kEventParamFMFontFamily
,
77 typeFMFontFamily
, NULL
,
78 sizeof (FMFontFamily
),
82 status
= GetEventParameter (event
, kEventParamFMFontStyle
,
83 typeFMFontStyle
, NULL
,
88 status
= GetEventParameter (event
, kEventParamFMFontSize
,
96 status
= GetEventParameter (event
, kEventParamFontColor
,
98 sizeof( RGBColor
), NULL
, &fontcolor
);
102 //now do the conversion to the wx font data
103 wxFontData theFontData
;
109 theColor
.Set(&(WXCOLORREF
&)fontcolor
);
110 theFontData
.SetColour(theColor
);
114 theFont
.SetPointSize(fontsize
);
118 GetFontName(fontfamily
, theFontName
);
119 theFont
.SetFaceName(wxMacMakeStringFromPascal(theFontName
));
121 //TODOTODO: Get font family - mayby by the script code?
122 theFont
.SetFamily(wxDEFAULT
);
124 //TODOTODO: Get other styles?
125 theFont
.SetStyle(((fontstyle
& italic
) ? wxFONTSTYLE_ITALIC
: 0));
126 theFont
.SetWeight((fontstyle
& bold
) ? wxBOLD
: wxNORMAL
);
127 theFont
.SetUnderlined(((fontstyle
& underline
) ? true : false));
129 //phew!! We're done - set the chosen font
130 theFontData
.SetChosenFont(theFont
);
131 ((wxFontDialog
*)pData
)->SetData(theFontData
);
136 DEFINE_ONE_SHOT_HANDLER_GETTER( wxFontDialogEventHandler
);
138 // ---------------------------------------------------------------------------
140 // ---------------------------------------------------------------------------
142 wxFontDialog::wxFontDialog() :
143 m_dialogParent(NULL
), m_pEventHandlerRef(NULL
)
147 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
149 Create(parent
, data
);
152 wxFontDialog::~wxFontDialog()
154 if (m_pEventHandlerRef
)
155 ::RemoveEventHandler((EventHandlerRef
&)m_pEventHandlerRef
);
158 void wxFontDialog::SetData(wxFontData
& fontdata
)
160 m_fontData
= fontdata
;
163 bool wxFontDialog::Create(wxWindow
*parent
, const wxFontData
& data
)
165 m_dialogParent
= parent
;
168 //Register the events that will return this dialog
169 EventTypeSpec ftEventList
[] = { { kEventClassFont
, kEventFontSelection
} };
171 OSStatus err
= noErr
;
173 //FIXMEFIXME: Why doesn't it recieve events if there's a parent?
176 // err = InstallWindowEventHandler(
177 // MAC_WXHWND(parent->GetHandle()),
178 // GetwxFontDialogEventHandlerUPP(),
179 // GetEventTypeCount(ftEventList), ftEventList,
180 // this, (&(EventHandlerRef&)m_pEventHandlerRef));
183 // else //no parent - send to app
185 err
= InstallApplicationEventHandler(
186 GetwxFontDialogEventHandlerUPP(),
187 GetEventTypeCount(ftEventList
), ftEventList
,
188 this, (&(EventHandlerRef
&)m_pEventHandlerRef
));
194 bool wxFontDialog::IsShown() const
196 return FPIsFontPanelVisible();
199 int wxFontDialog::ShowModal()
201 wxASSERT(!FPIsFontPanelVisible());
203 //set up initial font
204 wxFont theInitialFont
= m_fontData
.GetInitialFont();
208 OSStatus status
= ATSUCreateStyle(&theStyle
);
211 //put stuff into the style - we don't need kATSUColorTag
212 ATSUFontID fontid
= theInitialFont
.MacGetATSUFontID();
213 Fixed fontsize
= theInitialFont
.MacGetFontSize() << 16;
214 ATSUAttributeTag theTags
[2] = { kATSUFontTag
, kATSUSizeTag
};
215 ByteCount theSizes
[2] = { sizeof(ATSUFontID
), sizeof(Fixed
) };
216 ATSUAttributeValuePtr theValues
[2] = { &fontid
,
219 //set the stuff for the ATSU style
220 verify_noerr (ATSUSetAttributes (theStyle
, 2, theTags
, theSizes
, theValues
) );
222 //they set us up the bomb! Set the initial font of the dialog
223 SetFontInfoForSelection(kFontSelectionATSUIType
,
228 GetWindowEventTarget(MAC_WXHWND(m_dialogParent
->GetHandle())) :
229 GetApplicationEventTarget())
232 //dispose of the style
233 status
= ATSUDisposeStyle(theStyle
);
236 //in case the user doesn't choose anything -
237 //if he doesn't we'll get a bad font with red text
238 m_fontData
.SetChosenFont(m_fontData
.GetInitialFont());
239 m_fontData
.SetColour(wxColour(0,0,0));
241 //finally, show the font dialog
242 if( (status
= FPShowHideFontPanel()) == noErr
)
244 while(FPIsFontPanelVisible())
246 //yeild so we can get events
247 wxTheApp
->Yield(false);
260 // ---------------------------------------------------------------------------
261 // wxFontDialog stub for mac OS's without a native font dialog
262 // ---------------------------------------------------------------------------
264 wxFontDialog::wxFontDialog()
266 m_dialogParent
= NULL
;
269 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
271 Create(parent
, data
);
274 wxFontDialog::~wxFontDialog()
279 void wxFontDialog::SetData(wxFontData
& fontdata
)
281 m_fontData
= fontdata
;
284 bool wxFontDialog::Create(wxWindow
*parent
, const wxFontData
& data
)
286 m_dialogParent
= parent
;
290 // TODO: you may need to do dialog creation here, unless it's
291 // done in ShowModal.
295 bool wxFontDialog::IsShown() const
300 int wxFontDialog::ShowModal()
302 // TODO: show (maybe create) the dialog