1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/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 wxMAC_USE_EXPERIMENTAL_FONTDIALOG
47 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
49 #include "wx/osx/uma.h"
51 // ---------------------------------------------------------------------------
53 // ---------------------------------------------------------------------------
55 static const EventTypeSpec eventList
[] =
57 { kEventClassFont
, kEventFontSelection
} ,
62 wxMacCarbonFontPanelHandler(EventHandlerCallRef
WXUNUSED(nextHandler
),
66 OSStatus result
= eventNotHandledErr
;
67 wxFontDialog
*fontdialog
= (wxFontDialog
*) userData
;
68 wxFontData
& fontdata
= fontdialog
->GetFontData() ;
70 wxMacCarbonEvent
cEvent( event
);
71 switch(cEvent
.GetKind())
73 case kEventFontSelection
:
76 #if wxMAC_USE_CORE_TEXT
77 if ( UMAGetSystemVersion() >= 0x1050 )
79 CTFontDescriptorRef descr
;
80 if ( cEvent
.GetParameter
<CTFontDescriptorRef
>( kEventParamCTFontDescriptor
, typeCTFontDescriptorRef
, &descr
) == noErr
)
83 font
.MacCreateFromCTFontDescriptor(descr
);
84 fontdata
.SetChosenFont( font
) ;
89 #if wxMAC_USE_ATSU_TEXT
90 ATSUFontID fontId
= 0 ;
91 if ( !setup
&& (cEvent
.GetParameter
<ATSUFontID
>(kEventParamATSUFontID
, &fontId
) == noErr
) )
93 FMFontStyle fontStyle
= cEvent
.GetParameter
<FMFontStyle
>(kEventParamFMFontStyle
);
94 FMFontSize fontSize
= cEvent
.GetParameter
<FMFontSize
>(kEventParamFMFontSize
);
96 CFStringRef cfName
= NULL
;
98 FMFontFamily fontFamily
= cEvent
.GetParameter
<FMFontFamily
>(kEventParamFMFontFamily
);
99 ATSFontFamilyRef atsfontfamilyref
= FMGetATSFontFamilyRefFromFontFamily( fontFamily
) ;
100 OSStatus err
= ATSFontFamilyGetName( atsfontfamilyref
, kATSOptionFlagsDefault
, &cfName
) ;
103 wxFAIL_MSG("ATSFontFamilyGetName failed");
106 // we don't use the ATSU naming anymore
107 ByteCount actualLength
= 0;
109 OSStatus err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
110 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
114 char *c
= (char*)malloc( actualLength
);
115 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
116 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
117 cfName
= CFStringCreateWithCharacters(NULL
, (UniChar
*) c
, (actualLength
-1) >> 1);
121 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
122 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
126 c
= (char*)malloc(actualLength
);
127 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
128 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
129 c
[actualLength
-1] = 0;
130 cfName
= CFStringCreateWithCString(NULL
, c
, kCFStringEncodingMacRoman
);
138 fontdata
.m_chosenFont
.SetFaceName(wxCFStringRef(cfName
).AsString(wxLocale::GetSystemEncoding()));
139 fontdata
.m_chosenFont
.SetPointSize(fontSize
);
140 fontdata
.m_chosenFont
.SetStyle(fontStyle
& italic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
);
141 fontdata
.m_chosenFont
.SetUnderlined((fontStyle
& underline
)!=0);
142 fontdata
.m_chosenFont
.SetWeight(fontStyle
& bold
? wxFONTWEIGHT_BOLD
: wxFONTWEIGHT_NORMAL
);
145 #endif // wxMAC_USE_ATSU_TEXT
147 // retrieving the color
149 if ( cEvent
.GetParameter
<RGBColor
>(kEventParamFontColor
, &fontColor
) == noErr
)
151 fontdata
.m_fontColour
= fontColor
;
155 CFDictionaryRef dict
;
156 if ( cEvent
.GetParameter
<CFDictionaryRef
>(kEventParamDictionary
, &dict
) == noErr
)
158 CFDictionaryRef attributesDict
;
159 if ( CFDictionaryGetValueIfPresent(dict
, kFontPanelAttributesKey
, (const void **)&attributesDict
) )
163 CFDataRef valuesData
;
164 if ( CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeTagsKey
, (const void **)&tagsData
) &&
165 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeSizesKey
, (const void **)&sizesData
) &&
166 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeValuesKey
, (const void **)&valuesData
) )
168 ItemCount count
= CFDataGetLength(tagsData
)/sizeof(ATSUAttributeTag
);
169 ATSUAttributeTag
*tagPtr
= (ATSUAttributeTag
*)CFDataGetBytePtr(tagsData
);
170 ByteCount
*sizePtr
= (ByteCount
*)CFDataGetBytePtr(sizesData
);
171 UInt32
*bytePtr
= (UInt32
*)CFDataGetBytePtr(valuesData
);
172 ATSUAttributeValuePtr valuesPtr
= bytePtr
;
173 for ( ItemCount i
= 0 ; i
< count
; ++i
)
175 if ( tagPtr
[i
] == kATSUColorTag
&& sizePtr
[i
] == sizeof(RGBColor
))
177 fontdata
.m_fontColour
= *(RGBColor
*)valuesPtr
;
180 bytePtr
= (UInt32
*)( (UInt8
*)bytePtr
+ sizePtr
[i
]);
193 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler
)
195 wxFontDialog::wxFontDialog()
199 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
201 Create(parent
, data
);
204 wxFontDialog::~wxFontDialog()
208 bool wxFontDialog::Create(wxWindow
*WXUNUSED(parent
), const wxFontData
& data
)
214 int wxFontDialog::ShowModal()
217 wxFont font
= *wxNORMAL_FONT
;
218 if ( m_fontData
.m_initialFont
.Ok() )
220 font
= m_fontData
.m_initialFont
;
224 #if wxMAC_USE_CORE_TEXT
225 if ( UMAGetSystemVersion() >= 0x1050 )
227 CTFontDescriptorRef descr
= (CTFontDescriptorRef
)font
.MacGetCTFontDescriptor();
228 err
= SetFontInfoForSelection (kFontSelectionCoreTextType
,1, &descr
, NULL
);
232 #if wxMAC_USE_ATSU_TEXT
235 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
236 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
240 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
241 // that field is already correct
242 m_fontData
.m_chosenFont
= font
;
244 EventHandlerRef handler
;
246 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
248 if ( !FPIsFontPanelVisible() )
249 FPShowHideFontPanel();
251 int retval
= RunMixedFontDialog(this);
253 ::RemoveEventHandler(handler
);
260 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
264 #include "wx/osx/fontdlg.h"
266 #include "wx/fontenum.h"
267 #include "wx/colordlg.h"
268 #include "wx/spinctrl.h"
270 // ---------------------------------------------------------------------------
271 // wxFontDialog stub for mac OS's without a native font dialog
272 // ---------------------------------------------------------------------------
274 static const wxChar
*FontFamilyIntToString(int family
);
275 static int FontFamilyStringToInt(const wxChar
*family
);
278 //-----------------------------------------------------------------------------
279 // helper class - wxFontPreviewCtrl
280 //-----------------------------------------------------------------------------
282 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
285 wxFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
286 wxWindow(parent
, id
, pos
, sz
, style
)
288 SetBackgroundColour(*wxWHITE
);
292 void OnPaint(wxPaintEvent
& event
);
293 DECLARE_EVENT_TABLE()
296 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
297 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
300 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
304 wxSize size
= GetSize();
305 wxFont font
= GetFont();
310 // Calculate vertical centre
312 dc
.GetTextExtent( wxT("X"), &w
, &h
);
313 dc
.SetTextForeground(GetForegroundColour());
314 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
315 dc
.DrawText(_("ABCDEFGabcdefg12345"),
317 dc
.DestroyClippingRegion();
322 * A control for displaying a small preview of a colour or bitmap
325 class wxFontColourSwatchCtrl
: public wxControl
327 DECLARE_CLASS(wxFontColourSwatchCtrl
)
329 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
330 virtual ~wxFontColourSwatchCtrl();
332 void OnPaint(wxPaintEvent
& event
);
333 void OnMouseEvent(wxMouseEvent
& event
);
335 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
337 wxColour
& GetColour() { return m_colour
; }
339 virtual wxSize
DoGetBestSize() const { return GetSize(); }
344 DECLARE_EVENT_TABLE()
348 * A control for displaying a small preview of a colour or bitmap
351 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
352 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
355 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
357 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
358 wxControl(parent
, id
, pos
, size
, style
)
360 SetColour(* wxWHITE
);
361 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
364 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
368 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
370 if (event
.LeftDown())
372 wxWindow
* parent
= GetParent();
373 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
374 parent
= parent
->GetParent();
377 data
.SetChooseFull(true);
378 data
.SetColour(m_colour
);
379 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
380 // Crashes on wxMac (no m_peer)
382 dialog
->SetTitle(_("Background colour"));
384 if (dialog
->ShowModal() == wxID_OK
)
386 wxColourData retData
= dialog
->GetColourData();
387 m_colour
= retData
.GetColour();
388 SetBackgroundColour(m_colour
);
393 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
394 HandleWindowEvent(event
);
399 * wxFontDialog type definition
402 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
405 * wxFontDialog event table definition
408 BEGIN_EVENT_TABLE( wxFontDialog
, wxDialog
)
409 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME
, wxFontDialog::OnFontdialogFacenameSelected
)
410 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeUpdated
)
411 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeTextUpdated
)
412 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD
, wxFontDialog::OnFontdialogBoldClick
)
413 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC
, wxFontDialog::OnFontdialogItalicClick
)
414 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED
, wxFontDialog::OnFontdialogUnderlinedClick
)
415 EVT_BUTTON( wxID_OK
, wxFontDialog::OnOkClick
)
416 EVT_BUTTON(wxID_FONTDIALOG_COLOUR
, wxFontDialog::OnColourChanged
)
420 * wxFontDialog constructors
423 wxFontDialog::wxFontDialog( )
425 m_dialogParent
= NULL
;
428 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
430 m_dialogParent
= NULL
;
432 Create(parent
, fontData
);
435 wxFontDialog::~wxFontDialog()
441 * wxFontDialog creator
444 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
446 m_fontData
= fontData
;
447 m_suppressUpdates
= false;
449 wxString caption
= _("Font");
451 m_facenameCtrl
= NULL
;
455 m_underlinedCtrl
= NULL
;
457 m_previewCtrl
= NULL
;
461 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
462 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
465 GetSizer()->Fit(this);
466 GetSizer()->SetSizeHints(this);
473 * Control creation for wxFontDialog
476 void wxFontDialog::CreateControls()
478 wxFontDialog
* itemDialog1
= this;
480 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
481 itemDialog1
->SetSizer(itemBoxSizer2
);
483 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
484 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
486 wxFlexGridSizer
* itemFlexGridSizer4
= new wxFlexGridSizer(6, 2, 10, 0);
487 itemFlexGridSizer4
->AddGrowableRow(4);
488 itemFlexGridSizer4
->AddGrowableCol(1);
489 itemBoxSizer3
->Add(itemFlexGridSizer4
, 1, wxGROW
|wxALL
, 5);
491 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
492 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
494 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
495 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
|wxGROW
, 5);
497 wxString
* m_facenameCtrlStrings
= NULL
;
498 m_facenameCtrl
= new wxListBox( itemDialog1
, wxID_FONTDIALOG_FACENAME
, wxDefaultPosition
, wxSize(320, 100), 0, m_facenameCtrlStrings
, wxLB_SINGLE
);
499 itemBoxSizer6
->Add(m_facenameCtrl
, 0, wxGROW
|wxALL
, 5);
501 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
502 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
504 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, _T("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
505 m_sizeCtrl
->SetHelpText(_("The font size in points."));
507 m_sizeCtrl
->SetToolTip(_("The font size in points."));
508 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
510 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
511 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
513 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
514 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
516 m_boldCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_BOLD
, _("Bold"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
517 m_boldCtrl
->SetValue(false);
518 m_boldCtrl
->SetHelpText(_("Check to make the font bold."));
520 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
521 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
523 m_italicCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_ITALIC
, _("Italic"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
524 m_italicCtrl
->SetValue(false);
525 m_italicCtrl
->SetHelpText(_("Check to make the font italic."));
527 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
528 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
530 if (m_fontData
.GetEnableEffects())
532 m_underlinedCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_UNDERLINED
, _("Underlined"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
533 m_underlinedCtrl
->SetValue(false);
534 m_underlinedCtrl
->SetHelpText(_("Check to make the font underlined."));
536 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
537 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
540 if (m_fontData
.GetEnableEffects())
542 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
543 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
545 m_colourCtrl
= new wxFontColourSwatchCtrl( itemDialog1
, wxID_FONTDIALOG_COLOUR
, wxDefaultPosition
, wxSize(-1, 30), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
546 m_colourCtrl
->SetHelpText(_("Click to change the font colour."));
548 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
549 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
552 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
553 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
555 m_previewCtrl
= new wxFontPreviewCtrl( itemDialog1
, wxID_FONTDIALOG_PREVIEW
, wxDefaultPosition
, wxSize(-1, 70), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
556 m_previewCtrl
->SetHelpText(_("Shows a preview of the font."));
558 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
559 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
561 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
562 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
564 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
565 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
567 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
568 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
570 wxButton
* itemButton21
= new wxButton( itemDialog1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
571 itemButton21
->SetDefault();
572 itemButton21
->SetHelpText(_("Click to confirm changes to the font."));
574 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
575 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
577 wxFontEnumerator enumerator
;
578 enumerator
.EnumerateFacenames();
579 wxArrayString facenames
= enumerator
.GetFacenames();
582 facenames
.Add(_("<Any>"));
583 facenames
.Add(_("<Any Roman>"));
584 facenames
.Add(_("<Any Decorative>"));
585 facenames
.Add(_("<Any Modern>"));
586 facenames
.Add(_("<Any Script>"));
587 facenames
.Add(_("<Any Swiss>"));
588 facenames
.Add(_("<Any Teletype>"));
590 m_facenameCtrl
->Append(facenames
);
593 InitializeControls();
594 m_previewCtrl
->SetFont(m_dialogFont
);
595 if (m_fontData
.GetColour().Ok())
597 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
599 m_previewCtrl
->Refresh();
603 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
606 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
612 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
615 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
621 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
624 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
630 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
633 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
639 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
642 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
648 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
651 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
658 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
661 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
666 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
668 m_fontData
.SetColour(m_colourCtrl
->GetColour());
669 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
670 m_previewCtrl
->Refresh();
674 * Should we show tooltips?
677 bool wxFontDialog::ShowToolTips()
682 void wxFontDialog::InitializeFont()
684 int fontFamily
= wxSWISS
;
685 int fontWeight
= wxNORMAL
;
686 int fontStyle
= wxNORMAL
;
688 bool fontUnderline
= false;
691 if (m_fontData
.m_initialFont
.Ok())
693 fontFamily
= m_fontData
.m_initialFont
.GetFamily();
694 fontWeight
= m_fontData
.m_initialFont
.GetWeight();
695 fontStyle
= m_fontData
.m_initialFont
.GetStyle();
696 fontSize
= m_fontData
.m_initialFont
.GetPointSize();
697 fontUnderline
= m_fontData
.m_initialFont
.GetUnderlined();
698 fontName
= m_fontData
.m_initialFont
.GetFaceName();
701 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
702 fontWeight
, fontUnderline
, fontName
);
705 m_previewCtrl
->SetFont(m_dialogFont
);
707 m_fontData
.SetChosenFont(m_dialogFont
);
710 /// Set controls according to current font
711 void wxFontDialog::InitializeControls()
713 m_suppressUpdates
= true;
715 if (m_underlinedCtrl
)
716 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
718 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
719 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
720 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
722 wxString facename
= m_dialogFont
.GetFaceName();
723 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
725 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
727 m_facenameCtrl
->SetStringSelection(facename
);
729 if (m_colourCtrl
&& m_fontData
.GetColour().Ok())
731 m_colourCtrl
->SetColour(m_fontData
.GetColour());
732 m_colourCtrl
->Refresh();
735 m_suppressUpdates
= false;
738 /// Respond to font change
739 void wxFontDialog::ChangeFont()
741 if (m_suppressUpdates
)
744 bool underlined
= m_underlinedCtrl
? m_underlinedCtrl
->GetValue() : false;
745 bool italic
= m_italicCtrl
->GetValue();
746 bool bold
= m_boldCtrl
->GetValue();
747 int size
= m_sizeCtrl
->GetValue();
748 wxString facename
= m_facenameCtrl
->GetStringSelection();
750 int family
= FontFamilyStringToInt(facename
);
754 facename
= wxEmptyString
;
756 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
757 underlined
, facename
);
759 m_fontData
.SetChosenFont(m_dialogFont
);
761 m_previewCtrl
->SetFont(m_dialogFont
);
762 m_previewCtrl
->Refresh();
765 void wxFontDialog::SetData(const wxFontData
& fontdata
)
767 m_fontData
= fontdata
;
770 bool wxFontDialog::IsShown() const
775 int wxFontDialog::ShowModal()
777 return wxDialog::ShowModal();
780 void wxFontDialog::OnPanelClose()
784 const wxChar
*FontFamilyIntToString(int family
)
789 return _("<Any Roman>");
791 return _("<Any Decorative>");
793 return _("<Any Modern>");
795 return _("<Any Script>");
797 return _("<Any Teletype>");
800 return _("<Any Swiss>");
804 int FontFamilyStringToInt(const wxChar
*family
)
809 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
811 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
813 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
815 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
817 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
819 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
824 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
826 #endif // wxMAC_USE_EXPERIMENTAL_FONTDIALOG
828 #endif // wxUSE_FONTDLG