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"
45 #if wxOSX_USE_EXPERIMENTAL_FONTDIALOG
47 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
49 #include "wx/osx/private.h"
51 // ---------------------------------------------------------------------------
53 // ---------------------------------------------------------------------------
57 static const EventTypeSpec eventList
[] =
59 { kEventClassFont
, kEventFontSelection
} ,
64 wxMacCarbonFontPanelHandler(EventHandlerCallRef
WXUNUSED(nextHandler
),
68 OSStatus result
= eventNotHandledErr
;
69 wxFontDialog
*fontdialog
= (wxFontDialog
*) userData
;
70 wxFontData
& fontdata
= fontdialog
->GetFontData() ;
72 wxMacCarbonEvent
cEvent( event
);
73 switch(cEvent
.GetKind())
75 case kEventFontSelection
:
78 #if wxOSX_USE_CORE_TEXT
79 if ( UMAGetSystemVersion() >= 0x1050 )
81 CTFontDescriptorRef descr
;
82 if ( cEvent
.GetParameter
<CTFontDescriptorRef
>( kEventParamCTFontDescriptor
, typeCTFontDescriptorRef
, &descr
) == noErr
)
85 font
.MacCreateFromCTFontDescriptor(descr
);
86 fontdata
.SetChosenFont( font
) ;
91 #if wxOSX_USE_ATSU_TEXT
92 ATSUFontID fontId
= 0 ;
93 if ( !setup
&& (cEvent
.GetParameter
<ATSUFontID
>(kEventParamATSUFontID
, &fontId
) == noErr
) )
95 FMFontStyle fontStyle
= cEvent
.GetParameter
<FMFontStyle
>(kEventParamFMFontStyle
);
96 FMFontSize fontSize
= cEvent
.GetParameter
<FMFontSize
>(kEventParamFMFontSize
);
98 CFStringRef cfName
= NULL
;
100 FMFontFamily fontFamily
= cEvent
.GetParameter
<FMFontFamily
>(kEventParamFMFontFamily
);
101 ATSFontFamilyRef atsfontfamilyref
= FMGetATSFontFamilyRefFromFontFamily( fontFamily
) ;
102 OSStatus err
= ATSFontFamilyGetName( atsfontfamilyref
, kATSOptionFlagsDefault
, &cfName
) ;
105 wxFAIL_MSG("ATSFontFamilyGetName failed");
108 // we don't use the ATSU naming anymore
109 ByteCount actualLength
= 0;
111 OSStatus err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
112 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
116 char *c
= (char*)malloc( actualLength
);
117 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
118 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
119 cfName
= CFStringCreateWithCharacters(NULL
, (UniChar
*) c
, (actualLength
-1) >> 1);
123 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
124 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
128 c
= (char*)malloc(actualLength
);
129 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
130 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
131 c
[actualLength
-1] = 0;
132 cfName
= CFStringCreateWithCString(NULL
, c
, kCFStringEncodingMacRoman
);
140 fontdata
.m_chosenFont
.SetFaceName(wxCFStringRef(cfName
).AsString(wxLocale::GetSystemEncoding()));
141 fontdata
.m_chosenFont
.SetPointSize(fontSize
);
142 fontdata
.m_chosenFont
.SetStyle(fontStyle
& italic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
);
143 fontdata
.m_chosenFont
.SetUnderlined((fontStyle
& underline
)!=0);
144 fontdata
.m_chosenFont
.SetWeight(fontStyle
& bold
? wxFONTWEIGHT_BOLD
: wxFONTWEIGHT_NORMAL
);
147 #endif // wxOSX_USE_ATSU_TEXT
149 // retrieving the color
151 if ( cEvent
.GetParameter
<RGBColor
>(kEventParamFontColor
, &fontColor
) == noErr
)
153 fontdata
.m_fontColour
= fontColor
;
157 CFDictionaryRef dict
;
158 if ( cEvent
.GetParameter
<CFDictionaryRef
>(kEventParamDictionary
, &dict
) == noErr
)
160 CFDictionaryRef attributesDict
;
161 if ( CFDictionaryGetValueIfPresent(dict
, kFontPanelAttributesKey
, (const void **)&attributesDict
) )
165 CFDataRef valuesData
;
166 if ( CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeTagsKey
, (const void **)&tagsData
) &&
167 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeSizesKey
, (const void **)&sizesData
) &&
168 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeValuesKey
, (const void **)&valuesData
) )
170 ItemCount count
= CFDataGetLength(tagsData
)/sizeof(ATSUAttributeTag
);
171 ATSUAttributeTag
*tagPtr
= (ATSUAttributeTag
*)CFDataGetBytePtr(tagsData
);
172 ByteCount
*sizePtr
= (ByteCount
*)CFDataGetBytePtr(sizesData
);
173 UInt32
*bytePtr
= (UInt32
*)CFDataGetBytePtr(valuesData
);
174 ATSUAttributeValuePtr valuesPtr
= bytePtr
;
175 for ( ItemCount i
= 0 ; i
< count
; ++i
)
177 if ( tagPtr
[i
] == kATSUColorTag
&& sizePtr
[i
] == sizeof(RGBColor
))
179 fontdata
.m_fontColour
= *(RGBColor
*)valuesPtr
;
182 bytePtr
= (UInt32
*)( (UInt8
*)bytePtr
+ sizePtr
[i
]);
195 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler
)
198 wxFontDialog::wxFontDialog()
202 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
204 Create(parent
, data
);
207 wxFontDialog::~wxFontDialog()
211 bool wxFontDialog::Create(wxWindow
*WXUNUSED(parent
), const wxFontData
& data
)
217 int wxFontDialog::ShowModal()
222 wxFont font
= *wxNORMAL_FONT
;
223 if ( m_fontData
.m_initialFont
.Ok() )
225 font
= m_fontData
.m_initialFont
;
229 #if wxOSX_USE_CORE_TEXT
230 if ( UMAGetSystemVersion() >= 0x1050 )
232 CTFontDescriptorRef descr
= (CTFontDescriptorRef
) CTFontCopyFontDescriptor( (CTFontRef
) font
.MacGetCTFont() );
233 err
= SetFontInfoForSelection (kFontSelectionCoreTextType
,1, &descr
, NULL
);
238 #if wxOSX_USE_ATSU_TEXT
241 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
242 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
246 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
247 // that field is already correct
248 m_fontData
.m_chosenFont
= font
;
250 EventHandlerRef handler
;
252 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
254 if ( !FPIsFontPanelVisible() )
255 FPShowHideFontPanel();
257 int retval
= RunMixedFontDialog(this);
260 ::RemoveEventHandler(handler
);
268 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
272 #include "wx/osx/fontdlg.h"
274 #include "wx/fontenum.h"
275 #include "wx/colordlg.h"
276 #include "wx/spinctrl.h"
278 // ---------------------------------------------------------------------------
279 // wxFontDialog stub for mac OS's without a native font dialog
280 // ---------------------------------------------------------------------------
282 static const wxChar
*FontFamilyIntToString(int family
);
283 static int FontFamilyStringToInt(const wxChar
*family
);
286 //-----------------------------------------------------------------------------
287 // helper class - wxFontPreviewCtrl
288 //-----------------------------------------------------------------------------
290 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
293 wxFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
294 wxWindow(parent
, id
, pos
, sz
, style
)
296 SetBackgroundColour(*wxWHITE
);
300 void OnPaint(wxPaintEvent
& event
);
301 DECLARE_EVENT_TABLE()
304 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
305 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
308 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
312 wxSize size
= GetSize();
313 wxFont font
= GetFont();
318 // Calculate vertical centre
320 dc
.GetTextExtent( wxT("X"), &w
, &h
);
321 dc
.SetTextForeground(GetForegroundColour());
322 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
323 dc
.DrawText(_("ABCDEFGabcdefg12345"),
325 dc
.DestroyClippingRegion();
330 * A control for displaying a small preview of a colour or bitmap
333 class wxFontColourSwatchCtrl
: public wxControl
335 DECLARE_CLASS(wxFontColourSwatchCtrl
)
337 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
338 virtual ~wxFontColourSwatchCtrl();
340 void OnPaint(wxPaintEvent
& event
);
341 void OnMouseEvent(wxMouseEvent
& event
);
343 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
345 wxColour
& GetColour() { return m_colour
; }
347 virtual wxSize
DoGetBestSize() const { return GetSize(); }
352 DECLARE_EVENT_TABLE()
356 * A control for displaying a small preview of a colour or bitmap
359 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
360 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
363 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
365 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
366 wxControl(parent
, id
, pos
, size
, style
)
368 SetColour(* wxWHITE
);
369 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
372 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
376 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
378 if (event
.LeftDown())
380 wxWindow
* parent
= GetParent();
381 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
382 parent
= parent
->GetParent();
385 data
.SetChooseFull(true);
386 data
.SetColour(m_colour
);
387 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
388 // Crashes on wxMac (no m_peer)
390 dialog
->SetTitle(_("Background colour"));
392 if (dialog
->ShowModal() == wxID_OK
)
394 wxColourData retData
= dialog
->GetColourData();
395 m_colour
= retData
.GetColour();
396 SetBackgroundColour(m_colour
);
401 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
402 HandleWindowEvent(event
);
407 * wxFontDialog type definition
410 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
413 * wxFontDialog event table definition
416 BEGIN_EVENT_TABLE( wxFontDialog
, wxDialog
)
417 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME
, wxFontDialog::OnFontdialogFacenameSelected
)
418 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeUpdated
)
419 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeTextUpdated
)
420 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD
, wxFontDialog::OnFontdialogBoldClick
)
421 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC
, wxFontDialog::OnFontdialogItalicClick
)
422 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED
, wxFontDialog::OnFontdialogUnderlinedClick
)
423 EVT_BUTTON( wxID_OK
, wxFontDialog::OnOkClick
)
424 EVT_BUTTON(wxID_FONTDIALOG_COLOUR
, wxFontDialog::OnColourChanged
)
428 * wxFontDialog constructors
431 wxFontDialog::wxFontDialog( )
433 m_dialogParent
= NULL
;
436 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
438 m_dialogParent
= NULL
;
440 Create(parent
, fontData
);
443 wxFontDialog::~wxFontDialog()
449 * wxFontDialog creator
452 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
454 m_fontData
= fontData
;
455 m_suppressUpdates
= false;
457 wxString caption
= _("Font");
459 m_facenameCtrl
= NULL
;
463 m_underlinedCtrl
= NULL
;
465 m_previewCtrl
= NULL
;
469 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
470 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
473 GetSizer()->Fit(this);
474 GetSizer()->SetSizeHints(this);
481 * Control creation for wxFontDialog
484 void wxFontDialog::CreateControls()
486 wxFontDialog
* itemDialog1
= this;
488 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
489 itemDialog1
->SetSizer(itemBoxSizer2
);
491 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
492 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
494 wxFlexGridSizer
* itemFlexGridSizer4
= new wxFlexGridSizer(6, 2, 10, 0);
495 itemFlexGridSizer4
->AddGrowableRow(4);
496 itemFlexGridSizer4
->AddGrowableCol(1);
497 itemBoxSizer3
->Add(itemFlexGridSizer4
, 1, wxGROW
|wxALL
, 5);
499 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
500 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
502 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
503 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
|wxGROW
, 5);
505 wxString
* m_facenameCtrlStrings
= NULL
;
506 m_facenameCtrl
= new wxListBox( itemDialog1
, wxID_FONTDIALOG_FACENAME
, wxDefaultPosition
, wxSize(320, 100), 0, m_facenameCtrlStrings
, wxLB_SINGLE
);
507 itemBoxSizer6
->Add(m_facenameCtrl
, 0, wxGROW
|wxALL
, 5);
509 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
510 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
512 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, _T("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
513 m_sizeCtrl
->SetHelpText(_("The font size in points."));
515 m_sizeCtrl
->SetToolTip(_("The font size in points."));
516 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
518 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
519 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
521 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
522 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
524 m_boldCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_BOLD
, _("Bold"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
525 m_boldCtrl
->SetValue(false);
526 m_boldCtrl
->SetHelpText(_("Check to make the font bold."));
528 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
529 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
531 m_italicCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_ITALIC
, _("Italic"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
532 m_italicCtrl
->SetValue(false);
533 m_italicCtrl
->SetHelpText(_("Check to make the font italic."));
535 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
536 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
538 if (m_fontData
.GetEnableEffects())
540 m_underlinedCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_UNDERLINED
, _("Underlined"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
541 m_underlinedCtrl
->SetValue(false);
542 m_underlinedCtrl
->SetHelpText(_("Check to make the font underlined."));
544 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
545 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
548 if (m_fontData
.GetEnableEffects())
550 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
551 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
553 m_colourCtrl
= new wxFontColourSwatchCtrl( itemDialog1
, wxID_FONTDIALOG_COLOUR
, wxDefaultPosition
, wxSize(-1, 30), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
554 m_colourCtrl
->SetHelpText(_("Click to change the font colour."));
556 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
557 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
560 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
561 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
563 m_previewCtrl
= new wxFontPreviewCtrl( itemDialog1
, wxID_FONTDIALOG_PREVIEW
, wxDefaultPosition
, wxSize(-1, 70), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
564 m_previewCtrl
->SetHelpText(_("Shows a preview of the font."));
566 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
567 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
569 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
570 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
572 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
573 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
575 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
576 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
578 wxButton
* itemButton21
= new wxButton( itemDialog1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
579 itemButton21
->SetDefault();
580 itemButton21
->SetHelpText(_("Click to confirm changes to the font."));
582 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
583 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
585 wxFontEnumerator enumerator
;
586 enumerator
.EnumerateFacenames();
587 wxArrayString facenames
= enumerator
.GetFacenames();
590 facenames
.Add(_("<Any>"));
591 facenames
.Add(_("<Any Roman>"));
592 facenames
.Add(_("<Any Decorative>"));
593 facenames
.Add(_("<Any Modern>"));
594 facenames
.Add(_("<Any Script>"));
595 facenames
.Add(_("<Any Swiss>"));
596 facenames
.Add(_("<Any Teletype>"));
598 m_facenameCtrl
->Append(facenames
);
601 InitializeControls();
602 m_previewCtrl
->SetFont(m_dialogFont
);
603 if (m_fontData
.GetColour().Ok())
605 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
607 m_previewCtrl
->Refresh();
611 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
614 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
620 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
623 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
629 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
632 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
638 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
641 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
647 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
650 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
656 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
659 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
666 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
669 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
674 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
676 m_fontData
.SetColour(m_colourCtrl
->GetColour());
677 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
678 m_previewCtrl
->Refresh();
682 * Should we show tooltips?
685 bool wxFontDialog::ShowToolTips()
690 void wxFontDialog::InitializeFont()
692 int fontFamily
= wxSWISS
;
693 int fontWeight
= wxNORMAL
;
694 int fontStyle
= wxNORMAL
;
696 bool fontUnderline
= false;
699 if (m_fontData
.m_initialFont
.Ok())
701 fontFamily
= m_fontData
.m_initialFont
.GetFamily();
702 fontWeight
= m_fontData
.m_initialFont
.GetWeight();
703 fontStyle
= m_fontData
.m_initialFont
.GetStyle();
704 fontSize
= m_fontData
.m_initialFont
.GetPointSize();
705 fontUnderline
= m_fontData
.m_initialFont
.GetUnderlined();
706 fontName
= m_fontData
.m_initialFont
.GetFaceName();
709 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
710 fontWeight
, fontUnderline
, fontName
);
713 m_previewCtrl
->SetFont(m_dialogFont
);
715 m_fontData
.SetChosenFont(m_dialogFont
);
718 /// Set controls according to current font
719 void wxFontDialog::InitializeControls()
721 m_suppressUpdates
= true;
723 if (m_underlinedCtrl
)
724 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
726 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
727 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
728 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
730 wxString facename
= m_dialogFont
.GetFaceName();
731 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
733 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
735 m_facenameCtrl
->SetStringSelection(facename
);
737 if (m_colourCtrl
&& m_fontData
.GetColour().Ok())
739 m_colourCtrl
->SetColour(m_fontData
.GetColour());
740 m_colourCtrl
->Refresh();
743 m_suppressUpdates
= false;
746 /// Respond to font change
747 void wxFontDialog::ChangeFont()
749 if (m_suppressUpdates
)
752 bool underlined
= m_underlinedCtrl
? m_underlinedCtrl
->GetValue() : false;
753 bool italic
= m_italicCtrl
->GetValue();
754 bool bold
= m_boldCtrl
->GetValue();
755 int size
= m_sizeCtrl
->GetValue();
756 wxString facename
= m_facenameCtrl
->GetStringSelection();
758 int family
= FontFamilyStringToInt(facename
);
762 facename
= wxEmptyString
;
764 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
765 underlined
, facename
);
767 m_fontData
.SetChosenFont(m_dialogFont
);
769 m_previewCtrl
->SetFont(m_dialogFont
);
770 m_previewCtrl
->Refresh();
773 void wxFontDialog::SetData(const wxFontData
& fontdata
)
775 m_fontData
= fontdata
;
778 bool wxFontDialog::IsShown() const
783 int wxFontDialog::ShowModal()
785 return wxDialog::ShowModal();
788 void wxFontDialog::OnPanelClose()
792 const wxChar
*FontFamilyIntToString(int family
)
797 return _("<Any Roman>");
799 return _("<Any Decorative>");
801 return _("<Any Modern>");
803 return _("<Any Script>");
805 return _("<Any Teletype>");
808 return _("<Any Swiss>");
812 int FontFamilyStringToInt(const wxChar
*family
)
817 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
819 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
821 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
823 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
825 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
827 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
832 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
834 #endif // wxOSX_USE_EXPERIMENTAL_FONTDIALOG
836 #endif // wxUSE_FONTDLG