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/mac/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
) ;
101 wxASSERT_MSG( err
== noErr
, wxT("ATSFontFamilyGetName failed") );
103 // we don't use the ATSU naming anymore
104 ByteCount actualLength
= 0;
106 OSStatus err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
107 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
111 char *c
= (char*)malloc( actualLength
);
112 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
113 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
114 cfName
= CFStringCreateWithCharacters(NULL
, (UniChar
*) c
, (actualLength
-1) >> 1);
118 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
119 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
123 c
= (char*)malloc(actualLength
);
124 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
125 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
126 c
[actualLength
-1] = 0;
127 cfName
= CFStringCreateWithCString(NULL
, c
, kCFStringEncodingMacRoman
);
135 fontdata
.m_chosenFont
.SetFaceName(wxCFStringRef(cfName
).AsString(wxLocale::GetSystemEncoding()));
136 fontdata
.m_chosenFont
.SetPointSize(fontSize
);
137 fontdata
.m_chosenFont
.SetStyle(fontStyle
& italic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
);
138 fontdata
.m_chosenFont
.SetUnderlined((fontStyle
& underline
)!=0);
139 fontdata
.m_chosenFont
.SetWeight(fontStyle
& bold
? wxFONTWEIGHT_BOLD
: wxFONTWEIGHT_NORMAL
);
142 #endif // wxMAC_USE_ATSU_TEXT
144 // retrieving the color
146 if ( cEvent
.GetParameter
<RGBColor
>(kEventParamFontColor
, &fontColor
) == noErr
)
148 fontdata
.m_fontColour
= fontColor
;
152 CFDictionaryRef dict
;
153 if ( cEvent
.GetParameter
<CFDictionaryRef
>(kEventParamDictionary
, &dict
) == noErr
)
155 CFDictionaryRef attributesDict
;
156 if ( CFDictionaryGetValueIfPresent(dict
, kFontPanelAttributesKey
, (const void **)&attributesDict
) )
160 CFDataRef valuesData
;
161 if ( CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeTagsKey
, (const void **)&tagsData
) &&
162 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeSizesKey
, (const void **)&sizesData
) &&
163 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeValuesKey
, (const void **)&valuesData
) )
165 ItemCount count
= CFDataGetLength(tagsData
)/sizeof(ATSUAttributeTag
);
166 ATSUAttributeTag
*tagPtr
= (ATSUAttributeTag
*)CFDataGetBytePtr(tagsData
);
167 ByteCount
*sizePtr
= (ByteCount
*)CFDataGetBytePtr(sizesData
);
168 UInt32
*bytePtr
= (UInt32
*)CFDataGetBytePtr(valuesData
);
169 ATSUAttributeValuePtr valuesPtr
= bytePtr
;
170 for ( ItemCount i
= 0 ; i
< count
; ++i
)
172 if ( tagPtr
[i
] == kATSUColorTag
&& sizePtr
[i
] == sizeof(RGBColor
))
174 fontdata
.m_fontColour
= *(RGBColor
*)valuesPtr
;
177 bytePtr
= (UInt32
*)( (UInt8
*)bytePtr
+ sizePtr
[i
]);
190 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler
)
192 wxFontDialog::wxFontDialog()
196 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
198 Create(parent
, data
);
201 wxFontDialog::~wxFontDialog()
205 bool wxFontDialog::Create(wxWindow
*WXUNUSED(parent
), const wxFontData
& data
)
211 int wxFontDialog::ShowModal()
214 wxFont font
= *wxNORMAL_FONT
;
215 if ( m_fontData
.m_initialFont
.Ok() )
217 font
= m_fontData
.m_initialFont
;
221 #if wxMAC_USE_CORE_TEXT
222 if ( UMAGetSystemVersion() >= 0x1050 )
224 CTFontDescriptorRef descr
= (CTFontDescriptorRef
)font
.MacGetCTFontDescriptor();
225 err
= SetFontInfoForSelection (kFontSelectionCoreTextType
,1, &descr
, NULL
);
229 #if wxMAC_USE_ATSU_TEXT
232 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
233 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
237 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
238 // that field is already correct
239 m_fontData
.m_chosenFont
= font
;
241 EventHandlerRef handler
;
243 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
245 if ( !FPIsFontPanelVisible() )
246 FPShowHideFontPanel();
248 int retval
= RunMixedFontDialog(this);
250 ::RemoveEventHandler(handler
);
257 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
261 #include "wx/mac/fontdlg.h"
263 #include "wx/fontenum.h"
264 #include "wx/colordlg.h"
265 #include "wx/spinctrl.h"
267 // ---------------------------------------------------------------------------
268 // wxFontDialog stub for mac OS's without a native font dialog
269 // ---------------------------------------------------------------------------
271 static const wxChar
*FontFamilyIntToString(int family
);
272 static int FontFamilyStringToInt(const wxChar
*family
);
275 //-----------------------------------------------------------------------------
276 // helper class - wxFontPreviewCtrl
277 //-----------------------------------------------------------------------------
279 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
282 wxFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
283 wxWindow(parent
, id
, pos
, sz
, style
)
285 SetBackgroundColour(*wxWHITE
);
289 void OnPaint(wxPaintEvent
& event
);
290 DECLARE_EVENT_TABLE()
293 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
294 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
297 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
301 wxSize size
= GetSize();
302 wxFont font
= GetFont();
307 // Calculate vertical centre
309 dc
.GetTextExtent( wxT("X"), &w
, &h
);
310 dc
.SetTextForeground(GetForegroundColour());
311 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
312 dc
.DrawText(_("ABCDEFGabcdefg12345"),
314 dc
.DestroyClippingRegion();
319 * A control for displaying a small preview of a colour or bitmap
322 class wxFontColourSwatchCtrl
: public wxControl
324 DECLARE_CLASS(wxFontColourSwatchCtrl
)
326 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
327 virtual ~wxFontColourSwatchCtrl();
329 void OnPaint(wxPaintEvent
& event
);
330 void OnMouseEvent(wxMouseEvent
& event
);
332 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
334 wxColour
& GetColour() { return m_colour
; }
336 virtual wxSize
DoGetBestSize() const { return GetSize(); }
341 DECLARE_EVENT_TABLE()
345 * A control for displaying a small preview of a colour or bitmap
348 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
349 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
352 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
354 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
355 wxControl(parent
, id
, pos
, size
, style
)
357 SetColour(* wxWHITE
);
358 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
361 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
365 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
367 if (event
.LeftDown())
369 wxWindow
* parent
= GetParent();
370 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
371 parent
= parent
->GetParent();
374 data
.SetChooseFull(true);
375 data
.SetColour(m_colour
);
376 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
377 // Crashes on wxMac (no m_peer)
379 dialog
->SetTitle(_("Background colour"));
381 if (dialog
->ShowModal() == wxID_OK
)
383 wxColourData retData
= dialog
->GetColourData();
384 m_colour
= retData
.GetColour();
385 SetBackgroundColour(m_colour
);
390 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
391 HandleWindowEvent(event
);
396 * wxFontDialog type definition
399 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
402 * wxFontDialog event table definition
405 BEGIN_EVENT_TABLE( wxFontDialog
, wxDialog
)
406 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME
, wxFontDialog::OnFontdialogFacenameSelected
)
407 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeUpdated
)
408 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeTextUpdated
)
409 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD
, wxFontDialog::OnFontdialogBoldClick
)
410 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC
, wxFontDialog::OnFontdialogItalicClick
)
411 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED
, wxFontDialog::OnFontdialogUnderlinedClick
)
412 EVT_BUTTON( wxID_OK
, wxFontDialog::OnOkClick
)
413 EVT_BUTTON(wxID_FONTDIALOG_COLOUR
, wxFontDialog::OnColourChanged
)
417 * wxFontDialog constructors
420 wxFontDialog::wxFontDialog( )
422 m_dialogParent
= NULL
;
425 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
427 m_dialogParent
= NULL
;
429 Create(parent
, fontData
);
432 wxFontDialog::~wxFontDialog()
438 * wxFontDialog creator
441 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
443 m_fontData
= fontData
;
444 m_suppressUpdates
= false;
446 wxString caption
= _("Font");
448 m_facenameCtrl
= NULL
;
452 m_underlinedCtrl
= NULL
;
454 m_previewCtrl
= NULL
;
458 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
459 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
462 GetSizer()->Fit(this);
463 GetSizer()->SetSizeHints(this);
470 * Control creation for wxFontDialog
473 void wxFontDialog::CreateControls()
475 wxFontDialog
* itemDialog1
= this;
477 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
478 itemDialog1
->SetSizer(itemBoxSizer2
);
480 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
481 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
483 wxFlexGridSizer
* itemFlexGridSizer4
= new wxFlexGridSizer(6, 2, 10, 0);
484 itemFlexGridSizer4
->AddGrowableRow(4);
485 itemFlexGridSizer4
->AddGrowableCol(1);
486 itemBoxSizer3
->Add(itemFlexGridSizer4
, 1, wxGROW
|wxALL
, 5);
488 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
489 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
491 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
492 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
|wxGROW
, 5);
494 wxString
* m_facenameCtrlStrings
= NULL
;
495 m_facenameCtrl
= new wxListBox( itemDialog1
, wxID_FONTDIALOG_FACENAME
, wxDefaultPosition
, wxSize(320, 100), 0, m_facenameCtrlStrings
, wxLB_SINGLE
);
496 itemBoxSizer6
->Add(m_facenameCtrl
, 0, wxGROW
|wxALL
, 5);
498 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
499 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
501 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, _T("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
502 m_sizeCtrl
->SetHelpText(_("The font size in points."));
504 m_sizeCtrl
->SetToolTip(_("The font size in points."));
505 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
507 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
508 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
510 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
511 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
513 m_boldCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_BOLD
, _("Bold"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
514 m_boldCtrl
->SetValue(false);
515 m_boldCtrl
->SetHelpText(_("Check to make the font bold."));
517 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
518 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
520 m_italicCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_ITALIC
, _("Italic"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
521 m_italicCtrl
->SetValue(false);
522 m_italicCtrl
->SetHelpText(_("Check to make the font italic."));
524 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
525 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
527 if (m_fontData
.GetEnableEffects())
529 m_underlinedCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_UNDERLINED
, _("Underlined"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
530 m_underlinedCtrl
->SetValue(false);
531 m_underlinedCtrl
->SetHelpText(_("Check to make the font underlined."));
533 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
534 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
537 if (m_fontData
.GetEnableEffects())
539 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
540 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
542 m_colourCtrl
= new wxFontColourSwatchCtrl( itemDialog1
, wxID_FONTDIALOG_COLOUR
, wxDefaultPosition
, wxSize(-1, 30), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
543 m_colourCtrl
->SetHelpText(_("Click to change the font colour."));
545 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
546 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
549 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
550 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
552 m_previewCtrl
= new wxFontPreviewCtrl( itemDialog1
, wxID_FONTDIALOG_PREVIEW
, wxDefaultPosition
, wxSize(-1, 70), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
553 m_previewCtrl
->SetHelpText(_("Shows a preview of the font."));
555 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
556 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
558 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
559 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
561 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
562 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
564 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
565 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
567 wxButton
* itemButton21
= new wxButton( itemDialog1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
568 itemButton21
->SetDefault();
569 itemButton21
->SetHelpText(_("Click to confirm changes to the font."));
571 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
572 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
574 wxFontEnumerator enumerator
;
575 enumerator
.EnumerateFacenames();
576 wxArrayString facenames
= enumerator
.GetFacenames();
579 facenames
.Add(_("<Any>"));
580 facenames
.Add(_("<Any Roman>"));
581 facenames
.Add(_("<Any Decorative>"));
582 facenames
.Add(_("<Any Modern>"));
583 facenames
.Add(_("<Any Script>"));
584 facenames
.Add(_("<Any Swiss>"));
585 facenames
.Add(_("<Any Teletype>"));
587 m_facenameCtrl
->Append(facenames
);
590 InitializeControls();
591 m_previewCtrl
->SetFont(m_dialogFont
);
592 if (m_fontData
.GetColour().Ok())
594 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
596 m_previewCtrl
->Refresh();
600 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
603 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
609 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
612 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
618 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
621 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
627 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
630 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
636 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
639 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
645 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
648 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
655 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
658 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
663 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
665 m_fontData
.SetColour(m_colourCtrl
->GetColour());
666 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
667 m_previewCtrl
->Refresh();
671 * Should we show tooltips?
674 bool wxFontDialog::ShowToolTips()
679 void wxFontDialog::InitializeFont()
681 int fontFamily
= wxSWISS
;
682 int fontWeight
= wxNORMAL
;
683 int fontStyle
= wxNORMAL
;
685 bool fontUnderline
= false;
688 if (m_fontData
.m_initialFont
.Ok())
690 fontFamily
= m_fontData
.m_initialFont
.GetFamily();
691 fontWeight
= m_fontData
.m_initialFont
.GetWeight();
692 fontStyle
= m_fontData
.m_initialFont
.GetStyle();
693 fontSize
= m_fontData
.m_initialFont
.GetPointSize();
694 fontUnderline
= m_fontData
.m_initialFont
.GetUnderlined();
695 fontName
= m_fontData
.m_initialFont
.GetFaceName();
698 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
699 fontWeight
, fontUnderline
, fontName
);
702 m_previewCtrl
->SetFont(m_dialogFont
);
704 m_fontData
.SetChosenFont(m_dialogFont
);
707 /// Set controls according to current font
708 void wxFontDialog::InitializeControls()
710 m_suppressUpdates
= true;
712 if (m_underlinedCtrl
)
713 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
715 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
716 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
717 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
719 wxString facename
= m_dialogFont
.GetFaceName();
720 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
722 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
724 m_facenameCtrl
->SetStringSelection(facename
);
726 if (m_colourCtrl
&& m_fontData
.GetColour().Ok())
728 m_colourCtrl
->SetColour(m_fontData
.GetColour());
729 m_colourCtrl
->Refresh();
732 m_suppressUpdates
= false;
735 /// Respond to font change
736 void wxFontDialog::ChangeFont()
738 if (m_suppressUpdates
)
741 bool underlined
= m_underlinedCtrl
? m_underlinedCtrl
->GetValue() : false;
742 bool italic
= m_italicCtrl
->GetValue();
743 bool bold
= m_boldCtrl
->GetValue();
744 int size
= m_sizeCtrl
->GetValue();
745 wxString facename
= m_facenameCtrl
->GetStringSelection();
747 int family
= FontFamilyStringToInt(facename
);
751 facename
= wxEmptyString
;
753 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
754 underlined
, facename
);
756 m_fontData
.SetChosenFont(m_dialogFont
);
758 m_previewCtrl
->SetFont(m_dialogFont
);
759 m_previewCtrl
->Refresh();
762 void wxFontDialog::SetData(const wxFontData
& fontdata
)
764 m_fontData
= fontdata
;
767 bool wxFontDialog::IsShown() const
772 int wxFontDialog::ShowModal()
774 return wxDialog::ShowModal();
777 void wxFontDialog::OnPanelClose()
781 const wxChar
*FontFamilyIntToString(int family
)
786 return _("<Any Roman>");
788 return _("<Any Decorative>");
790 return _("<Any Modern>");
792 return _("<Any Script>");
794 return _("<Any Teletype>");
797 return _("<Any Swiss>");
801 int FontFamilyStringToInt(const wxChar
*family
)
806 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
808 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
810 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
812 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
814 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
816 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
821 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
823 #endif // wxMAC_USE_EXPERIMENTAL_FONTDIALOG
825 #endif // wxUSE_FONTDLG