]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/fontdlg.cpp
remove unfinished impl
[wxWidgets.git] / src / mac / carbon / fontdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: fontdlg.cpp
3 // Purpose: wxFontDialog class for carbon 10.2+.
4 // Author: Ryan Norton
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "fontdlg.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/mac/fontdlg.h"
33 #include "wx/cmndata.h"
34 #endif
35
36 #if !USE_SHARED_LIBRARY
37 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
38 #endif
39
40 #include "wx/mac/private.h"
41
42 //Mac OSX 10.2+ only
43 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
44
45 #include <ATSUnicode.h>
46
47 #include "wx/msgdlg.h"
48
49 // ============================================================================
50 // implementation
51 // ============================================================================
52
53 // ---------------------------------------------------------------------------
54 // Carbon event callback(s)
55 // ---------------------------------------------------------------------------
56
57 pascal OSStatus wxFontDialogEventHandler( EventHandlerCallRef inHandlerCallRef,
58 EventRef event, void* pData)
59 {
60 wxASSERT(GetEventClass(event) == kEventClassFont &&
61 GetEventKind(event) == kEventFontSelection);
62
63 OSStatus status = noErr;
64
65 FMFontFamily fontfamily;
66 FMFontStyle fontstyle;
67 FMFontSize fontsize;
68 RGBColor fontcolor;
69
70 status = GetEventParameter (event, kEventParamFMFontFamily,
71 typeFMFontFamily, NULL,
72 sizeof (FMFontFamily),
73 NULL, &(fontfamily));
74 check_noerr (status);
75
76 status = GetEventParameter (event, kEventParamFMFontStyle,
77 typeFMFontStyle, NULL,
78 sizeof (FMFontStyle),
79 NULL, &(fontstyle));
80 check_noerr (status);
81
82 status = GetEventParameter (event, kEventParamFMFontSize,
83 typeFMFontSize, NULL,
84 sizeof (FMFontSize),
85 NULL, &(fontsize));
86
87 check_noerr (status);
88
89 status = GetEventParameter (event, kEventParamFontColor,
90 typeRGBColor, NULL,
91 sizeof( RGBColor ), NULL, &fontcolor);
92 check_noerr (status);
93
94 //now do the conversion to the wx font data
95 wxFontData theFontData;
96 wxFont theFont;
97
98 //set color
99 wxColour theColor;
100 theColor.Set(&(WXCOLORREF&)fontcolor);
101 theFontData.SetColour(theColor);
102
103 //set size
104 theFont.SetPointSize(fontsize);
105
106 //set name
107 Str255 theFontName;
108 GetFontName(fontfamily, theFontName);
109 theFont.SetFaceName(wxMacMakeStringFromPascal(theFontName));
110
111 //TODOTODO: Get font family - mayby by the script code?
112 theFont.SetFamily(wxDEFAULT);
113
114 //TODOTODO: Get other styles?
115 theFont.SetStyle(((fontstyle & italic) ? wxFONTSTYLE_ITALIC : 0));
116 theFont.SetWeight((fontstyle & bold) ? wxBOLD : wxNORMAL);
117 theFont.SetUnderlined(((fontstyle & underline) ? true : false));
118
119 //phew!! We're done - set the chosen font
120 theFontData.SetChosenFont(theFont);
121 ((wxFontDialog*)pData)->SetData(theFontData);
122
123 return status;
124 }
125
126 DEFINE_ONE_SHOT_HANDLER_GETTER( wxFontDialogEventHandler );
127
128 // ---------------------------------------------------------------------------
129 // wxFontDialog
130 // ---------------------------------------------------------------------------
131
132 wxFontDialog::wxFontDialog() :
133 m_dialogParent(NULL), m_pEventHandlerRef(NULL)
134 {
135 }
136
137 wxFontDialog::wxFontDialog(wxWindow *parent, const wxFontData& data)
138 {
139 Create(parent, data);
140 }
141
142 wxFontDialog::~wxFontDialog()
143 {
144 if (m_pEventHandlerRef)
145 ::RemoveEventHandler((EventHandlerRef&)m_pEventHandlerRef);
146 }
147
148 void wxFontDialog::SetData(wxFontData& fontdata)
149 {
150 m_fontData = fontdata;
151 }
152
153 bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data)
154 {
155 m_dialogParent = parent;
156 m_fontData = data;
157
158 //Register the events that will return this dialog
159 EventTypeSpec ftEventList[] = { { kEventClassFont, kEventFontSelection } };
160
161 OSStatus err = noErr;
162
163 //FIXMEFIXME: Why doesn't it recieve events if there's a parent?
164 // if (parent)
165 // {
166 // err = InstallWindowEventHandler(
167 // MAC_WXHWND(parent->GetHandle()),
168 // GetwxFontDialogEventHandlerUPP(),
169 // GetEventTypeCount(ftEventList), ftEventList,
170 // this, (&(EventHandlerRef&)m_pEventHandlerRef));
171 //
172 // }
173 // else //no parent - send to app
174 // {
175 err = InstallApplicationEventHandler(
176 GetwxFontDialogEventHandlerUPP(),
177 GetEventTypeCount(ftEventList), ftEventList,
178 this, (&(EventHandlerRef&)m_pEventHandlerRef));
179 // }
180
181 return err == noErr;
182 }
183
184 bool wxFontDialog::IsShown() const
185 {
186 return FPIsFontPanelVisible();
187 }
188
189 int wxFontDialog::ShowModal()
190 {
191 wxASSERT(!FPIsFontPanelVisible());
192
193 //set up initial font
194 wxFont theInitialFont = m_fontData.GetInitialFont();
195
196 //create ATSU style
197 ATSUStyle theStyle;
198 OSStatus status = ATSUCreateStyle(&theStyle);
199 check_noerr(status);
200
201 //put stuff into the style - we don't need kATSUColorTag
202 ATSUFontID fontid = theInitialFont.MacGetATSUFontID();
203 Fixed fontsize = theInitialFont.MacGetFontSize() << 16;
204 ATSUAttributeTag theTags[2] = { kATSUFontTag, kATSUSizeTag };
205 ByteCount theSizes[2] = { sizeof(ATSUFontID), sizeof(Fixed) };
206 ATSUAttributeValuePtr theValues[2] = { &fontid,
207 &fontsize };
208
209 //set the stuff for the ATSU style
210 verify_noerr (ATSUSetAttributes (theStyle, 2, theTags, theSizes, theValues) );
211
212 //they set us up the bomb! Set the initial font of the dialog
213 SetFontInfoForSelection(kFontSelectionATSUIType,
214 1,
215 &theStyle,
216 (HIObjectRef)
217 (m_dialogParent ?
218 GetWindowEventTarget(MAC_WXHWND(m_dialogParent->GetHandle())) :
219 GetApplicationEventTarget())
220 );
221
222 //dispose of the style
223 status = ATSUDisposeStyle(theStyle);
224 check_noerr(status);
225
226 //in case the user doesn't choose anything -
227 //if he doesn't we'll get a bad font with red text
228 m_fontData.SetChosenFont(m_fontData.GetInitialFont());
229 m_fontData.SetColour(wxColour(0,0,0));
230
231 //finally, show the font dialog
232 if( (status = FPShowHideFontPanel()) == noErr)
233 {
234 while(FPIsFontPanelVisible())
235 {
236 //yeild so we can get events
237 ::wxSafeYield(m_dialogParent, false);
238 }
239 }
240 else
241 return wxID_CANCEL;
242
243 return wxID_OK;
244 }
245
246
247 #else
248 //10.2+ only
249
250 // ---------------------------------------------------------------------------
251 // wxFontDialog stub for mac OS's without a native font dialog
252 // ---------------------------------------------------------------------------
253
254 wxFontDialog::wxFontDialog()
255 {
256 m_dialogParent = NULL;
257 }
258
259 wxFontDialog::wxFontDialog(wxWindow *parent, const wxFontData& data)
260 {
261 Create(parent, data);
262 }
263
264 void wxFontDialog::SetData(wxFontData& fontdata)
265 {
266 m_fontData = fontdata;
267 }
268
269 bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data)
270 {
271 m_dialogParent = parent;
272
273 m_fontData = data;
274
275 // TODO: you may need to do dialog creation here, unless it's
276 // done in ShowModal.
277 return TRUE;
278 }
279
280 bool wxFontDialog::IsShown() const
281 {
282 return false;
283 }
284
285 int wxFontDialog::ShowModal()
286 {
287 // TODO: show (maybe create) the dialog
288 return wxID_CANCEL;
289 }
290
291 #endif // 10.2+