]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: fontdlg.cpp | |
72fcdc75 RN |
3 | // Purpose: wxFontDialog class for carbon 10.2+. |
4 | // Author: Ryan Norton | |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
72fcdc75 RN |
8 | // Copyright: (c) Ryan Norton |
9 | // Licence: wxWindows licence | |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
1553abf4 RN |
12 | // =========================================================================== |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
e9576ca5 SC |
20 | #ifdef __GNUG__ |
21 | #pragma implementation "fontdlg.h" | |
22 | #endif | |
23 | ||
1553abf4 RN |
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 | |
e9576ca5 | 35 | |
2f1ae414 | 36 | #if !USE_SHARED_LIBRARY |
e9576ca5 | 37 | IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) |
2f1ae414 | 38 | #endif |
e9576ca5 | 39 | |
72fcdc75 RN |
40 | #include "wx/mac/private.h" |
41 | ||
1553abf4 | 42 | //Mac OSX 10.2+ only |
72fcdc75 RN |
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 | ||
1553abf4 RN |
49 | // ============================================================================ |
50 | // implementation | |
51 | // ============================================================================ | |
52 | ||
53 | // --------------------------------------------------------------------------- | |
54 | // Carbon event callback(s) | |
55 | // --------------------------------------------------------------------------- | |
56 | ||
72fcdc75 RN |
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 | ||
ffa561cf | 65 | FMFontFamily fontfamily; |
c0a6772a RN |
66 | FMFontStyle fontstyle; |
67 | FMFontSize fontsize; | |
68 | RGBColor fontcolor; | |
72fcdc75 | 69 | |
ffa561cf RN |
70 | status = GetEventParameter (event, kEventParamFMFontFamily, |
71 | typeFMFontFamily, NULL, | |
72 | sizeof (FMFontFamily), | |
73 | NULL, &(fontfamily)); | |
74 | check_noerr (status); | |
75 | ||
72fcdc75 RN |
76 | status = GetEventParameter (event, kEventParamFMFontStyle, |
77 | typeFMFontStyle, NULL, | |
78 | sizeof (FMFontStyle), | |
79 | NULL, &(fontstyle)); | |
80 | check_noerr (status); | |
81 | ||
c0a6772a RN |
82 | status = GetEventParameter (event, kEventParamFMFontSize, |
83 | typeFMFontSize, NULL, | |
84 | sizeof (FMFontSize), | |
72fcdc75 RN |
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 | ||
72fcdc75 RN |
94 | //now do the conversion to the wx font data |
95 | wxFontData theFontData; | |
96 | wxFont theFont; | |
97 | ||
c0a6772a | 98 | //set color |
72fcdc75 RN |
99 | wxColour theColor; |
100 | theColor.Set(&(WXCOLORREF&)fontcolor); | |
101 | theFontData.SetColour(theColor); | |
c0a6772a RN |
102 | |
103 | //set size | |
104 | theFont.SetPointSize(fontsize); | |
72fcdc75 | 105 | |
c0a6772a | 106 | //set name |
ffa561cf RN |
107 | Str255 theFontName; |
108 | GetFontName(fontfamily, theFontName); | |
109 | theFont.SetFaceName(wxMacMakeStringFromPascal(theFontName)); | |
110 | ||
72fcdc75 RN |
111 | //TODOTODO: Get font family - mayby by the script code? |
112 | theFont.SetFamily(wxDEFAULT); | |
113 | ||
c0a6772a | 114 | //TODOTODO: Get other styles? |
810d800e | 115 | theFont.SetStyle(((fontstyle & italic) ? wxFONTSTYLE_ITALIC : 0)); |
72fcdc75 | 116 | theFont.SetWeight((fontstyle & bold) ? wxBOLD : wxNORMAL); |
810d800e | 117 | theFont.SetUnderlined(((fontstyle & underline) ? true : false)); |
c0a6772a | 118 | |
72fcdc75 RN |
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 | ||
1553abf4 RN |
128 | // --------------------------------------------------------------------------- |
129 | // wxFontDialog | |
130 | // --------------------------------------------------------------------------- | |
72fcdc75 RN |
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 | ||
f5698096 RN |
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 | ||
72fcdc75 RN |
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 | ||
1553abf4 RN |
250 | // --------------------------------------------------------------------------- |
251 | // wxFontDialog stub for mac OS's without a native font dialog | |
252 | // --------------------------------------------------------------------------- | |
e9576ca5 SC |
253 | |
254 | wxFontDialog::wxFontDialog() | |
255 | { | |
256 | m_dialogParent = NULL; | |
257 | } | |
258 | ||
baaae89f | 259 | wxFontDialog::wxFontDialog(wxWindow *parent, const wxFontData& data) |
e9576ca5 SC |
260 | { |
261 | Create(parent, data); | |
262 | } | |
263 | ||
72fcdc75 RN |
264 | void wxFontDialog::SetData(wxFontData& fontdata) |
265 | { | |
266 | m_fontData = fontdata; | |
267 | } | |
268 | ||
baaae89f | 269 | bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data) |
e9576ca5 SC |
270 | { |
271 | m_dialogParent = parent; | |
272 | ||
baaae89f | 273 | m_fontData = data; |
e9576ca5 SC |
274 | |
275 | // TODO: you may need to do dialog creation here, unless it's | |
276 | // done in ShowModal. | |
277 | return TRUE; | |
278 | } | |
279 | ||
72fcdc75 RN |
280 | bool wxFontDialog::IsShown() const |
281 | { | |
282 | return false; | |
283 | } | |
284 | ||
e9576ca5 SC |
285 | int wxFontDialog::ShowModal() |
286 | { | |
287 | // TODO: show (maybe create) the dialog | |
288 | return wxID_CANCEL; | |
289 | } | |
290 | ||
72fcdc75 | 291 | #endif // 10.2+ |