1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/fontdlg.cpp
3 // Purpose: wxFontDialog class for carbon 10.2+.
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
32 #include "wx/dcclient.h"
34 #include "wx/textctrl.h"
35 #include "wx/listbox.h"
36 #include "wx/checkbox.h"
37 #include "wx/choice.h"
39 #include "wx/stattext.h"
40 #include "wx/button.h"
43 #include "wx/fontdlg.h"
44 #include "wx/fontutil.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
80 if ( UMAGetSystemVersion() >= 0x1050 )
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
, const wxFontData
& data
)
207 Create(parent
, data
);
210 wxFontDialog::~wxFontDialog()
214 bool wxFontDialog::Create(wxWindow
*WXUNUSED(parent
), const wxFontData
& data
)
220 int wxFontDialog::ShowModal()
225 wxFont font
= *wxNORMAL_FONT
;
226 if ( m_fontData
.m_initialFont
.Ok() )
228 font
= m_fontData
.m_initialFont
;
232 #if wxOSX_USE_CORE_TEXT
233 if ( UMAGetSystemVersion() >= 0x1050 )
235 CTFontDescriptorRef descr
= (CTFontDescriptorRef
) CTFontCopyFontDescriptor( (CTFontRef
) font
.OSXGetCTFont() );
236 err
= SetFontInfoForSelection (kFontSelectionCoreTextType
,1, &descr
, NULL
);
241 #if wxOSX_USE_ATSU_TEXT
244 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
245 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
249 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
250 // that field is already correct
251 m_fontData
.m_chosenFont
= font
;
253 EventHandlerRef handler
;
255 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
257 if ( !FPIsFontPanelVisible() )
258 FPShowHideFontPanel();
260 int retval
= RunMixedFontDialog(this);
263 ::RemoveEventHandler(handler
);
271 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
275 #include "wx/osx/fontdlg.h"
277 #include "wx/fontenum.h"
278 #include "wx/colordlg.h"
279 #include "wx/spinctrl.h"
281 // ---------------------------------------------------------------------------
282 // wxFontDialog stub for mac OS's without a native font dialog
283 // ---------------------------------------------------------------------------
285 static const wxChar
*FontFamilyIntToString(int family
);
286 static int FontFamilyStringToInt(const wxChar
*family
);
289 //-----------------------------------------------------------------------------
290 // helper class - wxFontPreviewCtrl
291 //-----------------------------------------------------------------------------
293 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
296 wxFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
297 wxWindow(parent
, id
, pos
, sz
, style
)
299 SetBackgroundColour(*wxWHITE
);
303 void OnPaint(wxPaintEvent
& event
);
304 DECLARE_EVENT_TABLE()
307 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
308 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
311 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
315 wxSize size
= GetSize();
316 wxFont font
= GetFont();
321 // Calculate vertical centre
323 dc
.GetTextExtent( wxT("X"), &w
, &h
);
324 dc
.SetTextForeground(GetForegroundColour());
325 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
326 dc
.DrawText(_("ABCDEFGabcdefg12345"),
328 dc
.DestroyClippingRegion();
333 * A control for displaying a small preview of a colour or bitmap
336 class wxFontColourSwatchCtrl
: public wxControl
338 DECLARE_CLASS(wxFontColourSwatchCtrl
)
340 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
341 virtual ~wxFontColourSwatchCtrl();
343 void OnPaint(wxPaintEvent
& event
);
344 void OnMouseEvent(wxMouseEvent
& event
);
346 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
348 wxColour
& GetColour() { return m_colour
; }
350 virtual wxSize
DoGetBestSize() const { return GetSize(); }
355 DECLARE_EVENT_TABLE()
359 * A control for displaying a small preview of a colour or bitmap
362 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
363 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
366 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
368 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
369 wxControl(parent
, id
, pos
, size
, style
)
371 SetColour(* wxWHITE
);
372 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
375 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
379 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
381 if (event
.LeftDown())
383 wxWindow
* parent
= GetParent();
384 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
385 parent
= parent
->GetParent();
388 data
.SetChooseFull(true);
389 data
.SetColour(m_colour
);
390 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
391 // Crashes on wxMac (no m_peer)
393 dialog
->SetTitle(_("Background colour"));
395 if (dialog
->ShowModal() == wxID_OK
)
397 wxColourData retData
= dialog
->GetColourData();
398 m_colour
= retData
.GetColour();
399 SetBackgroundColour(m_colour
);
404 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
405 HandleWindowEvent(event
);
410 * wxFontDialog type definition
413 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
416 * wxFontDialog event table definition
419 BEGIN_EVENT_TABLE( wxFontDialog
, wxDialog
)
420 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME
, wxFontDialog::OnFontdialogFacenameSelected
)
421 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeUpdated
)
422 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeTextUpdated
)
423 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD
, wxFontDialog::OnFontdialogBoldClick
)
424 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC
, wxFontDialog::OnFontdialogItalicClick
)
425 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED
, wxFontDialog::OnFontdialogUnderlinedClick
)
426 EVT_BUTTON( wxID_OK
, wxFontDialog::OnOkClick
)
427 EVT_BUTTON(wxID_FONTDIALOG_COLOUR
, wxFontDialog::OnColourChanged
)
431 * wxFontDialog constructors
434 wxFontDialog::wxFontDialog( )
436 m_dialogParent
= NULL
;
439 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
441 m_dialogParent
= NULL
;
443 Create(parent
, fontData
);
446 wxFontDialog::~wxFontDialog()
452 * wxFontDialog creator
455 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
457 m_fontData
= fontData
;
458 m_suppressUpdates
= false;
460 wxString caption
= _("Font");
462 m_facenameCtrl
= NULL
;
466 m_underlinedCtrl
= NULL
;
468 m_previewCtrl
= NULL
;
472 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
473 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
476 GetSizer()->Fit(this);
477 GetSizer()->SetSizeHints(this);
484 * Control creation for wxFontDialog
487 void wxFontDialog::CreateControls()
489 wxFontDialog
* itemDialog1
= this;
491 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
492 itemDialog1
->SetSizer(itemBoxSizer2
);
494 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
495 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
497 wxFlexGridSizer
* itemFlexGridSizer4
= new wxFlexGridSizer(6, 2, 10, 0);
498 itemFlexGridSizer4
->AddGrowableRow(4);
499 itemFlexGridSizer4
->AddGrowableCol(1);
500 itemBoxSizer3
->Add(itemFlexGridSizer4
, 1, wxGROW
|wxALL
, 5);
502 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
503 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
505 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
506 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
|wxGROW
, 5);
508 wxString
* m_facenameCtrlStrings
= NULL
;
509 m_facenameCtrl
= new wxListBox( itemDialog1
, wxID_FONTDIALOG_FACENAME
, wxDefaultPosition
, wxSize(320, 100), 0, m_facenameCtrlStrings
, wxLB_SINGLE
);
510 itemBoxSizer6
->Add(m_facenameCtrl
, 0, wxGROW
|wxALL
, 5);
512 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
513 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
515 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, _T("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
516 m_sizeCtrl
->SetHelpText(_("The font size in points."));
518 m_sizeCtrl
->SetToolTip(_("The font size in points."));
519 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
521 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
522 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
524 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
525 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
527 m_boldCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_BOLD
, _("Bold"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
528 m_boldCtrl
->SetValue(false);
529 m_boldCtrl
->SetHelpText(_("Check to make the font bold."));
531 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
532 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
534 m_italicCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_ITALIC
, _("Italic"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
535 m_italicCtrl
->SetValue(false);
536 m_italicCtrl
->SetHelpText(_("Check to make the font italic."));
538 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
539 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
541 if (m_fontData
.GetEnableEffects())
543 m_underlinedCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_UNDERLINED
, _("Underlined"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
544 m_underlinedCtrl
->SetValue(false);
545 m_underlinedCtrl
->SetHelpText(_("Check to make the font underlined."));
547 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
548 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
551 if (m_fontData
.GetEnableEffects())
553 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
554 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
556 m_colourCtrl
= new wxFontColourSwatchCtrl( itemDialog1
, wxID_FONTDIALOG_COLOUR
, wxDefaultPosition
, wxSize(-1, 30), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
557 m_colourCtrl
->SetHelpText(_("Click to change the font colour."));
559 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
560 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
563 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
564 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
566 m_previewCtrl
= new wxFontPreviewCtrl( itemDialog1
, wxID_FONTDIALOG_PREVIEW
, wxDefaultPosition
, wxSize(-1, 70), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
567 m_previewCtrl
->SetHelpText(_("Shows a preview of the font."));
569 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
570 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
572 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
573 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
575 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
576 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
578 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
579 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
581 wxButton
* itemButton21
= new wxButton( itemDialog1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
582 itemButton21
->SetDefault();
583 itemButton21
->SetHelpText(_("Click to confirm changes to the font."));
585 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
586 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
588 wxFontEnumerator enumerator
;
589 enumerator
.EnumerateFacenames();
590 wxArrayString facenames
= enumerator
.GetFacenames();
593 facenames
.Add(_("<Any>"));
594 facenames
.Add(_("<Any Roman>"));
595 facenames
.Add(_("<Any Decorative>"));
596 facenames
.Add(_("<Any Modern>"));
597 facenames
.Add(_("<Any Script>"));
598 facenames
.Add(_("<Any Swiss>"));
599 facenames
.Add(_("<Any Teletype>"));
601 m_facenameCtrl
->Append(facenames
);
604 InitializeControls();
605 m_previewCtrl
->SetFont(m_dialogFont
);
606 if (m_fontData
.GetColour().Ok())
608 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
610 m_previewCtrl
->Refresh();
614 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
617 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
623 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
626 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
632 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
635 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
641 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
644 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
650 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
653 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
659 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
662 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
669 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
672 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
677 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
679 m_fontData
.SetColour(m_colourCtrl
->GetColour());
680 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
681 m_previewCtrl
->Refresh();
685 * Should we show tooltips?
688 bool wxFontDialog::ShowToolTips()
693 void wxFontDialog::InitializeFont()
695 int fontFamily
= wxSWISS
;
696 int fontWeight
= wxNORMAL
;
697 int fontStyle
= wxNORMAL
;
699 bool fontUnderline
= false;
702 if (m_fontData
.m_initialFont
.Ok())
704 fontFamily
= m_fontData
.m_initialFont
.GetFamily();
705 fontWeight
= m_fontData
.m_initialFont
.GetWeight();
706 fontStyle
= m_fontData
.m_initialFont
.GetStyle();
707 fontSize
= m_fontData
.m_initialFont
.GetPointSize();
708 fontUnderline
= m_fontData
.m_initialFont
.GetUnderlined();
709 fontName
= m_fontData
.m_initialFont
.GetFaceName();
712 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
713 fontWeight
, fontUnderline
, fontName
);
716 m_previewCtrl
->SetFont(m_dialogFont
);
718 m_fontData
.SetChosenFont(m_dialogFont
);
721 /// Set controls according to current font
722 void wxFontDialog::InitializeControls()
724 m_suppressUpdates
= true;
726 if (m_underlinedCtrl
)
727 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
729 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
730 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
731 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
733 wxString facename
= m_dialogFont
.GetFaceName();
734 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
736 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
738 m_facenameCtrl
->SetStringSelection(facename
);
740 if (m_colourCtrl
&& m_fontData
.GetColour().Ok())
742 m_colourCtrl
->SetColour(m_fontData
.GetColour());
743 m_colourCtrl
->Refresh();
746 m_suppressUpdates
= false;
749 /// Respond to font change
750 void wxFontDialog::ChangeFont()
752 if (m_suppressUpdates
)
755 bool underlined
= m_underlinedCtrl
? m_underlinedCtrl
->GetValue() : false;
756 bool italic
= m_italicCtrl
->GetValue();
757 bool bold
= m_boldCtrl
->GetValue();
758 int size
= m_sizeCtrl
->GetValue();
759 wxString facename
= m_facenameCtrl
->GetStringSelection();
761 int family
= FontFamilyStringToInt(facename
);
765 facename
= wxEmptyString
;
767 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
768 underlined
, facename
);
770 m_fontData
.SetChosenFont(m_dialogFont
);
772 m_previewCtrl
->SetFont(m_dialogFont
);
773 m_previewCtrl
->Refresh();
776 void wxFontDialog::SetData(const wxFontData
& fontdata
)
778 m_fontData
= fontdata
;
781 bool wxFontDialog::IsShown() const
786 int wxFontDialog::ShowModal()
788 return wxDialog::ShowModal();
791 void wxFontDialog::OnPanelClose()
795 const wxChar
*FontFamilyIntToString(int family
)
800 return _("<Any Roman>");
802 return _("<Any Decorative>");
804 return _("<Any Modern>");
806 return _("<Any Script>");
808 return _("<Any Teletype>");
811 return _("<Any Swiss>");
815 int FontFamilyStringToInt(const wxChar
*family
)
820 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
822 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
824 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
826 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
828 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
830 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
835 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
837 #endif // wxOSX_USE_EXPERIMENTAL_FONTDIALOG
839 #endif // wxUSE_FONTDLG