1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/fontdlg.cpp
3 // Purpose: wxFontDialog class for carbon 10.2+.
7 // Copyright: (c) Ryan Norton
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
31 #include "wx/dcclient.h"
33 #include "wx/textctrl.h"
34 #include "wx/listbox.h"
35 #include "wx/checkbox.h"
36 #include "wx/choice.h"
38 #include "wx/stattext.h"
39 #include "wx/button.h"
42 #include "wx/fontdlg.h"
43 #include "wx/fontutil.h"
44 #include "wx/modalhook.h"
46 #if wxOSX_USE_EXPERIMENTAL_FONTDIALOG
48 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
50 #include "wx/osx/private.h"
52 // ---------------------------------------------------------------------------
54 // ---------------------------------------------------------------------------
58 static const EventTypeSpec eventList
[] =
60 { kEventClassFont
, kEventFontSelection
} ,
65 wxMacCarbonFontPanelHandler(EventHandlerCallRef
WXUNUSED(nextHandler
),
69 OSStatus result
= eventNotHandledErr
;
70 wxFontDialog
*fontdialog
= (wxFontDialog
*) userData
;
71 wxFontData
& fontdata
= fontdialog
->GetFontData() ;
73 wxMacCarbonEvent
cEvent( event
);
74 switch(cEvent
.GetKind())
76 case kEventFontSelection
:
79 #if wxOSX_USE_CORE_TEXT
82 CTFontDescriptorRef descr
;
83 if ( cEvent
.GetParameter
<CTFontDescriptorRef
>( kEventParamCTFontDescriptor
, typeCTFontDescriptorRef
, &descr
) == noErr
)
86 wxNativeFontInfo fontinfo
;
88 font
.Create(fontinfo
);
89 fontdata
.SetChosenFont( font
) ;
94 #if wxOSX_USE_ATSU_TEXT
95 ATSUFontID fontId
= 0 ;
96 if ( !setup
&& (cEvent
.GetParameter
<ATSUFontID
>(kEventParamATSUFontID
, &fontId
) == noErr
) )
98 FMFontStyle fontStyle
= cEvent
.GetParameter
<FMFontStyle
>(kEventParamFMFontStyle
);
99 FMFontSize fontSize
= cEvent
.GetParameter
<FMFontSize
>(kEventParamFMFontSize
);
101 CFStringRef cfName
= NULL
;
103 FMFontFamily fontFamily
= cEvent
.GetParameter
<FMFontFamily
>(kEventParamFMFontFamily
);
104 ATSFontFamilyRef atsfontfamilyref
= FMGetATSFontFamilyRefFromFontFamily( fontFamily
) ;
105 OSStatus err
= ATSFontFamilyGetName( atsfontfamilyref
, kATSOptionFlagsDefault
, &cfName
) ;
108 wxFAIL_MSG("ATSFontFamilyGetName failed");
111 // we don't use the ATSU naming anymore
112 ByteCount actualLength
= 0;
114 OSStatus err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
115 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
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);
126 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
127 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
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
);
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
);
150 #endif // wxOSX_USE_ATSU_TEXT
152 // retrieving the color
154 if ( cEvent
.GetParameter
<RGBColor
>(kEventParamFontColor
, &fontColor
) == noErr
)
156 fontdata
.m_fontColour
= fontColor
;
160 CFDictionaryRef dict
;
161 if ( cEvent
.GetParameter
<CFDictionaryRef
>(kEventParamDictionary
, &dict
) == noErr
)
163 CFDictionaryRef attributesDict
;
164 if ( CFDictionaryGetValueIfPresent(dict
, kFontPanelAttributesKey
, (const void **)&attributesDict
) )
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
) )
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
)
180 if ( tagPtr
[i
] == kATSUColorTag
&& sizePtr
[i
] == sizeof(RGBColor
))
182 fontdata
.m_fontColour
= *(RGBColor
*)valuesPtr
;
185 bytePtr
= (UInt32
*)( (UInt8
*)bytePtr
+ sizePtr
[i
]);
198 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler
)
201 wxFontDialog::wxFontDialog()
205 wxFontDialog::wxFontDialog(wxWindow
*parent
)
210 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
212 Create(parent
, data
);
215 wxFontDialog::~wxFontDialog()
219 bool wxFontDialog::Create(wxWindow
*WXUNUSED(parent
))
224 bool wxFontDialog::Create(wxWindow
*parent
, const wxFontData
& data
)
227 return Create(parent
) ;
230 int wxFontDialog::ShowModal()
232 WX_HOOK_MODAL_DIALOG();
237 wxFont font
= *wxNORMAL_FONT
;
238 if ( m_fontData
.m_initialFont
.IsOk() )
240 font
= m_fontData
.m_initialFont
;
244 #if wxOSX_USE_CORE_TEXT
247 CTFontDescriptorRef descr
= (CTFontDescriptorRef
) CTFontCopyFontDescriptor( (CTFontRef
) font
.OSXGetCTFont() );
248 err
= SetFontInfoForSelection (kFontSelectionCoreTextType
,1, &descr
, NULL
);
253 #if wxOSX_USE_ATSU_TEXT
256 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
257 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
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
;
265 EventHandlerRef handler
;
267 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
269 if ( !FPIsFontPanelVisible() )
270 FPShowHideFontPanel();
272 wxDialog::OSXBeginModalDialog();
273 int retval
= RunMixedFontDialog(this);
274 wxDialog::OSXEndModalDialog();
276 ::RemoveEventHandler(handler
);
284 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
288 #include "wx/osx/fontdlg.h"
290 #include "wx/fontenum.h"
291 #include "wx/colordlg.h"
292 #include "wx/spinctrl.h"
294 // ---------------------------------------------------------------------------
295 // wxFontDialog stub for mac OS's without a native font dialog
296 // ---------------------------------------------------------------------------
298 static const wxChar
*FontFamilyIntToString(int family
);
299 static int FontFamilyStringToInt(const wxChar
*family
);
302 //-----------------------------------------------------------------------------
303 // helper class - wxFontPreviewCtrl
304 //-----------------------------------------------------------------------------
306 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
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
)
312 SetBackgroundColour(*wxWHITE
);
316 void OnPaint(wxPaintEvent
& event
);
317 DECLARE_EVENT_TABLE()
320 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
321 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
324 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
328 wxSize size
= GetSize();
329 wxFont font
= GetFont();
334 // Calculate vertical centre
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"),
341 dc
.DestroyClippingRegion();
346 * A control for displaying a small preview of a colour or bitmap
349 class wxFontColourSwatchCtrl
: public wxControl
351 DECLARE_CLASS(wxFontColourSwatchCtrl
)
353 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
354 virtual ~wxFontColourSwatchCtrl();
356 void OnPaint(wxPaintEvent
& event
);
357 void OnMouseEvent(wxMouseEvent
& event
);
359 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
361 wxColour
& GetColour() { return m_colour
; }
363 virtual wxSize
DoGetBestSize() const { return GetSize(); }
368 DECLARE_EVENT_TABLE()
372 * A control for displaying a small preview of a colour or bitmap
375 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
376 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
379 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
381 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
382 wxControl(parent
, id
, pos
, size
, style
)
384 SetColour(* wxWHITE
);
385 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
388 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
392 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
394 if (event
.LeftDown())
396 wxWindow
* parent
= GetParent();
397 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
398 parent
= parent
->GetParent();
401 data
.SetChooseFull(true);
402 data
.SetColour(m_colour
);
403 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
404 // Crashes on wxMac (no m_peer)
406 dialog
->SetTitle(_("Background colour"));
408 if (dialog
->ShowModal() == wxID_OK
)
410 wxColourData retData
= dialog
->GetColourData();
411 m_colour
= retData
.GetColour();
412 SetBackgroundColour(m_colour
);
417 wxCommandEvent
event(wxEVT_BUTTON
, GetId());
418 HandleWindowEvent(event
);
423 * wxFontDialog type definition
426 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
429 * wxFontDialog event table definition
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
)
444 * wxFontDialog constructors
447 wxFontDialog::wxFontDialog( )
449 m_dialogParent
= NULL
;
452 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
454 m_dialogParent
= NULL
;
456 Create(parent
, fontData
);
459 wxFontDialog::~wxFontDialog()
465 * wxFontDialog creator
468 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
470 m_fontData
= fontData
;
471 m_suppressUpdates
= false;
473 wxString caption
= _("Font");
475 m_facenameCtrl
= NULL
;
479 m_underlinedCtrl
= NULL
;
481 m_previewCtrl
= NULL
;
485 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
486 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
489 GetSizer()->Fit(this);
490 GetSizer()->SetSizeHints(this);
497 * Control creation for wxFontDialog
500 void wxFontDialog::CreateControls()
502 wxFontDialog
* itemDialog1
= this;
504 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
505 itemDialog1
->SetSizer(itemBoxSizer2
);
507 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
508 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
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);
515 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
516 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
518 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
519 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
, 5);
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);
525 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
526 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
528 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, wxT("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
529 m_sizeCtrl
->SetHelpText(_("The font size in points."));
531 m_sizeCtrl
->SetToolTip(_("The font size in points."));
532 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
534 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
535 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
537 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
538 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
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."));
544 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
545 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
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."));
551 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
552 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
554 if (m_fontData
.GetEnableEffects())
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."));
560 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
561 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
564 if (m_fontData
.GetEnableEffects())
566 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
567 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
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."));
572 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
573 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
576 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
577 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
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."));
582 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
583 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
585 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
586 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
588 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
589 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
591 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
592 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
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."));
598 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
599 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
601 wxFontEnumerator enumerator
;
602 enumerator
.EnumerateFacenames();
603 wxArrayString facenames
= enumerator
.GetFacenames();
604 if (!facenames
.empty())
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>"));
614 m_facenameCtrl
->Append(facenames
);
617 InitializeControls();
618 m_previewCtrl
->SetFont(m_dialogFont
);
619 if (m_fontData
.GetColour().IsOk())
621 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
623 m_previewCtrl
->Refresh();
627 * wxEVT_SPINCTRL event handler for wxID_FONTDIALOG_FONTSIZE
630 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
636 * wxEVT_TEXT event handler for wxID_FONTDIALOG_FONTSIZE
639 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
645 * wxEVT_CHECKBOX event handler for wxID_FONTDIALOG_BOLD
648 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
654 * wxEVT_CHECKBOX event handler for wxID_FONTDIALOG_ITALIC
657 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
663 * wxEVT_CHECKBOX event handler for wxID_FONTDIALOG_UNDERLINED
666 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
672 * wxEVT_BUTTON event handler for wxID_OK
675 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
682 * wxEVT_LISTBOX event handler for wxID_FONTDIALOG_FACENAME
685 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
690 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
692 m_fontData
.SetColour(m_colourCtrl
->GetColour());
693 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
694 m_previewCtrl
->Refresh();
698 * Should we show tooltips?
701 bool wxFontDialog::ShowToolTips()
706 void wxFontDialog::InitializeFont()
708 int fontFamily
= wxSWISS
;
709 int fontWeight
= wxNORMAL
;
710 int fontStyle
= wxNORMAL
;
712 bool fontUnderline
= false;
715 if (m_fontData
.m_initialFont
.IsOk())
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();
725 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
726 fontWeight
, fontUnderline
, fontName
);
729 m_previewCtrl
->SetFont(m_dialogFont
);
731 m_fontData
.SetChosenFont(m_dialogFont
);
734 /// Set controls according to current font
735 void wxFontDialog::InitializeControls()
737 m_suppressUpdates
= true;
739 if (m_underlinedCtrl
)
740 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
742 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
743 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
744 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
746 wxString facename
= m_dialogFont
.GetFaceName();
747 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
749 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
751 m_facenameCtrl
->SetStringSelection(facename
);
753 if (m_colourCtrl
&& m_fontData
.GetColour().IsOk())
755 m_colourCtrl
->SetColour(m_fontData
.GetColour());
756 m_colourCtrl
->Refresh();
759 m_suppressUpdates
= false;
762 /// Respond to font change
763 void wxFontDialog::ChangeFont()
765 if (m_suppressUpdates
)
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();
774 int family
= FontFamilyStringToInt(facename
);
778 facename
= wxEmptyString
;
780 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
781 underlined
, facename
);
783 m_fontData
.SetChosenFont(m_dialogFont
);
785 m_previewCtrl
->SetFont(m_dialogFont
);
786 m_previewCtrl
->Refresh();
789 void wxFontDialog::SetData(const wxFontData
& fontdata
)
791 m_fontData
= fontdata
;
794 bool wxFontDialog::IsShown() const
799 int wxFontDialog::ShowModal()
801 return wxDialog::ShowModal();
804 void wxFontDialog::OnPanelClose()
808 const wxChar
*FontFamilyIntToString(int family
)
813 return _("<Any Roman>");
815 return _("<Any Decorative>");
817 return _("<Any Modern>");
819 return _("<Any Script>");
821 return _("<Any Teletype>");
824 return _("<Any Swiss>");
828 int FontFamilyStringToInt(const wxChar
*family
)
833 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
835 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
837 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
839 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
841 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
843 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
848 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
850 #endif // wxOSX_USE_EXPERIMENTAL_FONTDIALOG
852 #endif // wxUSE_FONTDLG