]>
Commit | Line | Data |
---|---|---|
489468fe | 1 | ///////////////////////////////////////////////////////////////////////////// |
524c47aa | 2 | // Name: src/osx/carbon/fontdlg.cpp |
489468fe SC |
3 | // Purpose: wxFontDialog class for carbon 10.2+. |
4 | // Author: Ryan Norton | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
489468fe SC |
7 | // Copyright: (c) Ryan Norton |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // =========================================================================== | |
12 | // declarations | |
13 | // =========================================================================== | |
14 | ||
15 | // --------------------------------------------------------------------------- | |
16 | // headers | |
17 | // --------------------------------------------------------------------------- | |
18 | ||
19 | // For compilers that support precompilation, includes "wx.h". | |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #if wxUSE_FONTDLG | |
23 | ||
24 | #ifdef __BORLANDC__ | |
25 | #pragma hdrstop | |
26 | #endif | |
27 | ||
28 | #ifndef WX_PRECOMP | |
29 | #include "wx/intl.h" | |
30 | #include "wx/crt.h" | |
31 | #include "wx/dcclient.h" | |
32 | #include "wx/frame.h" | |
33 | #include "wx/textctrl.h" | |
34 | #include "wx/listbox.h" | |
35 | #include "wx/checkbox.h" | |
36 | #include "wx/choice.h" | |
37 | #include "wx/sizer.h" | |
38 | #include "wx/stattext.h" | |
39 | #include "wx/button.h" | |
40 | #endif | |
41 | ||
42 | #include "wx/fontdlg.h" | |
f1c40652 | 43 | #include "wx/fontutil.h" |
691745ab | 44 | #include "wx/modalhook.h" |
489468fe | 45 | |
292e5e1f | 46 | #if wxOSX_USE_EXPERIMENTAL_FONTDIALOG |
489468fe SC |
47 | |
48 | IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) | |
49 | ||
524c47aa | 50 | #include "wx/osx/private.h" |
489468fe SC |
51 | |
52 | // --------------------------------------------------------------------------- | |
53 | // wxFontDialog | |
54 | // --------------------------------------------------------------------------- | |
55 | ||
524c47aa SC |
56 | #if wxOSX_USE_CARBON |
57 | ||
489468fe SC |
58 | static const EventTypeSpec eventList[] = |
59 | { | |
60 | { kEventClassFont, kEventFontSelection } , | |
61 | } ; | |
62 | ||
63 | ||
64 | pascal OSStatus | |
65 | wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler), | |
66 | EventRef event, | |
67 | void *userData) | |
68 | { | |
69 | OSStatus result = eventNotHandledErr ; | |
70 | wxFontDialog *fontdialog = (wxFontDialog*) userData ; | |
71 | wxFontData& fontdata= fontdialog->GetFontData() ; | |
72 | ||
73 | wxMacCarbonEvent cEvent( event ); | |
74 | switch(cEvent.GetKind()) | |
75 | { | |
76 | case kEventFontSelection : | |
77 | { | |
78 | bool setup = false ; | |
292e5e1f | 79 | #if wxOSX_USE_CORE_TEXT |
b97d6fb1 | 80 | if ( !setup ) |
489468fe SC |
81 | { |
82 | CTFontDescriptorRef descr; | |
83 | if ( cEvent.GetParameter<CTFontDescriptorRef>( kEventParamCTFontDescriptor, typeCTFontDescriptorRef, &descr ) == noErr ) | |
84 | { | |
85 | wxFont font; | |
f1c40652 SC |
86 | wxNativeFontInfo fontinfo; |
87 | fontinfo.Init(descr); | |
88 | font.Create(fontinfo); | |
489468fe SC |
89 | fontdata.SetChosenFont( font ) ; |
90 | setup = true; | |
91 | } | |
92 | } | |
93 | #endif | |
292e5e1f | 94 | #if wxOSX_USE_ATSU_TEXT |
489468fe SC |
95 | ATSUFontID fontId = 0 ; |
96 | if ( !setup && (cEvent.GetParameter<ATSUFontID>(kEventParamATSUFontID, &fontId) == noErr) ) | |
97 | { | |
98 | FMFontStyle fontStyle = cEvent.GetParameter<FMFontStyle>(kEventParamFMFontStyle); | |
99 | FMFontSize fontSize = cEvent.GetParameter<FMFontSize>(kEventParamFMFontSize); | |
100 | ||
101 | CFStringRef cfName = NULL; | |
102 | #if 1 | |
103 | FMFontFamily fontFamily = cEvent.GetParameter<FMFontFamily>(kEventParamFMFontFamily); | |
104 | ATSFontFamilyRef atsfontfamilyref = FMGetATSFontFamilyRefFromFontFamily( fontFamily ) ; | |
105 | OSStatus err = ATSFontFamilyGetName( atsfontfamilyref , kATSOptionFlagsDefault , &cfName ) ; | |
8dcf5bc1 | 106 | if ( err != noErr ) |
489468fe SC |
107 | { |
108 | wxFAIL_MSG("ATSFontFamilyGetName failed"); | |
109 | } | |
110 | #else | |
111 | // we don't use the ATSU naming anymore | |
112 | ByteCount actualLength = 0; | |
113 | char *c = NULL; | |
114 | OSStatus err = ATSUFindFontName(fontId , kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode, | |
115 | kFontNoLanguageCode , 0 , NULL , &actualLength , NULL ); | |
116 | if ( err == noErr) | |
117 | { | |
118 | actualLength += 1 ; | |
119 | char *c = (char*)malloc( actualLength ); | |
120 | err = ATSUFindFontName(fontId, kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode, | |
121 | kFontNoLanguageCode, actualLength, c , NULL, NULL); | |
122 | cfName = CFStringCreateWithCharacters(NULL, (UniChar*) c, (actualLength-1) >> 1); | |
123 | } | |
124 | else | |
125 | { | |
126 | err = ATSUFindFontName(fontId , kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode, | |
127 | kFontNoLanguageCode , 0 , NULL , &actualLength , NULL ); | |
128 | if ( err == noErr ) | |
129 | { | |
130 | actualLength += 1 ; | |
131 | c = (char*)malloc(actualLength); | |
132 | err = ATSUFindFontName(fontId, kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode, | |
133 | kFontNoLanguageCode, actualLength, c , NULL, NULL); | |
134 | c[actualLength-1] = 0; | |
135 | cfName = CFStringCreateWithCString(NULL, c, kCFStringEncodingMacRoman ); | |
136 | } | |
137 | } | |
138 | if ( c!=NULL ) | |
139 | free(c); | |
140 | #endif | |
141 | if ( cfName!=NULL ) | |
142 | { | |
143 | fontdata.m_chosenFont.SetFaceName(wxCFStringRef(cfName).AsString(wxLocale::GetSystemEncoding())); | |
144 | fontdata.m_chosenFont.SetPointSize(fontSize); | |
145 | fontdata.m_chosenFont.SetStyle(fontStyle & italic ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL); | |
146 | fontdata.m_chosenFont.SetUnderlined((fontStyle & underline)!=0); | |
147 | fontdata.m_chosenFont.SetWeight(fontStyle & bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL); | |
148 | } | |
149 | } | |
292e5e1f | 150 | #endif // wxOSX_USE_ATSU_TEXT |
489468fe SC |
151 | |
152 | // retrieving the color | |
153 | RGBColor fontColor ; | |
154 | if ( cEvent.GetParameter<RGBColor>(kEventParamFontColor, &fontColor) == noErr ) | |
155 | { | |
156 | fontdata.m_fontColour = fontColor; | |
157 | } | |
158 | else | |
159 | { | |
160 | CFDictionaryRef dict ; | |
161 | if ( cEvent.GetParameter<CFDictionaryRef>(kEventParamDictionary, &dict) == noErr ) | |
162 | { | |
163 | CFDictionaryRef attributesDict ; | |
164 | if ( CFDictionaryGetValueIfPresent(dict, kFontPanelAttributesKey, (const void **)&attributesDict) ) | |
165 | { | |
166 | CFDataRef tagsData; | |
167 | CFDataRef sizesData; | |
168 | CFDataRef valuesData; | |
169 | if ( CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeTagsKey, (const void **)&tagsData) && | |
170 | CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeSizesKey, (const void **)&sizesData) && | |
171 | CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeValuesKey, (const void **)&valuesData) ) | |
172 | { | |
173 | ItemCount count = CFDataGetLength(tagsData)/sizeof(ATSUAttributeTag); | |
174 | ATSUAttributeTag *tagPtr = (ATSUAttributeTag *)CFDataGetBytePtr(tagsData); | |
175 | ByteCount *sizePtr = (ByteCount *)CFDataGetBytePtr(sizesData); | |
176 | UInt32 *bytePtr = (UInt32*)CFDataGetBytePtr(valuesData); | |
177 | ATSUAttributeValuePtr valuesPtr = bytePtr ; | |
178 | for ( ItemCount i = 0 ; i < count ; ++i) | |
179 | { | |
180 | if ( tagPtr[i] == kATSUColorTag && sizePtr[i] == sizeof(RGBColor)) | |
181 | { | |
182 | fontdata.m_fontColour = *(RGBColor *)valuesPtr; | |
183 | break ; | |
184 | } | |
185 | bytePtr = (UInt32*)( (UInt8*)bytePtr + sizePtr[i]); | |
186 | } | |
187 | } | |
188 | } | |
189 | } | |
190 | } | |
191 | } | |
192 | break ; | |
193 | } | |
194 | ||
195 | return result ; | |
196 | } | |
197 | ||
198 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler ) | |
524c47aa | 199 | #endif |
489468fe SC |
200 | |
201 | wxFontDialog::wxFontDialog() | |
202 | { | |
203 | } | |
204 | ||
d05ff890 VZ |
205 | wxFontDialog::wxFontDialog(wxWindow *parent) |
206 | { | |
207 | Create(parent); | |
208 | } | |
209 | ||
489468fe SC |
210 | wxFontDialog::wxFontDialog(wxWindow *parent, const wxFontData& data) |
211 | { | |
212 | Create(parent, data); | |
213 | } | |
214 | ||
215 | wxFontDialog::~wxFontDialog() | |
216 | { | |
217 | } | |
218 | ||
d05ff890 | 219 | bool wxFontDialog::Create(wxWindow *WXUNUSED(parent)) |
489468fe | 220 | { |
489468fe SC |
221 | return true ; |
222 | } | |
223 | ||
d05ff890 VZ |
224 | bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data) |
225 | { | |
226 | m_fontData = data; | |
227 | return Create(parent) ; | |
228 | } | |
229 | ||
489468fe SC |
230 | int wxFontDialog::ShowModal() |
231 | { | |
691745ab | 232 | WX_HOOK_MODAL_DIALOG(); |
643e9cf9 | 233 | |
524c47aa SC |
234 | #if wxOSX_USE_CARBON |
235 | ||
489468fe SC |
236 | OSStatus err ; |
237 | wxFont font = *wxNORMAL_FONT ; | |
a1b806b9 | 238 | if ( m_fontData.m_initialFont.IsOk() ) |
489468fe SC |
239 | { |
240 | font = m_fontData.m_initialFont ; | |
241 | } | |
242 | ||
243 | bool setup = false; | |
292e5e1f | 244 | #if wxOSX_USE_CORE_TEXT |
b97d6fb1 | 245 | if ( !setup ) |
489468fe | 246 | { |
aa6208d9 | 247 | CTFontDescriptorRef descr = (CTFontDescriptorRef) CTFontCopyFontDescriptor( (CTFontRef) font.OSXGetCTFont() ); |
489468fe | 248 | err = SetFontInfoForSelection (kFontSelectionCoreTextType,1, &descr , NULL); |
01548e7c | 249 | CFRelease( descr ); |
489468fe SC |
250 | setup = true; |
251 | } | |
252 | #endif | |
292e5e1f | 253 | #if wxOSX_USE_ATSU_TEXT |
489468fe SC |
254 | if ( !setup ) |
255 | { | |
256 | ATSUStyle style = (ATSUStyle)font.MacGetATSUStyle(); | |
257 | err = SetFontInfoForSelection (kFontSelectionATSUIType,1, &style , NULL); | |
258 | setup = true; | |
259 | } | |
260 | #endif | |
261 | // just clicking on ENTER will not send us any font setting event, therefore we have to make sure | |
262 | // that field is already correct | |
263 | m_fontData.m_chosenFont = font ; | |
264 | ||
265 | EventHandlerRef handler ; | |
266 | ||
267 | err = InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList), eventList, this , &handler ); | |
268 | ||
269 | if ( !FPIsFontPanelVisible() ) | |
270 | FPShowHideFontPanel(); | |
524c47aa | 271 | #endif |
445e564f | 272 | wxDialog::OSXBeginModalDialog(); |
489468fe | 273 | int retval = RunMixedFontDialog(this); |
445e564f | 274 | wxDialog::OSXEndModalDialog(); |
524c47aa | 275 | #if wxOSX_USE_CARBON |
489468fe | 276 | ::RemoveEventHandler(handler); |
524c47aa | 277 | #endif |
489468fe SC |
278 | |
279 | return retval ; | |
280 | } | |
281 | ||
282 | #else | |
283 | ||
284 | #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX | |
285 | ||
286 | #undef wxFontDialog | |
287 | ||
1f0c8f31 | 288 | #include "wx/osx/fontdlg.h" |
489468fe SC |
289 | |
290 | #include "wx/fontenum.h" | |
291 | #include "wx/colordlg.h" | |
292 | #include "wx/spinctrl.h" | |
293 | ||
294 | // --------------------------------------------------------------------------- | |
295 | // wxFontDialog stub for mac OS's without a native font dialog | |
296 | // --------------------------------------------------------------------------- | |
297 | ||
298 | static const wxChar *FontFamilyIntToString(int family); | |
299 | static int FontFamilyStringToInt(const wxChar *family); | |
300 | ||
301 | ||
302 | //----------------------------------------------------------------------------- | |
303 | // helper class - wxFontPreviewCtrl | |
304 | //----------------------------------------------------------------------------- | |
305 | ||
306 | class WXDLLEXPORT wxFontPreviewCtrl : public wxWindow | |
307 | { | |
308 | public: | |
309 | wxFontPreviewCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = 0) : | |
310 | wxWindow(parent, id, pos, sz, style) | |
311 | { | |
312 | SetBackgroundColour(*wxWHITE); | |
313 | } | |
314 | ||
315 | private: | |
316 | void OnPaint(wxPaintEvent& event); | |
317 | DECLARE_EVENT_TABLE() | |
318 | }; | |
319 | ||
320 | BEGIN_EVENT_TABLE(wxFontPreviewCtrl, wxWindow) | |
321 | EVT_PAINT(wxFontPreviewCtrl::OnPaint) | |
322 | END_EVENT_TABLE() | |
323 | ||
324 | void wxFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
325 | { | |
326 | wxPaintDC dc(this); | |
327 | ||
328 | wxSize size = GetSize(); | |
329 | wxFont font = GetFont(); | |
330 | ||
a1b806b9 | 331 | if ( font.IsOk() ) |
489468fe SC |
332 | { |
333 | dc.SetFont(font); | |
334 | // Calculate vertical centre | |
335 | long w = 0, h = 0; | |
336 | dc.GetTextExtent( wxT("X"), &w, &h); | |
337 | dc.SetTextForeground(GetForegroundColour()); | |
338 | dc.SetClippingRegion(2, 2, size.x-4, size.y-4); | |
339 | dc.DrawText(_("ABCDEFGabcdefg12345"), | |
340 | 10, size.y/2 - h/2); | |
341 | dc.DestroyClippingRegion(); | |
342 | } | |
343 | } | |
344 | ||
345 | /* | |
346 | * A control for displaying a small preview of a colour or bitmap | |
347 | */ | |
348 | ||
349 | class wxFontColourSwatchCtrl: public wxControl | |
350 | { | |
351 | DECLARE_CLASS(wxFontColourSwatchCtrl) | |
352 | public: | |
353 | wxFontColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0); | |
354 | virtual ~wxFontColourSwatchCtrl(); | |
355 | ||
356 | void OnPaint(wxPaintEvent& event); | |
357 | void OnMouseEvent(wxMouseEvent& event); | |
358 | ||
359 | void SetColour(const wxColour& colour) { m_colour = colour; SetBackgroundColour(m_colour); } | |
360 | ||
361 | wxColour& GetColour() { return m_colour; } | |
362 | ||
363 | virtual wxSize DoGetBestSize() const { return GetSize(); } | |
364 | ||
365 | protected: | |
366 | wxColour m_colour; | |
367 | ||
368 | DECLARE_EVENT_TABLE() | |
369 | }; | |
370 | ||
371 | /* | |
372 | * A control for displaying a small preview of a colour or bitmap | |
373 | */ | |
374 | ||
375 | BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl, wxControl) | |
376 | EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent) | |
377 | END_EVENT_TABLE() | |
378 | ||
379 | IMPLEMENT_CLASS(wxFontColourSwatchCtrl, wxControl) | |
380 | ||
381 | wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style): | |
382 | wxControl(parent, id, pos, size, style) | |
383 | { | |
384 | SetColour(* wxWHITE); | |
385 | SetBackgroundStyle(wxBG_STYLE_COLOUR); | |
386 | } | |
387 | ||
388 | wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl() | |
389 | { | |
390 | } | |
391 | ||
392 | void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent& event) | |
393 | { | |
394 | if (event.LeftDown()) | |
395 | { | |
396 | wxWindow* parent = GetParent(); | |
397 | while (parent != NULL && !parent->IsKindOf(CLASSINFO(wxDialog)) && !parent->IsKindOf(CLASSINFO(wxFrame))) | |
398 | parent = parent->GetParent(); | |
399 | ||
400 | wxColourData data; | |
401 | data.SetChooseFull(true); | |
402 | data.SetColour(m_colour); | |
403 | wxColourDialog *dialog = new wxColourDialog(parent, &data); | |
404 | // Crashes on wxMac (no m_peer) | |
405 | #ifndef __WXMAC__ | |
406 | dialog->SetTitle(_("Background colour")); | |
407 | #endif | |
408 | if (dialog->ShowModal() == wxID_OK) | |
409 | { | |
410 | wxColourData retData = dialog->GetColourData(); | |
411 | m_colour = retData.GetColour(); | |
412 | SetBackgroundColour(m_colour); | |
413 | } | |
414 | dialog->Destroy(); | |
415 | Refresh(); | |
416 | ||
ce7fe42e | 417 | wxCommandEvent event(wxEVT_BUTTON, GetId()); |
489468fe SC |
418 | HandleWindowEvent(event); |
419 | } | |
420 | } | |
421 | ||
422 | /*! | |
423 | * wxFontDialog type definition | |
424 | */ | |
425 | ||
426 | IMPLEMENT_DYNAMIC_CLASS( wxFontDialog, wxDialog ) | |
427 | ||
428 | /*! | |
429 | * wxFontDialog event table definition | |
430 | */ | |
431 | ||
432 | BEGIN_EVENT_TABLE( wxFontDialog, wxDialog ) | |
433 | EVT_LISTBOX( wxID_FONTDIALOG_FACENAME, wxFontDialog::OnFontdialogFacenameSelected ) | |
434 | EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE, wxFontDialog::OnFontdialogFontsizeUpdated ) | |
435 | EVT_TEXT( wxID_FONTDIALOG_FONTSIZE, wxFontDialog::OnFontdialogFontsizeTextUpdated ) | |
436 | EVT_CHECKBOX( wxID_FONTDIALOG_BOLD, wxFontDialog::OnFontdialogBoldClick ) | |
437 | EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC, wxFontDialog::OnFontdialogItalicClick ) | |
438 | EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED, wxFontDialog::OnFontdialogUnderlinedClick ) | |
439 | EVT_BUTTON( wxID_OK, wxFontDialog::OnOkClick ) | |
440 | EVT_BUTTON(wxID_FONTDIALOG_COLOUR, wxFontDialog::OnColourChanged) | |
441 | END_EVENT_TABLE() | |
442 | ||
443 | /*! | |
444 | * wxFontDialog constructors | |
445 | */ | |
446 | ||
447 | wxFontDialog::wxFontDialog( ) | |
448 | { | |
449 | m_dialogParent = NULL; | |
450 | } | |
451 | ||
452 | wxFontDialog::wxFontDialog(wxWindow* parent, const wxFontData& fontData) | |
453 | { | |
454 | m_dialogParent = NULL; | |
455 | ||
456 | Create(parent, fontData); | |
457 | } | |
458 | ||
459 | wxFontDialog::~wxFontDialog() | |
460 | { | |
461 | // empty | |
462 | } | |
463 | ||
464 | /*! | |
465 | * wxFontDialog creator | |
466 | */ | |
467 | ||
468 | bool wxFontDialog::Create(wxWindow* parent, const wxFontData& fontData) | |
469 | { | |
470 | m_fontData = fontData; | |
471 | m_suppressUpdates = false; | |
472 | ||
473 | wxString caption = _("Font"); | |
474 | ||
475 | m_facenameCtrl = NULL; | |
476 | m_sizeCtrl = NULL; | |
477 | m_boldCtrl = NULL; | |
478 | m_italicCtrl = NULL; | |
479 | m_underlinedCtrl = NULL; | |
480 | m_colourCtrl = NULL; | |
481 | m_previewCtrl = NULL; | |
482 | ||
483 | InitializeFont(); | |
484 | ||
485 | SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS); | |
486 | wxDialog::Create( parent, wxID_ANY, caption, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); | |
487 | ||
488 | CreateControls(); | |
489 | GetSizer()->Fit(this); | |
490 | GetSizer()->SetSizeHints(this); | |
491 | Centre(); | |
492 | ||
493 | return true; | |
494 | } | |
495 | ||
496 | /*! | |
497 | * Control creation for wxFontDialog | |
498 | */ | |
499 | ||
500 | void wxFontDialog::CreateControls() | |
501 | { | |
502 | wxFontDialog* itemDialog1 = this; | |
503 | ||
504 | wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); | |
505 | itemDialog1->SetSizer(itemBoxSizer2); | |
506 | ||
507 | wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL); | |
508 | itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5); | |
509 | ||
510 | wxFlexGridSizer* itemFlexGridSizer4 = new wxFlexGridSizer(6, 2, 10, 0); | |
511 | itemFlexGridSizer4->AddGrowableRow(4); | |
512 | itemFlexGridSizer4->AddGrowableCol(1); | |
513 | itemBoxSizer3->Add(itemFlexGridSizer4, 1, wxGROW|wxALL, 5); | |
514 | ||
515 | wxStaticText* itemStaticText5 = new wxStaticText( itemDialog1, wxID_STATIC, _("Font:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
516 | itemFlexGridSizer4->Add(itemStaticText5, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5); | |
517 | ||
518 | wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxVERTICAL); | |
cec9cd06 | 519 | itemFlexGridSizer4->Add(itemBoxSizer6, 0, wxGROW, 5); |
489468fe SC |
520 | |
521 | wxString* m_facenameCtrlStrings = NULL; | |
522 | m_facenameCtrl = new wxListBox( itemDialog1, wxID_FONTDIALOG_FACENAME, wxDefaultPosition, wxSize(320, 100), 0, m_facenameCtrlStrings, wxLB_SINGLE ); | |
523 | itemBoxSizer6->Add(m_facenameCtrl, 0, wxGROW|wxALL, 5); | |
524 | ||
525 | wxStaticText* itemStaticText8 = new wxStaticText( itemDialog1, wxID_STATIC, _("Size:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
526 | itemFlexGridSizer4->Add(itemStaticText8, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
527 | ||
9a83f860 | 528 | m_sizeCtrl = new wxSpinCtrl( itemDialog1, wxID_FONTDIALOG_FONTSIZE, wxT("12"), wxDefaultPosition, wxSize(60, -1), wxSP_ARROW_KEYS, 1, 300, 12 ); |
489468fe SC |
529 | m_sizeCtrl->SetHelpText(_("The font size in points.")); |
530 | if (ShowToolTips()) | |
531 | m_sizeCtrl->SetToolTip(_("The font size in points.")); | |
532 | itemFlexGridSizer4->Add(m_sizeCtrl, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
533 | ||
534 | wxStaticText* itemStaticText10 = new wxStaticText( itemDialog1, wxID_STATIC, _("Style:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
535 | itemFlexGridSizer4->Add(itemStaticText10, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
536 | ||
537 | wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxHORIZONTAL); | |
538 | itemFlexGridSizer4->Add(itemBoxSizer11, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5); | |
539 | ||
540 | m_boldCtrl = new wxCheckBox( itemDialog1, wxID_FONTDIALOG_BOLD, _("Bold"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE ); | |
541 | m_boldCtrl->SetValue(false); | |
542 | m_boldCtrl->SetHelpText(_("Check to make the font bold.")); | |
543 | if (ShowToolTips()) | |
544 | m_boldCtrl->SetToolTip(_("Check to make the font bold.")); | |
545 | itemBoxSizer11->Add(m_boldCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
546 | ||
547 | m_italicCtrl = new wxCheckBox( itemDialog1, wxID_FONTDIALOG_ITALIC, _("Italic"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE ); | |
548 | m_italicCtrl->SetValue(false); | |
549 | m_italicCtrl->SetHelpText(_("Check to make the font italic.")); | |
550 | if (ShowToolTips()) | |
551 | m_italicCtrl->SetToolTip(_("Check to make the font italic.")); | |
552 | itemBoxSizer11->Add(m_italicCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
553 | ||
554 | if (m_fontData.GetEnableEffects()) | |
555 | { | |
556 | m_underlinedCtrl = new wxCheckBox( itemDialog1, wxID_FONTDIALOG_UNDERLINED, _("Underlined"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE ); | |
557 | m_underlinedCtrl->SetValue(false); | |
558 | m_underlinedCtrl->SetHelpText(_("Check to make the font underlined.")); | |
559 | if (ShowToolTips()) | |
560 | m_underlinedCtrl->SetToolTip(_("Check to make the font underlined.")); | |
561 | itemBoxSizer11->Add(m_underlinedCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
562 | } | |
563 | ||
564 | if (m_fontData.GetEnableEffects()) | |
565 | { | |
566 | wxStaticText* itemStaticText15 = new wxStaticText( itemDialog1, wxID_STATIC, _("Colour:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
567 | itemFlexGridSizer4->Add(itemStaticText15, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5); | |
568 | ||
569 | m_colourCtrl = new wxFontColourSwatchCtrl( itemDialog1, wxID_FONTDIALOG_COLOUR, wxDefaultPosition, wxSize(-1, 30), wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); | |
570 | m_colourCtrl->SetHelpText(_("Click to change the font colour.")); | |
571 | if (ShowToolTips()) | |
572 | m_colourCtrl->SetToolTip(_("Click to change the font colour.")); | |
573 | itemFlexGridSizer4->Add(m_colourCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
574 | } | |
575 | ||
576 | wxStaticText* itemStaticText17 = new wxStaticText( itemDialog1, wxID_STATIC, _("Preview:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
577 | itemFlexGridSizer4->Add(itemStaticText17, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5); | |
578 | ||
579 | m_previewCtrl = new wxFontPreviewCtrl( itemDialog1, wxID_FONTDIALOG_PREVIEW, wxDefaultPosition, wxSize(-1, 70), wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); | |
580 | m_previewCtrl->SetHelpText(_("Shows a preview of the font.")); | |
581 | if (ShowToolTips()) | |
582 | m_previewCtrl->SetToolTip(_("Shows a preview of the font.")); | |
583 | itemFlexGridSizer4->Add(m_previewCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
584 | ||
585 | wxBoxSizer* itemBoxSizer19 = new wxBoxSizer(wxHORIZONTAL); | |
586 | itemBoxSizer3->Add(itemBoxSizer19, 0, wxALIGN_RIGHT|wxALL, 5); | |
587 | ||
588 | wxButton* itemButton20 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); | |
589 | itemButton20->SetHelpText(_("Click to cancel changes to the font.")); | |
590 | if (ShowToolTips()) | |
591 | itemButton20->SetToolTip(_("Click to cancel changes to the font.")); | |
592 | itemBoxSizer19->Add(itemButton20, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
593 | ||
594 | wxButton* itemButton21 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 ); | |
595 | itemButton21->SetDefault(); | |
596 | itemButton21->SetHelpText(_("Click to confirm changes to the font.")); | |
597 | if (ShowToolTips()) | |
598 | itemButton21->SetToolTip(_("Click to confirm changes to the font.")); | |
599 | itemBoxSizer19->Add(itemButton21, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
600 | ||
601 | wxFontEnumerator enumerator; | |
602 | enumerator.EnumerateFacenames(); | |
603 | wxArrayString facenames = enumerator.GetFacenames(); | |
e8b90482 | 604 | if (!facenames.empty()) |
489468fe SC |
605 | { |
606 | facenames.Add(_("<Any>")); | |
607 | facenames.Add(_("<Any Roman>")); | |
608 | facenames.Add(_("<Any Decorative>")); | |
609 | facenames.Add(_("<Any Modern>")); | |
610 | facenames.Add(_("<Any Script>")); | |
611 | facenames.Add(_("<Any Swiss>")); | |
612 | facenames.Add(_("<Any Teletype>")); | |
613 | facenames.Sort(); | |
614 | m_facenameCtrl->Append(facenames); | |
615 | } | |
616 | ||
617 | InitializeControls(); | |
618 | m_previewCtrl->SetFont(m_dialogFont); | |
a1b806b9 | 619 | if (m_fontData.GetColour().IsOk()) |
489468fe SC |
620 | { |
621 | m_previewCtrl->SetForegroundColour(m_fontData.GetColour()); | |
622 | } | |
623 | m_previewCtrl->Refresh(); | |
624 | } | |
625 | ||
626 | /*! | |
ce7fe42e | 627 | * wxEVT_SPINCTRL event handler for wxID_FONTDIALOG_FONTSIZE |
489468fe SC |
628 | */ |
629 | ||
630 | void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent& WXUNUSED(event) ) | |
631 | { | |
632 | ChangeFont(); | |
633 | } | |
634 | ||
635 | /*! | |
ce7fe42e | 636 | * wxEVT_TEXT event handler for wxID_FONTDIALOG_FONTSIZE |
489468fe SC |
637 | */ |
638 | ||
639 | void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent& WXUNUSED(event) ) | |
640 | { | |
641 | ChangeFont(); | |
642 | } | |
643 | ||
644 | /*! | |
ce7fe42e | 645 | * wxEVT_CHECKBOX event handler for wxID_FONTDIALOG_BOLD |
489468fe SC |
646 | */ |
647 | ||
648 | void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent& WXUNUSED(event) ) | |
649 | { | |
650 | ChangeFont(); | |
651 | } | |
652 | ||
653 | /*! | |
ce7fe42e | 654 | * wxEVT_CHECKBOX event handler for wxID_FONTDIALOG_ITALIC |
489468fe SC |
655 | */ |
656 | ||
657 | void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent& WXUNUSED(event) ) | |
658 | { | |
659 | ChangeFont(); | |
660 | } | |
661 | ||
662 | /*! | |
ce7fe42e | 663 | * wxEVT_CHECKBOX event handler for wxID_FONTDIALOG_UNDERLINED |
489468fe SC |
664 | */ |
665 | ||
666 | void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent& WXUNUSED(event) ) | |
667 | { | |
668 | ChangeFont(); | |
669 | } | |
670 | ||
671 | /*! | |
ce7fe42e | 672 | * wxEVT_BUTTON event handler for wxID_OK |
489468fe SC |
673 | */ |
674 | ||
675 | void wxFontDialog::OnOkClick( wxCommandEvent& event ) | |
676 | { | |
677 | event.Skip(); | |
678 | } | |
679 | ||
680 | ||
681 | /*! | |
ce7fe42e | 682 | * wxEVT_LISTBOX event handler for wxID_FONTDIALOG_FACENAME |
489468fe SC |
683 | */ |
684 | ||
685 | void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent& WXUNUSED(event) ) | |
686 | { | |
687 | ChangeFont(); | |
688 | } | |
689 | ||
690 | void wxFontDialog::OnColourChanged(wxCommandEvent & WXUNUSED(event)) | |
691 | { | |
692 | m_fontData.SetColour(m_colourCtrl->GetColour()); | |
693 | m_previewCtrl->SetForegroundColour(m_colourCtrl->GetColour()); | |
694 | m_previewCtrl->Refresh(); | |
695 | } | |
696 | ||
697 | /*! | |
698 | * Should we show tooltips? | |
699 | */ | |
700 | ||
701 | bool wxFontDialog::ShowToolTips() | |
702 | { | |
703 | return true; | |
704 | } | |
705 | ||
706 | void wxFontDialog::InitializeFont() | |
707 | { | |
708 | int fontFamily = wxSWISS; | |
709 | int fontWeight = wxNORMAL; | |
710 | int fontStyle = wxNORMAL; | |
711 | int fontSize = 12; | |
712 | bool fontUnderline = false; | |
713 | wxString fontName; | |
714 | ||
a1b806b9 | 715 | if (m_fontData.m_initialFont.IsOk()) |
489468fe SC |
716 | { |
717 | fontFamily = m_fontData.m_initialFont.GetFamily(); | |
718 | fontWeight = m_fontData.m_initialFont.GetWeight(); | |
719 | fontStyle = m_fontData.m_initialFont.GetStyle(); | |
720 | fontSize = m_fontData.m_initialFont.GetPointSize(); | |
721 | fontUnderline = m_fontData.m_initialFont.GetUnderlined(); | |
722 | fontName = m_fontData.m_initialFont.GetFaceName(); | |
723 | } | |
724 | ||
725 | m_dialogFont = wxFont(fontSize, fontFamily, fontStyle, | |
726 | fontWeight, fontUnderline, fontName); | |
727 | ||
728 | if (m_previewCtrl) | |
729 | m_previewCtrl->SetFont(m_dialogFont); | |
730 | ||
731 | m_fontData.SetChosenFont(m_dialogFont); | |
732 | } | |
733 | ||
734 | /// Set controls according to current font | |
735 | void wxFontDialog::InitializeControls() | |
736 | { | |
737 | m_suppressUpdates = true; | |
738 | ||
739 | if (m_underlinedCtrl) | |
740 | m_underlinedCtrl->SetValue(m_dialogFont.GetUnderlined()); | |
741 | ||
742 | m_boldCtrl->SetValue(m_dialogFont.GetWeight() == wxBOLD); | |
743 | m_italicCtrl->SetValue(m_dialogFont.GetStyle() == wxITALIC); | |
744 | m_sizeCtrl->SetValue(m_dialogFont.GetPointSize()); | |
745 | ||
746 | wxString facename = m_dialogFont.GetFaceName(); | |
747 | if (facename.empty() || m_facenameCtrl->FindString(facename) == wxNOT_FOUND) | |
748 | { | |
749 | facename = FontFamilyIntToString(m_dialogFont.GetFamily()); | |
750 | } | |
751 | m_facenameCtrl->SetStringSelection(facename); | |
752 | ||
a1b806b9 | 753 | if (m_colourCtrl && m_fontData.GetColour().IsOk()) |
489468fe SC |
754 | { |
755 | m_colourCtrl->SetColour(m_fontData.GetColour()); | |
756 | m_colourCtrl->Refresh(); | |
757 | } | |
758 | ||
759 | m_suppressUpdates = false; | |
760 | } | |
761 | ||
762 | /// Respond to font change | |
763 | void wxFontDialog::ChangeFont() | |
764 | { | |
765 | if (m_suppressUpdates) | |
766 | return; | |
767 | ||
768 | bool underlined = m_underlinedCtrl ? m_underlinedCtrl->GetValue() : false; | |
769 | bool italic = m_italicCtrl->GetValue(); | |
770 | bool bold = m_boldCtrl->GetValue(); | |
771 | int size = m_sizeCtrl->GetValue(); | |
772 | wxString facename = m_facenameCtrl->GetStringSelection(); | |
773 | ||
774 | int family = FontFamilyStringToInt(facename); | |
775 | if (family == -1) | |
776 | family = wxDEFAULT; | |
777 | else | |
778 | facename = wxEmptyString; | |
779 | ||
780 | m_dialogFont = wxFont(size, family, italic ? wxITALIC : wxNORMAL, bold ? wxBOLD : wxNORMAL, | |
781 | underlined, facename); | |
782 | ||
783 | m_fontData.SetChosenFont(m_dialogFont); | |
784 | ||
785 | m_previewCtrl->SetFont(m_dialogFont); | |
786 | m_previewCtrl->Refresh(); | |
787 | } | |
788 | ||
789 | void wxFontDialog::SetData(const wxFontData& fontdata) | |
790 | { | |
791 | m_fontData = fontdata; | |
792 | } | |
793 | ||
794 | bool wxFontDialog::IsShown() const | |
795 | { | |
796 | return false; | |
797 | } | |
798 | ||
799 | int wxFontDialog::ShowModal() | |
800 | { | |
801 | return wxDialog::ShowModal(); | |
802 | } | |
803 | ||
804 | void wxFontDialog::OnPanelClose() | |
805 | { | |
806 | } | |
807 | ||
808 | const wxChar *FontFamilyIntToString(int family) | |
809 | { | |
810 | switch (family) | |
811 | { | |
812 | case wxROMAN: | |
813 | return _("<Any Roman>"); | |
814 | case wxDECORATIVE: | |
815 | return _("<Any Decorative>"); | |
816 | case wxMODERN: | |
817 | return _("<Any Modern>"); | |
818 | case wxSCRIPT: | |
819 | return _("<Any Script>"); | |
820 | case wxTELETYPE: | |
821 | return _("<Any Teletype>"); | |
822 | case wxSWISS: | |
823 | default: | |
824 | return _("<Any Swiss>"); | |
825 | } | |
826 | } | |
827 | ||
828 | int FontFamilyStringToInt(const wxChar *family) | |
829 | { | |
830 | if (!family) | |
831 | return wxSWISS; | |
832 | ||
833 | if (wxStrcmp(family, _("<Any Roman>")) == 0) | |
834 | return wxROMAN; | |
835 | else if (wxStrcmp(family, _("<Any Decorative>")) == 0) | |
836 | return wxDECORATIVE; | |
837 | else if (wxStrcmp(family, _("<Any Modern>")) == 0) | |
838 | return wxMODERN; | |
839 | else if (wxStrcmp(family, _("<Any Script>")) == 0) | |
840 | return wxSCRIPT; | |
841 | else if (wxStrcmp(family, _("<Any Teletype>")) == 0) | |
842 | return wxTELETYPE; | |
843 | else if (wxStrcmp(family, _("<Any Swiss>")) == 0) | |
844 | return wxSWISS; | |
845 | else return -1; | |
846 | } | |
847 | ||
848 | #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX | |
849 | ||
292e5e1f | 850 | #endif // wxOSX_USE_EXPERIMENTAL_FONTDIALOG |
489468fe SC |
851 | |
852 | #endif // wxUSE_FONTDLG |