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"
29 #include "wx/wxchar.h"
30 #include "wx/dcclient.h"
32 #include "wx/textctrl.h"
33 #include "wx/listbox.h"
34 #include "wx/checkbox.h"
35 #include "wx/choice.h"
37 #include "wx/stattext.h"
38 #include "wx/button.h"
41 #include "wx/fontdlg.h"
43 #if wxMAC_USE_EXPERIMENTAL_FONTDIALOG
45 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
47 #include "wx/mac/private.h"
49 // ---------------------------------------------------------------------------
51 // ---------------------------------------------------------------------------
53 static const EventTypeSpec eventList
[] =
55 { kEventClassFont
, kEventFontSelection
} ,
59 pascal OSStatus
wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler
, EventRef event
, void *userData
)
61 OSStatus result
= eventNotHandledErr
;
62 wxFontDialog
*fontdialog
= (wxFontDialog
*) userData
;
63 wxFontData
& fontdata
= fontdialog
->GetFontData() ;
65 wxMacCarbonEvent
cEvent( event
);
66 switch(cEvent
.GetKind())
68 case kEventFontSelection
:
71 if ( cEvent
.GetParameter
<ATSUFontID
>(kEventParamATSUFontID
, &fontId
) == noErr
)
73 FMFontStyle fontStyle
= cEvent
.GetParameter
<FMFontStyle
>(kEventParamFMFontStyle
);
74 FMFontSize fontSize
= cEvent
.GetParameter
<FMFontSize
>(kEventParamFMFontSize
);
76 ByteCount actualLength
= 0;
77 CFStringRef cfName
= NULL
;
79 OSStatus err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
80 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
84 char *c
= (char*)malloc( actualLength
);
85 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
86 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
87 cfName
= CFStringCreateWithCharacters(NULL
, (UniChar
*) c
, (actualLength
-1) >> 1);
91 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
92 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
96 c
= (char*)malloc(actualLength
);
97 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
98 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
99 c
[actualLength
-1] = 0;
100 cfName
= CFStringCreateWithCString(NULL
, c
, kCFStringEncodingMacRoman
);
108 fontdata
.m_chosenFont
.SetFaceName(wxMacCFStringHolder(cfName
).AsString(wxLocale::GetSystemEncoding()));
109 fontdata
.m_chosenFont
.SetPointSize(fontSize
);
110 fontdata
.m_chosenFont
.SetStyle(fontStyle
& italic
? wxFONTSTYLE_ITALIC
: 0);
111 fontdata
.m_chosenFont
.SetUnderlined(fontStyle
& underline
? wxFONTSTYLE_ITALIC
: 0);
112 fontdata
.m_chosenFont
.SetWeight(fontStyle
& bold
? wxBOLD
: wxNORMAL
);
117 if ( cEvent
.GetParameter
<RGBColor
>(kEventParamFontColor
, &fontColor
) == noErr
)
118 fontdata
.m_fontColour
.FromRGBColor((WXCOLORREF
*) &fontColor
);
121 CFDictionaryRef dict
;
122 if ( cEvent
.GetParameter
<CFDictionaryRef
>(kEventParamDictionary
, &dict
) == noErr
)
124 CFDictionaryRef attributesDict
;
125 if ( CFDictionaryGetValueIfPresent(dict
, kFontPanelAttributesKey
, (const void **)&attributesDict
) )
129 CFDataRef valuesData
;
130 if ( CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeTagsKey
, (const void **)&tagsData
) &&
131 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeSizesKey
, (const void **)&sizesData
) &&
132 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeValuesKey
, (const void **)&valuesData
) )
134 ItemCount count
= CFDataGetLength(tagsData
)/sizeof(ATSUAttributeTag
);
135 ATSUAttributeTag
*tagPtr
= (ATSUAttributeTag
*)CFDataGetBytePtr(tagsData
);
136 ByteCount
*sizePtr
= (ByteCount
*)CFDataGetBytePtr(sizesData
);
137 UInt32
*bytePtr
= (UInt32
*)CFDataGetBytePtr(valuesData
);
138 ATSUAttributeValuePtr valuesPtr
= bytePtr
;
139 for ( ItemCount i
= 0 ; i
< count
; ++i
)
141 if ( tagPtr
[i
] == kATSUColorTag
&& sizePtr
[i
] == sizeof(RGBColor
))
143 fontdata
.m_fontColour
.FromRGBColor((WXCOLORREF
*) valuesPtr
);
146 bytePtr
= (UInt32
*)( (UInt8
*)bytePtr
+ sizePtr
[i
]);
159 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler
)
161 wxFontDialog::wxFontDialog()
165 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
167 Create(parent
, data
);
170 wxFontDialog::~wxFontDialog()
174 bool wxFontDialog::Create(wxWindow
*parent
, const wxFontData
& data
)
180 int wxFontDialog::ShowModal()
183 wxFont font
= *wxNORMAL_FONT
;
184 if ( m_fontData
.m_initialFont
.Ok() )
186 font
= m_fontData
.m_initialFont
;
189 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
190 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
191 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
192 // that field is already correct
193 m_fontData
.m_chosenFont
= font
;
195 EventHandlerRef handler
;
197 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
199 if ( !FPIsFontPanelVisible() )
200 FPShowHideFontPanel();
202 int retval
= RunMixedFontDialog(this);
204 ::RemoveEventHandler(handler
);
211 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
215 #include "wx/mac/fontdlg.h"
217 #include "wx/fontenum.h"
218 #include "wx/colordlg.h"
219 #include "wx/spinctrl.h"
221 // ---------------------------------------------------------------------------
222 // wxFontDialog stub for mac OS's without a native font dialog
223 // ---------------------------------------------------------------------------
225 static const wxChar
*FontFamilyIntToString(int family
);
226 static int FontFamilyStringToInt(const wxChar
*family
);
229 //-----------------------------------------------------------------------------
230 // helper class - wxFontPreviewCtrl
231 //-----------------------------------------------------------------------------
233 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
236 wxFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
237 wxWindow(parent
, id
, pos
, sz
, style
)
239 SetBackgroundColour(*wxWHITE
);
243 void OnPaint(wxPaintEvent
& event
);
244 DECLARE_EVENT_TABLE()
247 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
248 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
251 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
255 wxSize size
= GetSize();
256 wxFont font
= GetFont();
261 // Calculate vertical centre
263 dc
.GetTextExtent( wxT("X"), &w
, &h
);
264 dc
.SetTextForeground(GetForegroundColour());
265 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
266 dc
.DrawText(_("ABCDEFGabcdefg12345"),
268 dc
.DestroyClippingRegion();
273 * A control for displaying a small preview of a colour or bitmap
276 class wxFontColourSwatchCtrl
: public wxControl
278 DECLARE_CLASS(wxFontColourSwatchCtrl
)
280 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
281 ~wxFontColourSwatchCtrl();
283 void OnPaint(wxPaintEvent
& event
);
284 void OnMouseEvent(wxMouseEvent
& event
);
286 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
288 wxColour
& GetColour() { return m_colour
; }
290 virtual wxSize
DoGetBestSize() const { return GetSize(); }
295 DECLARE_EVENT_TABLE()
299 * A control for displaying a small preview of a colour or bitmap
302 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
303 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
306 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
308 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
309 wxControl(parent
, id
, pos
, size
, style
)
311 SetColour(* wxWHITE
);
312 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
315 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
319 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
321 if (event
.LeftDown())
323 wxWindow
* parent
= GetParent();
324 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
325 parent
= parent
->GetParent();
328 data
.SetChooseFull(true);
329 data
.SetColour(m_colour
);
330 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
331 // Crashes on wxMac (no m_peer)
333 dialog
->SetTitle(_("Background colour"));
335 if (dialog
->ShowModal() == wxID_OK
)
337 wxColourData retData
= dialog
->GetColourData();
338 m_colour
= retData
.GetColour();
339 SetBackgroundColour(m_colour
);
344 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
345 GetEventHandler()->ProcessEvent(event
);
350 * wxFontDialog type definition
353 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
356 * wxFontDialog event table definition
359 BEGIN_EVENT_TABLE( wxFontDialog
, wxDialog
)
360 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME
, wxFontDialog::OnFontdialogFacenameSelected
)
361 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeUpdated
)
362 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeTextUpdated
)
363 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD
, wxFontDialog::OnFontdialogBoldClick
)
364 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC
, wxFontDialog::OnFontdialogItalicClick
)
365 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED
, wxFontDialog::OnFontdialogUnderlinedClick
)
366 EVT_BUTTON( wxID_OK
, wxFontDialog::OnOkClick
)
367 EVT_BUTTON(wxID_FONTDIALOG_COLOUR
, wxFontDialog::OnColourChanged
)
371 * wxFontDialog constructors
374 wxFontDialog::wxFontDialog( )
376 m_dialogParent
= NULL
;
379 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
381 m_dialogParent
= NULL
;
383 Create(parent
, fontData
);
386 wxFontDialog::~wxFontDialog()
392 * wxFontDialog creator
395 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
397 m_fontData
= fontData
;
398 m_suppressUpdates
= false;
400 wxString caption
= _("Font");
402 m_facenameCtrl
= NULL
;
406 m_underlinedCtrl
= NULL
;
408 m_previewCtrl
= NULL
;
412 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
413 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
416 GetSizer()->Fit(this);
417 GetSizer()->SetSizeHints(this);
424 * Control creation for wxFontDialog
427 void wxFontDialog::CreateControls()
429 wxFontDialog
* itemDialog1
= this;
431 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
432 itemDialog1
->SetSizer(itemBoxSizer2
);
434 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
435 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
437 wxFlexGridSizer
* itemFlexGridSizer4
= new wxFlexGridSizer(6, 2, 10, 0);
438 itemFlexGridSizer4
->AddGrowableRow(4);
439 itemFlexGridSizer4
->AddGrowableCol(1);
440 itemBoxSizer3
->Add(itemFlexGridSizer4
, 1, wxGROW
|wxALL
, 5);
442 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
443 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
445 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
446 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
|wxGROW
, 5);
448 wxString
* m_facenameCtrlStrings
= NULL
;
449 m_facenameCtrl
= new wxListBox( itemDialog1
, wxID_FONTDIALOG_FACENAME
, wxDefaultPosition
, wxSize(320, 100), 0, m_facenameCtrlStrings
, wxLB_SINGLE
);
450 itemBoxSizer6
->Add(m_facenameCtrl
, 0, wxGROW
|wxALL
, 5);
452 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
453 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
|wxADJUST_MINSIZE
, 5);
455 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, _T("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
456 m_sizeCtrl
->SetHelpText(_("The font size in points."));
458 m_sizeCtrl
->SetToolTip(_("The font size in points."));
459 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
461 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
462 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
|wxADJUST_MINSIZE
, 5);
464 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
465 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
467 m_boldCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_BOLD
, _("Bold"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
468 m_boldCtrl
->SetValue(false);
469 m_boldCtrl
->SetHelpText(_("Check to make the font bold."));
471 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
472 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
474 m_italicCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_ITALIC
, _("Italic"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
475 m_italicCtrl
->SetValue(false);
476 m_italicCtrl
->SetHelpText(_("Check to make the font italic."));
478 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
479 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
481 if (m_fontData
.GetEnableEffects())
483 m_underlinedCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_UNDERLINED
, _("Underlined"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
484 m_underlinedCtrl
->SetValue(false);
485 m_underlinedCtrl
->SetHelpText(_("Check to make the font underlined."));
487 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
488 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
491 if (m_fontData
.GetEnableEffects())
493 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
494 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
496 m_colourCtrl
= new wxFontColourSwatchCtrl( itemDialog1
, wxID_FONTDIALOG_COLOUR
, wxDefaultPosition
, wxSize(-1, 30), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
497 m_colourCtrl
->SetHelpText(_("Click to change the font colour."));
499 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
500 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
503 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
504 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
506 m_previewCtrl
= new wxFontPreviewCtrl( itemDialog1
, wxID_FONTDIALOG_PREVIEW
, wxDefaultPosition
, wxSize(-1, 70), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
507 m_previewCtrl
->SetHelpText(_("Shows a preview of the font."));
509 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
510 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
512 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
513 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
515 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
516 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
518 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
519 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
521 wxButton
* itemButton21
= new wxButton( itemDialog1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
522 itemButton21
->SetDefault();
523 itemButton21
->SetHelpText(_("Click to confirm changes to the font."));
525 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
526 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
528 wxFontEnumerator enumerator
;
529 enumerator
.EnumerateFacenames();
530 wxArrayString
* facenames
= enumerator
.GetFacenames();
533 facenames
->Add(_("<Any>"));
534 facenames
->Add(_("<Any Roman>"));
535 facenames
->Add(_("<Any Decorative>"));
536 facenames
->Add(_("<Any Modern>"));
537 facenames
->Add(_("<Any Script>"));
538 facenames
->Add(_("<Any Swiss>"));
539 facenames
->Add(_("<Any Teletype>"));
541 m_facenameCtrl
->Append(*facenames
);
544 InitializeControls();
545 m_previewCtrl
->SetFont(m_dialogFont
);
546 if (m_fontData
.GetColour().Ok())
548 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
550 m_previewCtrl
->Refresh();
554 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
557 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
563 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
566 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
572 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
575 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
581 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
584 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
590 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
593 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
599 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
602 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
609 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
612 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
617 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
619 m_fontData
.SetColour(m_colourCtrl
->GetColour());
620 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
621 m_previewCtrl
->Refresh();
625 * Should we show tooltips?
628 bool wxFontDialog::ShowToolTips()
633 void wxFontDialog::InitializeFont()
635 int fontFamily
= wxSWISS
;
636 int fontWeight
= wxNORMAL
;
637 int fontStyle
= wxNORMAL
;
639 bool fontUnderline
= false;
642 if (m_fontData
.m_initialFont
.Ok())
644 fontFamily
= m_fontData
.m_initialFont
.GetFamily();
645 fontWeight
= m_fontData
.m_initialFont
.GetWeight();
646 fontStyle
= m_fontData
.m_initialFont
.GetStyle();
647 fontSize
= m_fontData
.m_initialFont
.GetPointSize();
648 fontUnderline
= m_fontData
.m_initialFont
.GetUnderlined();
649 fontName
= m_fontData
.m_initialFont
.GetFaceName();
652 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
653 fontWeight
, fontUnderline
, fontName
);
656 m_previewCtrl
->SetFont(m_dialogFont
);
658 m_fontData
.SetChosenFont(m_dialogFont
);
661 /// Set controls according to current font
662 void wxFontDialog::InitializeControls()
664 m_suppressUpdates
= true;
666 if (m_underlinedCtrl
)
667 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
669 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
670 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
671 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
673 wxString facename
= m_dialogFont
.GetFaceName();
674 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
676 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
678 m_facenameCtrl
->SetStringSelection(facename
);
680 if (m_colourCtrl
&& m_fontData
.GetColour().Ok())
682 m_colourCtrl
->SetColour(m_fontData
.GetColour());
683 m_colourCtrl
->Refresh();
686 m_suppressUpdates
= false;
689 /// Respond to font change
690 void wxFontDialog::ChangeFont()
692 if (m_suppressUpdates
)
695 bool underlined
= m_underlinedCtrl
? m_underlinedCtrl
->GetValue() : false;
696 bool italic
= m_italicCtrl
->GetValue();
697 bool bold
= m_boldCtrl
->GetValue();
698 int size
= m_sizeCtrl
->GetValue();
699 wxString facename
= m_facenameCtrl
->GetStringSelection();
701 int family
= FontFamilyStringToInt(facename
);
705 facename
= wxEmptyString
;
707 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
708 underlined
, facename
);
710 m_fontData
.SetChosenFont(m_dialogFont
);
712 m_previewCtrl
->SetFont(m_dialogFont
);
713 m_previewCtrl
->Refresh();
716 void wxFontDialog::SetData(const wxFontData
& fontdata
)
718 m_fontData
= fontdata
;
721 bool wxFontDialog::IsShown() const
726 int wxFontDialog::ShowModal()
728 return wxDialog::ShowModal();
731 void wxFontDialog::OnPanelClose()
735 const wxChar
*FontFamilyIntToString(int family
)
740 return _("<Any Roman>");
742 return _("<Any Decorative>");
744 return _("<Any Modern>");
746 return _("<Any Script>");
748 return _("<Any Teletype>");
751 return _("<Any Swiss>");
755 int FontFamilyStringToInt(const wxChar
*family
)
760 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
762 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
764 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
766 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
768 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
770 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
775 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX