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"
31 #include "wx/wxchar.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/private.h"
51 // ---------------------------------------------------------------------------
53 // ---------------------------------------------------------------------------
55 static const EventTypeSpec eventList
[] =
57 { kEventClassFont
, kEventFontSelection
} ,
61 pascal OSStatus
wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler
, EventRef event
, void *userData
)
63 OSStatus result
= eventNotHandledErr
;
64 wxFontDialog
*fontdialog
= (wxFontDialog
*) userData
;
65 wxFontData
& fontdata
= fontdialog
->GetFontData() ;
67 wxMacCarbonEvent
cEvent( event
);
68 switch(cEvent
.GetKind())
70 case kEventFontSelection
:
72 ATSUFontID fontId
= 0 ;
73 if ( cEvent
.GetParameter
<ATSUFontID
>(kEventParamATSUFontID
, &fontId
) == noErr
)
75 FMFontStyle fontStyle
= cEvent
.GetParameter
<FMFontStyle
>(kEventParamFMFontStyle
);
76 FMFontSize fontSize
= cEvent
.GetParameter
<FMFontSize
>(kEventParamFMFontSize
);
78 CFStringRef cfName
= NULL
;
80 FMFontFamily fontFamily
= cEvent
.GetParameter
<FMFontFamily
>(kEventParamFMFontFamily
);
81 ATSFontFamilyRef atsfontfamilyref
= FMGetATSFontFamilyRefFromFontFamily( fontFamily
) ;
82 OSStatus err
= ATSFontFamilyGetName( atsfontfamilyref
, kATSOptionFlagsDefault
, &cfName
) ;
83 wxASSERT_MSG( err
== noErr
, wxT("ATSFontFamilyGetName failed") );
85 // we don't use the ATSU naming anymore
86 ByteCount actualLength
= 0;
88 OSStatus err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
89 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
93 char *c
= (char*)malloc( actualLength
);
94 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
95 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
96 cfName
= CFStringCreateWithCharacters(NULL
, (UniChar
*) c
, (actualLength
-1) >> 1);
100 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
101 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
105 c
= (char*)malloc(actualLength
);
106 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
107 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
108 c
[actualLength
-1] = 0;
109 cfName
= CFStringCreateWithCString(NULL
, c
, kCFStringEncodingMacRoman
);
118 fontdata
.m_chosenFont
.SetFaceName(wxMacCFStringHolder(cfName
).AsString(wxLocale::GetSystemEncoding()));
119 fontdata
.m_chosenFont
.SetPointSize(fontSize
);
120 fontdata
.m_chosenFont
.SetStyle(fontStyle
& italic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
);
121 fontdata
.m_chosenFont
.SetUnderlined((fontStyle
& underline
)!=0);
122 fontdata
.m_chosenFont
.SetWeight(fontStyle
& bold
? wxFONTWEIGHT_BOLD
: wxFONTWEIGHT_NORMAL
);
127 if ( cEvent
.GetParameter
<RGBColor
>(kEventParamFontColor
, &fontColor
) == noErr
)
128 fontdata
.m_fontColour
.FromRGBColor((WXCOLORREF
*) &fontColor
);
131 CFDictionaryRef dict
;
132 if ( cEvent
.GetParameter
<CFDictionaryRef
>(kEventParamDictionary
, &dict
) == noErr
)
134 CFDictionaryRef attributesDict
;
135 if ( CFDictionaryGetValueIfPresent(dict
, kFontPanelAttributesKey
, (const void **)&attributesDict
) )
139 CFDataRef valuesData
;
140 if ( CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeTagsKey
, (const void **)&tagsData
) &&
141 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeSizesKey
, (const void **)&sizesData
) &&
142 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeValuesKey
, (const void **)&valuesData
) )
144 ItemCount count
= CFDataGetLength(tagsData
)/sizeof(ATSUAttributeTag
);
145 ATSUAttributeTag
*tagPtr
= (ATSUAttributeTag
*)CFDataGetBytePtr(tagsData
);
146 ByteCount
*sizePtr
= (ByteCount
*)CFDataGetBytePtr(sizesData
);
147 UInt32
*bytePtr
= (UInt32
*)CFDataGetBytePtr(valuesData
);
148 ATSUAttributeValuePtr valuesPtr
= bytePtr
;
149 for ( ItemCount i
= 0 ; i
< count
; ++i
)
151 if ( tagPtr
[i
] == kATSUColorTag
&& sizePtr
[i
] == sizeof(RGBColor
))
153 fontdata
.m_fontColour
.FromRGBColor((WXCOLORREF
*) valuesPtr
);
156 bytePtr
= (UInt32
*)( (UInt8
*)bytePtr
+ sizePtr
[i
]);
169 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler
)
171 wxFontDialog::wxFontDialog()
175 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
177 Create(parent
, data
);
180 wxFontDialog::~wxFontDialog()
184 bool wxFontDialog::Create(wxWindow
*parent
, const wxFontData
& data
)
190 int wxFontDialog::ShowModal()
193 wxFont font
= *wxNORMAL_FONT
;
194 if ( m_fontData
.m_initialFont
.Ok() )
196 font
= m_fontData
.m_initialFont
;
199 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
200 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
201 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
202 // that field is already correct
203 m_fontData
.m_chosenFont
= font
;
205 EventHandlerRef handler
;
207 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
209 if ( !FPIsFontPanelVisible() )
210 FPShowHideFontPanel();
212 int retval
= RunMixedFontDialog(this);
214 ::RemoveEventHandler(handler
);
221 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
225 #include "wx/mac/fontdlg.h"
227 #include "wx/fontenum.h"
228 #include "wx/colordlg.h"
229 #include "wx/spinctrl.h"
231 // ---------------------------------------------------------------------------
232 // wxFontDialog stub for mac OS's without a native font dialog
233 // ---------------------------------------------------------------------------
235 static const wxChar
*FontFamilyIntToString(int family
);
236 static int FontFamilyStringToInt(const wxChar
*family
);
239 //-----------------------------------------------------------------------------
240 // helper class - wxFontPreviewCtrl
241 //-----------------------------------------------------------------------------
243 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
246 wxFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
247 wxWindow(parent
, id
, pos
, sz
, style
)
249 SetBackgroundColour(*wxWHITE
);
253 void OnPaint(wxPaintEvent
& event
);
254 DECLARE_EVENT_TABLE()
257 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
258 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
261 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
265 wxSize size
= GetSize();
266 wxFont font
= GetFont();
271 // Calculate vertical centre
273 dc
.GetTextExtent( wxT("X"), &w
, &h
);
274 dc
.SetTextForeground(GetForegroundColour());
275 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
276 dc
.DrawText(_("ABCDEFGabcdefg12345"),
278 dc
.DestroyClippingRegion();
283 * A control for displaying a small preview of a colour or bitmap
286 class wxFontColourSwatchCtrl
: public wxControl
288 DECLARE_CLASS(wxFontColourSwatchCtrl
)
290 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
291 virtual ~wxFontColourSwatchCtrl();
293 void OnPaint(wxPaintEvent
& event
);
294 void OnMouseEvent(wxMouseEvent
& event
);
296 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
298 wxColour
& GetColour() { return m_colour
; }
300 virtual wxSize
DoGetBestSize() const { return GetSize(); }
305 DECLARE_EVENT_TABLE()
309 * A control for displaying a small preview of a colour or bitmap
312 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
313 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
316 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
318 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
319 wxControl(parent
, id
, pos
, size
, style
)
321 SetColour(* wxWHITE
);
322 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
325 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
329 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
331 if (event
.LeftDown())
333 wxWindow
* parent
= GetParent();
334 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
335 parent
= parent
->GetParent();
338 data
.SetChooseFull(true);
339 data
.SetColour(m_colour
);
340 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
341 // Crashes on wxMac (no m_peer)
343 dialog
->SetTitle(_("Background colour"));
345 if (dialog
->ShowModal() == wxID_OK
)
347 wxColourData retData
= dialog
->GetColourData();
348 m_colour
= retData
.GetColour();
349 SetBackgroundColour(m_colour
);
354 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
355 GetEventHandler()->ProcessEvent(event
);
360 * wxFontDialog type definition
363 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
366 * wxFontDialog event table definition
369 BEGIN_EVENT_TABLE( wxFontDialog
, wxDialog
)
370 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME
, wxFontDialog::OnFontdialogFacenameSelected
)
371 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeUpdated
)
372 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeTextUpdated
)
373 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD
, wxFontDialog::OnFontdialogBoldClick
)
374 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC
, wxFontDialog::OnFontdialogItalicClick
)
375 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED
, wxFontDialog::OnFontdialogUnderlinedClick
)
376 EVT_BUTTON( wxID_OK
, wxFontDialog::OnOkClick
)
377 EVT_BUTTON(wxID_FONTDIALOG_COLOUR
, wxFontDialog::OnColourChanged
)
381 * wxFontDialog constructors
384 wxFontDialog::wxFontDialog( )
386 m_dialogParent
= NULL
;
389 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
391 m_dialogParent
= NULL
;
393 Create(parent
, fontData
);
396 wxFontDialog::~wxFontDialog()
402 * wxFontDialog creator
405 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
407 m_fontData
= fontData
;
408 m_suppressUpdates
= false;
410 wxString caption
= _("Font");
412 m_facenameCtrl
= NULL
;
416 m_underlinedCtrl
= NULL
;
418 m_previewCtrl
= NULL
;
422 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
423 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
426 GetSizer()->Fit(this);
427 GetSizer()->SetSizeHints(this);
434 * Control creation for wxFontDialog
437 void wxFontDialog::CreateControls()
439 wxFontDialog
* itemDialog1
= this;
441 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
442 itemDialog1
->SetSizer(itemBoxSizer2
);
444 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
445 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
447 wxFlexGridSizer
* itemFlexGridSizer4
= new wxFlexGridSizer(6, 2, 10, 0);
448 itemFlexGridSizer4
->AddGrowableRow(4);
449 itemFlexGridSizer4
->AddGrowableCol(1);
450 itemBoxSizer3
->Add(itemFlexGridSizer4
, 1, wxGROW
|wxALL
, 5);
452 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
453 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
455 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
456 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
|wxGROW
, 5);
458 wxString
* m_facenameCtrlStrings
= NULL
;
459 m_facenameCtrl
= new wxListBox( itemDialog1
, wxID_FONTDIALOG_FACENAME
, wxDefaultPosition
, wxSize(320, 100), 0, m_facenameCtrlStrings
, wxLB_SINGLE
);
460 itemBoxSizer6
->Add(m_facenameCtrl
, 0, wxGROW
|wxALL
, 5);
462 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
463 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
|wxADJUST_MINSIZE
, 5);
465 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, _T("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
466 m_sizeCtrl
->SetHelpText(_("The font size in points."));
468 m_sizeCtrl
->SetToolTip(_("The font size in points."));
469 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
471 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
472 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
|wxADJUST_MINSIZE
, 5);
474 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
475 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
477 m_boldCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_BOLD
, _("Bold"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
478 m_boldCtrl
->SetValue(false);
479 m_boldCtrl
->SetHelpText(_("Check to make the font bold."));
481 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
482 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
484 m_italicCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_ITALIC
, _("Italic"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
485 m_italicCtrl
->SetValue(false);
486 m_italicCtrl
->SetHelpText(_("Check to make the font italic."));
488 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
489 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
491 if (m_fontData
.GetEnableEffects())
493 m_underlinedCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_UNDERLINED
, _("Underlined"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
494 m_underlinedCtrl
->SetValue(false);
495 m_underlinedCtrl
->SetHelpText(_("Check to make the font underlined."));
497 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
498 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
501 if (m_fontData
.GetEnableEffects())
503 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
504 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
506 m_colourCtrl
= new wxFontColourSwatchCtrl( itemDialog1
, wxID_FONTDIALOG_COLOUR
, wxDefaultPosition
, wxSize(-1, 30), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
507 m_colourCtrl
->SetHelpText(_("Click to change the font colour."));
509 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
510 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
513 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
514 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
516 m_previewCtrl
= new wxFontPreviewCtrl( itemDialog1
, wxID_FONTDIALOG_PREVIEW
, wxDefaultPosition
, wxSize(-1, 70), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
517 m_previewCtrl
->SetHelpText(_("Shows a preview of the font."));
519 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
520 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
522 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
523 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
525 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
526 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
528 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
529 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
531 wxButton
* itemButton21
= new wxButton( itemDialog1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
532 itemButton21
->SetDefault();
533 itemButton21
->SetHelpText(_("Click to confirm changes to the font."));
535 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
536 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
538 wxFontEnumerator enumerator
;
539 enumerator
.EnumerateFacenames();
540 wxArrayString facenames
= enumerator
.GetFacenames();
543 facenames
.Add(_("<Any>"));
544 facenames
.Add(_("<Any Roman>"));
545 facenames
.Add(_("<Any Decorative>"));
546 facenames
.Add(_("<Any Modern>"));
547 facenames
.Add(_("<Any Script>"));
548 facenames
.Add(_("<Any Swiss>"));
549 facenames
.Add(_("<Any Teletype>"));
551 m_facenameCtrl
->Append(facenames
);
554 InitializeControls();
555 m_previewCtrl
->SetFont(m_dialogFont
);
556 if (m_fontData
.GetColour().Ok())
558 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
560 m_previewCtrl
->Refresh();
564 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
567 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
573 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
576 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
582 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
585 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
591 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
594 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
600 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
603 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
609 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
612 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
619 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
622 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
627 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
629 m_fontData
.SetColour(m_colourCtrl
->GetColour());
630 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
631 m_previewCtrl
->Refresh();
635 * Should we show tooltips?
638 bool wxFontDialog::ShowToolTips()
643 void wxFontDialog::InitializeFont()
645 int fontFamily
= wxSWISS
;
646 int fontWeight
= wxNORMAL
;
647 int fontStyle
= wxNORMAL
;
649 bool fontUnderline
= false;
652 if (m_fontData
.m_initialFont
.Ok())
654 fontFamily
= m_fontData
.m_initialFont
.GetFamily();
655 fontWeight
= m_fontData
.m_initialFont
.GetWeight();
656 fontStyle
= m_fontData
.m_initialFont
.GetStyle();
657 fontSize
= m_fontData
.m_initialFont
.GetPointSize();
658 fontUnderline
= m_fontData
.m_initialFont
.GetUnderlined();
659 fontName
= m_fontData
.m_initialFont
.GetFaceName();
662 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
663 fontWeight
, fontUnderline
, fontName
);
666 m_previewCtrl
->SetFont(m_dialogFont
);
668 m_fontData
.SetChosenFont(m_dialogFont
);
671 /// Set controls according to current font
672 void wxFontDialog::InitializeControls()
674 m_suppressUpdates
= true;
676 if (m_underlinedCtrl
)
677 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
679 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
680 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
681 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
683 wxString facename
= m_dialogFont
.GetFaceName();
684 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
686 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
688 m_facenameCtrl
->SetStringSelection(facename
);
690 if (m_colourCtrl
&& m_fontData
.GetColour().Ok())
692 m_colourCtrl
->SetColour(m_fontData
.GetColour());
693 m_colourCtrl
->Refresh();
696 m_suppressUpdates
= false;
699 /// Respond to font change
700 void wxFontDialog::ChangeFont()
702 if (m_suppressUpdates
)
705 bool underlined
= m_underlinedCtrl
? m_underlinedCtrl
->GetValue() : false;
706 bool italic
= m_italicCtrl
->GetValue();
707 bool bold
= m_boldCtrl
->GetValue();
708 int size
= m_sizeCtrl
->GetValue();
709 wxString facename
= m_facenameCtrl
->GetStringSelection();
711 int family
= FontFamilyStringToInt(facename
);
715 facename
= wxEmptyString
;
717 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
718 underlined
, facename
);
720 m_fontData
.SetChosenFont(m_dialogFont
);
722 m_previewCtrl
->SetFont(m_dialogFont
);
723 m_previewCtrl
->Refresh();
726 void wxFontDialog::SetData(const wxFontData
& fontdata
)
728 m_fontData
= fontdata
;
731 bool wxFontDialog::IsShown() const
736 int wxFontDialog::ShowModal()
738 return wxDialog::ShowModal();
741 void wxFontDialog::OnPanelClose()
745 const wxChar
*FontFamilyIntToString(int family
)
750 return _("<Any Roman>");
752 return _("<Any Decorative>");
754 return _("<Any Modern>");
756 return _("<Any Script>");
758 return _("<Any Teletype>");
761 return _("<Any Swiss>");
765 int FontFamilyStringToInt(const wxChar
*family
)
770 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
772 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
774 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
776 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
778 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
780 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
785 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
787 #endif // wxMAC_USE_EXPERIMENTAL_FONTDIALOG
789 #endif // wxUSE_FONTDLG