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