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"
45 #include "wx/modalhook.h"
47 #if wxOSX_USE_EXPERIMENTAL_FONTDIALOG
49 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
51 #include "wx/osx/private.h"
53 // ---------------------------------------------------------------------------
55 // ---------------------------------------------------------------------------
59 static const EventTypeSpec eventList
[] =
61 { kEventClassFont
, kEventFontSelection
} ,
66 wxMacCarbonFontPanelHandler(EventHandlerCallRef
WXUNUSED(nextHandler
),
70 OSStatus result
= eventNotHandledErr
;
71 wxFontDialog
*fontdialog
= (wxFontDialog
*) userData
;
72 wxFontData
& fontdata
= fontdialog
->GetFontData() ;
74 wxMacCarbonEvent
cEvent( event
);
75 switch(cEvent
.GetKind())
77 case kEventFontSelection
:
80 #if wxOSX_USE_CORE_TEXT
83 CTFontDescriptorRef descr
;
84 if ( cEvent
.GetParameter
<CTFontDescriptorRef
>( kEventParamCTFontDescriptor
, typeCTFontDescriptorRef
, &descr
) == noErr
)
87 wxNativeFontInfo fontinfo
;
89 font
.Create(fontinfo
);
90 fontdata
.SetChosenFont( font
) ;
95 #if wxOSX_USE_ATSU_TEXT
96 ATSUFontID fontId
= 0 ;
97 if ( !setup
&& (cEvent
.GetParameter
<ATSUFontID
>(kEventParamATSUFontID
, &fontId
) == noErr
) )
99 FMFontStyle fontStyle
= cEvent
.GetParameter
<FMFontStyle
>(kEventParamFMFontStyle
);
100 FMFontSize fontSize
= cEvent
.GetParameter
<FMFontSize
>(kEventParamFMFontSize
);
102 CFStringRef cfName
= NULL
;
104 FMFontFamily fontFamily
= cEvent
.GetParameter
<FMFontFamily
>(kEventParamFMFontFamily
);
105 ATSFontFamilyRef atsfontfamilyref
= FMGetATSFontFamilyRefFromFontFamily( fontFamily
) ;
106 OSStatus err
= ATSFontFamilyGetName( atsfontfamilyref
, kATSOptionFlagsDefault
, &cfName
) ;
109 wxFAIL_MSG("ATSFontFamilyGetName failed");
112 // we don't use the ATSU naming anymore
113 ByteCount actualLength
= 0;
115 OSStatus err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
116 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
120 char *c
= (char*)malloc( actualLength
);
121 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
122 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
123 cfName
= CFStringCreateWithCharacters(NULL
, (UniChar
*) c
, (actualLength
-1) >> 1);
127 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
128 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
132 c
= (char*)malloc(actualLength
);
133 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
134 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
135 c
[actualLength
-1] = 0;
136 cfName
= CFStringCreateWithCString(NULL
, c
, kCFStringEncodingMacRoman
);
144 fontdata
.m_chosenFont
.SetFaceName(wxCFStringRef(cfName
).AsString(wxLocale::GetSystemEncoding()));
145 fontdata
.m_chosenFont
.SetPointSize(fontSize
);
146 fontdata
.m_chosenFont
.SetStyle(fontStyle
& italic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
);
147 fontdata
.m_chosenFont
.SetUnderlined((fontStyle
& underline
)!=0);
148 fontdata
.m_chosenFont
.SetWeight(fontStyle
& bold
? wxFONTWEIGHT_BOLD
: wxFONTWEIGHT_NORMAL
);
151 #endif // wxOSX_USE_ATSU_TEXT
153 // retrieving the color
155 if ( cEvent
.GetParameter
<RGBColor
>(kEventParamFontColor
, &fontColor
) == noErr
)
157 fontdata
.m_fontColour
= fontColor
;
161 CFDictionaryRef dict
;
162 if ( cEvent
.GetParameter
<CFDictionaryRef
>(kEventParamDictionary
, &dict
) == noErr
)
164 CFDictionaryRef attributesDict
;
165 if ( CFDictionaryGetValueIfPresent(dict
, kFontPanelAttributesKey
, (const void **)&attributesDict
) )
169 CFDataRef valuesData
;
170 if ( CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeTagsKey
, (const void **)&tagsData
) &&
171 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeSizesKey
, (const void **)&sizesData
) &&
172 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeValuesKey
, (const void **)&valuesData
) )
174 ItemCount count
= CFDataGetLength(tagsData
)/sizeof(ATSUAttributeTag
);
175 ATSUAttributeTag
*tagPtr
= (ATSUAttributeTag
*)CFDataGetBytePtr(tagsData
);
176 ByteCount
*sizePtr
= (ByteCount
*)CFDataGetBytePtr(sizesData
);
177 UInt32
*bytePtr
= (UInt32
*)CFDataGetBytePtr(valuesData
);
178 ATSUAttributeValuePtr valuesPtr
= bytePtr
;
179 for ( ItemCount i
= 0 ; i
< count
; ++i
)
181 if ( tagPtr
[i
] == kATSUColorTag
&& sizePtr
[i
] == sizeof(RGBColor
))
183 fontdata
.m_fontColour
= *(RGBColor
*)valuesPtr
;
186 bytePtr
= (UInt32
*)( (UInt8
*)bytePtr
+ sizePtr
[i
]);
199 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler
)
202 wxFontDialog::wxFontDialog()
206 wxFontDialog::wxFontDialog(wxWindow
*parent
)
211 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
213 Create(parent
, data
);
216 wxFontDialog::~wxFontDialog()
220 bool wxFontDialog::Create(wxWindow
*WXUNUSED(parent
))
225 bool wxFontDialog::Create(wxWindow
*parent
, const wxFontData
& data
)
228 return Create(parent
) ;
231 int wxFontDialog::ShowModal()
233 WX_HOOK_MODAL_DIALOG();
238 wxFont font
= *wxNORMAL_FONT
;
239 if ( m_fontData
.m_initialFont
.IsOk() )
241 font
= m_fontData
.m_initialFont
;
245 #if wxOSX_USE_CORE_TEXT
248 CTFontDescriptorRef descr
= (CTFontDescriptorRef
) CTFontCopyFontDescriptor( (CTFontRef
) font
.OSXGetCTFont() );
249 err
= SetFontInfoForSelection (kFontSelectionCoreTextType
,1, &descr
, NULL
);
254 #if wxOSX_USE_ATSU_TEXT
257 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
258 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
262 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
263 // that field is already correct
264 m_fontData
.m_chosenFont
= font
;
266 EventHandlerRef handler
;
268 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
270 if ( !FPIsFontPanelVisible() )
271 FPShowHideFontPanel();
273 wxDialog::OSXBeginModalDialog();
274 int retval
= RunMixedFontDialog(this);
275 wxDialog::OSXEndModalDialog();
277 ::RemoveEventHandler(handler
);
285 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
289 #include "wx/osx/fontdlg.h"
291 #include "wx/fontenum.h"
292 #include "wx/colordlg.h"
293 #include "wx/spinctrl.h"
295 // ---------------------------------------------------------------------------
296 // wxFontDialog stub for mac OS's without a native font dialog
297 // ---------------------------------------------------------------------------
299 static const wxChar
*FontFamilyIntToString(int family
);
300 static int FontFamilyStringToInt(const wxChar
*family
);
303 //-----------------------------------------------------------------------------
304 // helper class - wxFontPreviewCtrl
305 //-----------------------------------------------------------------------------
307 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
310 wxFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
311 wxWindow(parent
, id
, pos
, sz
, style
)
313 SetBackgroundColour(*wxWHITE
);
317 void OnPaint(wxPaintEvent
& event
);
318 DECLARE_EVENT_TABLE()
321 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
322 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
325 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
329 wxSize size
= GetSize();
330 wxFont font
= GetFont();
335 // Calculate vertical centre
337 dc
.GetTextExtent( wxT("X"), &w
, &h
);
338 dc
.SetTextForeground(GetForegroundColour());
339 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
340 dc
.DrawText(_("ABCDEFGabcdefg12345"),
342 dc
.DestroyClippingRegion();
347 * A control for displaying a small preview of a colour or bitmap
350 class wxFontColourSwatchCtrl
: public wxControl
352 DECLARE_CLASS(wxFontColourSwatchCtrl
)
354 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
355 virtual ~wxFontColourSwatchCtrl();
357 void OnPaint(wxPaintEvent
& event
);
358 void OnMouseEvent(wxMouseEvent
& event
);
360 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
362 wxColour
& GetColour() { return m_colour
; }
364 virtual wxSize
DoGetBestSize() const { return GetSize(); }
369 DECLARE_EVENT_TABLE()
373 * A control for displaying a small preview of a colour or bitmap
376 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
377 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
380 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
382 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
383 wxControl(parent
, id
, pos
, size
, style
)
385 SetColour(* wxWHITE
);
386 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
389 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
393 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
395 if (event
.LeftDown())
397 wxWindow
* parent
= GetParent();
398 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
399 parent
= parent
->GetParent();
402 data
.SetChooseFull(true);
403 data
.SetColour(m_colour
);
404 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
405 // Crashes on wxMac (no m_peer)
407 dialog
->SetTitle(_("Background colour"));
409 if (dialog
->ShowModal() == wxID_OK
)
411 wxColourData retData
= dialog
->GetColourData();
412 m_colour
= retData
.GetColour();
413 SetBackgroundColour(m_colour
);
418 wxCommandEvent
event(wxEVT_BUTTON
, GetId());
419 HandleWindowEvent(event
);
424 * wxFontDialog type definition
427 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
430 * wxFontDialog event table definition
433 BEGIN_EVENT_TABLE( wxFontDialog
, wxDialog
)
434 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME
, wxFontDialog::OnFontdialogFacenameSelected
)
435 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeUpdated
)
436 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeTextUpdated
)
437 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD
, wxFontDialog::OnFontdialogBoldClick
)
438 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC
, wxFontDialog::OnFontdialogItalicClick
)
439 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED
, wxFontDialog::OnFontdialogUnderlinedClick
)
440 EVT_BUTTON( wxID_OK
, wxFontDialog::OnOkClick
)
441 EVT_BUTTON(wxID_FONTDIALOG_COLOUR
, wxFontDialog::OnColourChanged
)
445 * wxFontDialog constructors
448 wxFontDialog::wxFontDialog( )
450 m_dialogParent
= NULL
;
453 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
455 m_dialogParent
= NULL
;
457 Create(parent
, fontData
);
460 wxFontDialog::~wxFontDialog()
466 * wxFontDialog creator
469 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
471 m_fontData
= fontData
;
472 m_suppressUpdates
= false;
474 wxString caption
= _("Font");
476 m_facenameCtrl
= NULL
;
480 m_underlinedCtrl
= NULL
;
482 m_previewCtrl
= NULL
;
486 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
487 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
490 GetSizer()->Fit(this);
491 GetSizer()->SetSizeHints(this);
498 * Control creation for wxFontDialog
501 void wxFontDialog::CreateControls()
503 wxFontDialog
* itemDialog1
= this;
505 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
506 itemDialog1
->SetSizer(itemBoxSizer2
);
508 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
509 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
511 wxFlexGridSizer
* itemFlexGridSizer4
= new wxFlexGridSizer(6, 2, 10, 0);
512 itemFlexGridSizer4
->AddGrowableRow(4);
513 itemFlexGridSizer4
->AddGrowableCol(1);
514 itemBoxSizer3
->Add(itemFlexGridSizer4
, 1, wxGROW
|wxALL
, 5);
516 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
517 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
519 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
520 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
, 5);
522 wxString
* m_facenameCtrlStrings
= NULL
;
523 m_facenameCtrl
= new wxListBox( itemDialog1
, wxID_FONTDIALOG_FACENAME
, wxDefaultPosition
, wxSize(320, 100), 0, m_facenameCtrlStrings
, wxLB_SINGLE
);
524 itemBoxSizer6
->Add(m_facenameCtrl
, 0, wxGROW
|wxALL
, 5);
526 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
527 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
529 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, wxT("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
530 m_sizeCtrl
->SetHelpText(_("The font size in points."));
532 m_sizeCtrl
->SetToolTip(_("The font size in points."));
533 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
535 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
536 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
538 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
539 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
541 m_boldCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_BOLD
, _("Bold"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
542 m_boldCtrl
->SetValue(false);
543 m_boldCtrl
->SetHelpText(_("Check to make the font bold."));
545 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
546 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
548 m_italicCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_ITALIC
, _("Italic"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
549 m_italicCtrl
->SetValue(false);
550 m_italicCtrl
->SetHelpText(_("Check to make the font italic."));
552 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
553 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
555 if (m_fontData
.GetEnableEffects())
557 m_underlinedCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_UNDERLINED
, _("Underlined"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
558 m_underlinedCtrl
->SetValue(false);
559 m_underlinedCtrl
->SetHelpText(_("Check to make the font underlined."));
561 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
562 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
565 if (m_fontData
.GetEnableEffects())
567 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
568 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
570 m_colourCtrl
= new wxFontColourSwatchCtrl( itemDialog1
, wxID_FONTDIALOG_COLOUR
, wxDefaultPosition
, wxSize(-1, 30), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
571 m_colourCtrl
->SetHelpText(_("Click to change the font colour."));
573 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
574 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
577 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
578 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
580 m_previewCtrl
= new wxFontPreviewCtrl( itemDialog1
, wxID_FONTDIALOG_PREVIEW
, wxDefaultPosition
, wxSize(-1, 70), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
581 m_previewCtrl
->SetHelpText(_("Shows a preview of the font."));
583 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
584 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
586 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
587 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
589 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
590 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
592 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
593 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
595 wxButton
* itemButton21
= new wxButton( itemDialog1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
596 itemButton21
->SetDefault();
597 itemButton21
->SetHelpText(_("Click to confirm changes to the font."));
599 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
600 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
602 wxFontEnumerator enumerator
;
603 enumerator
.EnumerateFacenames();
604 wxArrayString facenames
= enumerator
.GetFacenames();
605 if (!facenames
.empty())
607 facenames
.Add(_("<Any>"));
608 facenames
.Add(_("<Any Roman>"));
609 facenames
.Add(_("<Any Decorative>"));
610 facenames
.Add(_("<Any Modern>"));
611 facenames
.Add(_("<Any Script>"));
612 facenames
.Add(_("<Any Swiss>"));
613 facenames
.Add(_("<Any Teletype>"));
615 m_facenameCtrl
->Append(facenames
);
618 InitializeControls();
619 m_previewCtrl
->SetFont(m_dialogFont
);
620 if (m_fontData
.GetColour().IsOk())
622 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
624 m_previewCtrl
->Refresh();
628 * wxEVT_SPINCTRL event handler for wxID_FONTDIALOG_FONTSIZE
631 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
637 * wxEVT_TEXT event handler for wxID_FONTDIALOG_FONTSIZE
640 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
646 * wxEVT_CHECKBOX event handler for wxID_FONTDIALOG_BOLD
649 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
655 * wxEVT_CHECKBOX event handler for wxID_FONTDIALOG_ITALIC
658 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
664 * wxEVT_CHECKBOX event handler for wxID_FONTDIALOG_UNDERLINED
667 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
673 * wxEVT_BUTTON event handler for wxID_OK
676 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
683 * wxEVT_LISTBOX event handler for wxID_FONTDIALOG_FACENAME
686 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
691 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
693 m_fontData
.SetColour(m_colourCtrl
->GetColour());
694 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
695 m_previewCtrl
->Refresh();
699 * Should we show tooltips?
702 bool wxFontDialog::ShowToolTips()
707 void wxFontDialog::InitializeFont()
709 int fontFamily
= wxSWISS
;
710 int fontWeight
= wxNORMAL
;
711 int fontStyle
= wxNORMAL
;
713 bool fontUnderline
= false;
716 if (m_fontData
.m_initialFont
.IsOk())
718 fontFamily
= m_fontData
.m_initialFont
.GetFamily();
719 fontWeight
= m_fontData
.m_initialFont
.GetWeight();
720 fontStyle
= m_fontData
.m_initialFont
.GetStyle();
721 fontSize
= m_fontData
.m_initialFont
.GetPointSize();
722 fontUnderline
= m_fontData
.m_initialFont
.GetUnderlined();
723 fontName
= m_fontData
.m_initialFont
.GetFaceName();
726 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
727 fontWeight
, fontUnderline
, fontName
);
730 m_previewCtrl
->SetFont(m_dialogFont
);
732 m_fontData
.SetChosenFont(m_dialogFont
);
735 /// Set controls according to current font
736 void wxFontDialog::InitializeControls()
738 m_suppressUpdates
= true;
740 if (m_underlinedCtrl
)
741 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
743 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
744 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
745 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
747 wxString facename
= m_dialogFont
.GetFaceName();
748 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
750 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
752 m_facenameCtrl
->SetStringSelection(facename
);
754 if (m_colourCtrl
&& m_fontData
.GetColour().IsOk())
756 m_colourCtrl
->SetColour(m_fontData
.GetColour());
757 m_colourCtrl
->Refresh();
760 m_suppressUpdates
= false;
763 /// Respond to font change
764 void wxFontDialog::ChangeFont()
766 if (m_suppressUpdates
)
769 bool underlined
= m_underlinedCtrl
? m_underlinedCtrl
->GetValue() : false;
770 bool italic
= m_italicCtrl
->GetValue();
771 bool bold
= m_boldCtrl
->GetValue();
772 int size
= m_sizeCtrl
->GetValue();
773 wxString facename
= m_facenameCtrl
->GetStringSelection();
775 int family
= FontFamilyStringToInt(facename
);
779 facename
= wxEmptyString
;
781 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
782 underlined
, facename
);
784 m_fontData
.SetChosenFont(m_dialogFont
);
786 m_previewCtrl
->SetFont(m_dialogFont
);
787 m_previewCtrl
->Refresh();
790 void wxFontDialog::SetData(const wxFontData
& fontdata
)
792 m_fontData
= fontdata
;
795 bool wxFontDialog::IsShown() const
800 int wxFontDialog::ShowModal()
802 return wxDialog::ShowModal();
805 void wxFontDialog::OnPanelClose()
809 const wxChar
*FontFamilyIntToString(int family
)
814 return _("<Any Roman>");
816 return _("<Any Decorative>");
818 return _("<Any Modern>");
820 return _("<Any Script>");
822 return _("<Any Teletype>");
825 return _("<Any Swiss>");
829 int FontFamilyStringToInt(const wxChar
*family
)
834 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
836 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
838 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
840 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
842 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
844 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
849 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
851 #endif // wxOSX_USE_EXPERIMENTAL_FONTDIALOG
853 #endif // wxUSE_FONTDLG