1 /////////////////////////////////////////////////////////////////////////////
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"
42 #include "wx/dcclient.h"
44 #if wxMAC_USE_EXPERIMENTAL_FONTDIALOG
46 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
48 #include "wx/mac/private.h"
50 // ---------------------------------------------------------------------------
52 // ---------------------------------------------------------------------------
54 static const EventTypeSpec eventList
[] =
56 { kEventClassFont
, kEventFontSelection
} ,
60 pascal OSStatus
wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler
, EventRef event
, void *userData
)
62 OSStatus result
= eventNotHandledErr
;
63 wxFontDialog
*fontdialog
= (wxFontDialog
*) userData
;
64 wxFontData
& fontdata
= fontdialog
->GetFontData() ;
66 wxMacCarbonEvent
cEvent( event
);
67 switch(cEvent
.GetKind())
69 case kEventFontSelection
:
72 if ( cEvent
.GetParameter
<ATSUFontID
>(kEventParamATSUFontID
, &fontId
) == noErr
)
74 FMFontStyle fontStyle
= cEvent
.GetParameter
<FMFontStyle
>(kEventParamFMFontStyle
);
75 FMFontSize fontSize
= cEvent
.GetParameter
<FMFontSize
>(kEventParamFMFontSize
);
77 ByteCount actualLength
= 0;
78 CFStringRef cfName
= NULL
;
80 OSStatus err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
81 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
85 char *c
= (char*)malloc( actualLength
);
86 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
87 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
88 cfName
= CFStringCreateWithCharacters(NULL
, (UniChar
*) c
, (actualLength
-1) >> 1);
92 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
93 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
97 c
= (char*)malloc(actualLength
);
98 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
99 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
100 c
[actualLength
-1] = 0;
101 cfName
= CFStringCreateWithCString(NULL
, c
, kCFStringEncodingMacRoman
);
109 fontdata
.m_chosenFont
.SetFaceName(wxMacCFStringHolder(cfName
).AsString(wxLocale::GetSystemEncoding()));
110 fontdata
.m_chosenFont
.SetPointSize(fontSize
);
111 fontdata
.m_chosenFont
.SetStyle(fontStyle
& italic
? wxFONTSTYLE_ITALIC
: 0);
112 fontdata
.m_chosenFont
.SetUnderlined(fontStyle
& underline
? wxFONTSTYLE_ITALIC
: 0);
113 fontdata
.m_chosenFont
.SetWeight(fontStyle
& bold
? wxBOLD
: wxNORMAL
);
118 if ( cEvent
.GetParameter
<RGBColor
>(kEventParamFontColor
, &fontColor
) == noErr
)
119 fontdata
.m_fontColour
.Set((WXCOLORREF
*) &fontColor
);
122 CFDictionaryRef dict
;
123 if ( cEvent
.GetParameter
<CFDictionaryRef
>(kEventParamDictionary
, &dict
) == noErr
)
125 CFDictionaryRef attributesDict
;
126 if ( CFDictionaryGetValueIfPresent(dict
, kFontPanelAttributesKey
, (const void **)&attributesDict
) )
130 CFDataRef valuesData
;
131 if ( CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeTagsKey
, (const void **)&tagsData
) &&
132 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeSizesKey
, (const void **)&sizesData
) &&
133 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeValuesKey
, (const void **)&valuesData
) )
135 ItemCount count
= CFDataGetLength(tagsData
)/sizeof(ATSUAttributeTag
);
136 ATSUAttributeTag
*tagPtr
= (ATSUAttributeTag
*)CFDataGetBytePtr(tagsData
);
137 ByteCount
*sizePtr
= (ByteCount
*)CFDataGetBytePtr(sizesData
);
138 UInt32
*bytePtr
= (UInt32
*)CFDataGetBytePtr(valuesData
);
139 ATSUAttributeValuePtr valuesPtr
= bytePtr
;
140 for ( ItemCount i
= 0 ; i
< count
; ++i
)
142 if ( tagPtr
[i
] == kATSUColorTag
&& sizePtr
[i
] == sizeof(RGBColor
))
144 fontdata
.m_fontColour
.Set((WXCOLORREF
*) valuesPtr
);
147 bytePtr
= (UInt32
*)( (UInt8
*)bytePtr
+ sizePtr
[i
]);
160 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler
)
162 wxFontDialog::wxFontDialog()
166 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
168 Create(parent
, data
);
171 wxFontDialog::~wxFontDialog()
175 bool wxFontDialog::Create(wxWindow
*parent
, const wxFontData
& data
)
181 int wxFontDialog::ShowModal()
184 wxFont font
= *wxNORMAL_FONT
;
185 if ( m_fontData
.m_initialFont
.Ok() )
187 font
= m_fontData
.m_initialFont
;
190 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
191 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
192 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
193 // that field is already correct
194 m_fontData
.m_chosenFont
= font
;
196 EventHandlerRef handler
;
198 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
200 if ( !FPIsFontPanelVisible() )
201 FPShowHideFontPanel();
203 int retval
= RunMixedFontDialog(this);
205 ::RemoveEventHandler(handler
);
212 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
216 #include "wx/mac/fontdlg.h"
218 #include "wx/fontenum.h"
219 #include "wx/colordlg.h"
220 #include "wx/spinctrl.h"
222 // ---------------------------------------------------------------------------
223 // wxFontDialog stub for mac OS's without a native font dialog
224 // ---------------------------------------------------------------------------
226 static const wxChar
*FontFamilyIntToString(int family
);
227 static int FontFamilyStringToInt(const wxChar
*family
);
230 //-----------------------------------------------------------------------------
231 // helper class - wxFontPreviewCtrl
232 //-----------------------------------------------------------------------------
234 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
237 wxFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
238 wxWindow(parent
, id
, pos
, sz
, style
)
240 SetBackgroundColour(*wxWHITE
);
244 void OnPaint(wxPaintEvent
& event
);
245 DECLARE_EVENT_TABLE()
248 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
249 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
252 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
256 wxSize size
= GetSize();
257 wxFont font
= GetFont();
262 // Calculate vertical centre
264 dc
.GetTextExtent( wxT("X"), &w
, &h
);
265 dc
.SetTextForeground(GetForegroundColour());
266 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
267 dc
.DrawText(_("ABCDEFGabcdefg12345"),
269 dc
.DestroyClippingRegion();
274 * A control for displaying a small preview of a colour or bitmap
277 class wxFontColourSwatchCtrl
: public wxControl
279 DECLARE_CLASS(wxFontColourSwatchCtrl
)
281 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
282 ~wxFontColourSwatchCtrl();
284 void OnPaint(wxPaintEvent
& event
);
285 void OnMouseEvent(wxMouseEvent
& event
);
287 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
289 wxColour
& GetColour() { return m_colour
; }
291 virtual wxSize
DoGetBestSize() const { return GetSize(); }
296 DECLARE_EVENT_TABLE()
300 * A control for displaying a small preview of a colour or bitmap
303 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
304 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
307 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
309 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
310 wxControl(parent
, id
, pos
, size
, style
)
312 SetColour(* wxWHITE
);
313 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
316 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
320 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
322 if (event
.LeftDown())
324 wxWindow
* parent
= GetParent();
325 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
326 parent
= parent
->GetParent();
329 data
.SetChooseFull(TRUE
);
330 data
.SetColour(m_colour
);
331 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
332 // Crashes on wxMac (no m_peer)
334 dialog
->SetTitle(_("Background colour"));
336 if (dialog
->ShowModal() == wxID_OK
)
338 wxColourData retData
= dialog
->GetColourData();
339 m_colour
= retData
.GetColour();
340 SetBackgroundColour(m_colour
);
345 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
346 GetEventHandler()->ProcessEvent(event
);
351 * wxFontDialog type definition
354 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
357 * wxFontDialog event table definition
360 BEGIN_EVENT_TABLE( wxFontDialog
, wxDialog
)
361 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME
, wxFontDialog::OnFontdialogFacenameSelected
)
362 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeUpdated
)
363 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeTextUpdated
)
364 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD
, wxFontDialog::OnFontdialogBoldClick
)
365 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC
, wxFontDialog::OnFontdialogItalicClick
)
366 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED
, wxFontDialog::OnFontdialogUnderlinedClick
)
367 EVT_BUTTON( wxID_OK
, wxFontDialog::OnOkClick
)
368 EVT_BUTTON(wxID_FONTDIALOG_COLOUR
, wxFontDialog::OnColourChanged
)
372 * wxFontDialog constructors
375 wxFontDialog::wxFontDialog( )
377 m_dialogParent
= NULL
;
380 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
382 m_dialogParent
= NULL
;
384 Create(parent
, fontData
);
387 wxFontDialog::~wxFontDialog()
393 * wxFontDialog creator
396 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
398 m_fontData
= fontData
;
399 m_suppressUpdates
= false;
401 wxString caption
= _("Font");
403 m_facenameCtrl
= NULL
;
407 m_underlinedCtrl
= NULL
;
409 m_previewCtrl
= NULL
;
413 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
414 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
417 GetSizer()->Fit(this);
418 GetSizer()->SetSizeHints(this);
425 * Control creation for wxFontDialog
428 void wxFontDialog::CreateControls()
430 wxFontDialog
* itemDialog1
= this;
432 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
433 itemDialog1
->SetSizer(itemBoxSizer2
);
435 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
436 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
438 wxFlexGridSizer
* itemFlexGridSizer4
= new wxFlexGridSizer(6, 2, 10, 0);
439 itemFlexGridSizer4
->AddGrowableRow(4);
440 itemFlexGridSizer4
->AddGrowableCol(1);
441 itemBoxSizer3
->Add(itemFlexGridSizer4
, 1, wxGROW
|wxALL
, 5);
443 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
444 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
446 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
447 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
|wxGROW
, 5);
449 wxString
* m_facenameCtrlStrings
= NULL
;
450 m_facenameCtrl
= new wxListBox( itemDialog1
, wxID_FONTDIALOG_FACENAME
, wxDefaultPosition
, wxSize(320, 100), 0, m_facenameCtrlStrings
, wxLB_SINGLE
);
451 itemBoxSizer6
->Add(m_facenameCtrl
, 0, wxGROW
|wxALL
, 5);
453 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
454 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
|wxADJUST_MINSIZE
, 5);
456 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, _T("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
457 m_sizeCtrl
->SetHelpText(_("The font size in points."));
459 m_sizeCtrl
->SetToolTip(_("The font size in points."));
460 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
462 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
463 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
|wxADJUST_MINSIZE
, 5);
465 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
466 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
468 m_boldCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_BOLD
, _("Bold"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
469 m_boldCtrl
->SetValue(false);
470 m_boldCtrl
->SetHelpText(_("Check to make the font bold."));
472 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
473 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
475 m_italicCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_ITALIC
, _("Italic"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
476 m_italicCtrl
->SetValue(false);
477 m_italicCtrl
->SetHelpText(_("Check to make the font italic."));
479 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
480 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
482 if (m_fontData
.GetEnableEffects())
484 m_underlinedCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_UNDERLINED
, _("Underlined"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
485 m_underlinedCtrl
->SetValue(false);
486 m_underlinedCtrl
->SetHelpText(_("Check to make the font underlined."));
488 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
489 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
492 if (m_fontData
.GetEnableEffects())
494 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
495 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
497 m_colourCtrl
= new wxFontColourSwatchCtrl( itemDialog1
, wxID_FONTDIALOG_COLOUR
, wxDefaultPosition
, wxSize(-1, 30), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
498 m_colourCtrl
->SetHelpText(_("Click to change the font colour."));
500 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
501 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
504 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
505 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
507 m_previewCtrl
= new wxFontPreviewCtrl( itemDialog1
, wxID_FONTDIALOG_PREVIEW
, wxDefaultPosition
, wxSize(-1, 70), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
508 m_previewCtrl
->SetHelpText(_("Shows a preview of the font."));
510 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
511 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
513 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
514 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
516 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
517 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
519 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
520 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
522 wxButton
* itemButton21
= new wxButton( itemDialog1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
523 itemButton21
->SetDefault();
524 itemButton21
->SetHelpText(_("Click to confirm changes to the font."));
526 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
527 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
529 wxFontEnumerator enumerator
;
530 enumerator
.EnumerateFacenames();
531 wxArrayString
* facenames
= enumerator
.GetFacenames();
534 facenames
->Add(_("<Any>"));
535 facenames
->Add(_("<Any Roman>"));
536 facenames
->Add(_("<Any Decorative>"));
537 facenames
->Add(_("<Any Modern>"));
538 facenames
->Add(_("<Any Script>"));
539 facenames
->Add(_("<Any Swiss>"));
540 facenames
->Add(_("<Any Teletype>"));
542 m_facenameCtrl
->Append(*facenames
);
545 InitializeControls();
546 m_previewCtrl
->SetFont(m_dialogFont
);
547 if (m_fontData
.GetColour().Ok())
549 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
551 m_previewCtrl
->Refresh();
555 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
558 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
564 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
567 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
573 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
576 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
582 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
585 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
591 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
594 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
600 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
603 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
610 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
613 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
618 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
620 m_fontData
.SetColour(m_colourCtrl
->GetColour());
621 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
622 m_previewCtrl
->Refresh();
626 * Should we show tooltips?
629 bool wxFontDialog::ShowToolTips()
634 void wxFontDialog::InitializeFont()
636 int fontFamily
= wxSWISS
;
637 int fontWeight
= wxNORMAL
;
638 int fontStyle
= wxNORMAL
;
640 bool fontUnderline
= false;
643 if (m_fontData
.m_initialFont
.Ok())
645 fontFamily
= m_fontData
.m_initialFont
.GetFamily();
646 fontWeight
= m_fontData
.m_initialFont
.GetWeight();
647 fontStyle
= m_fontData
.m_initialFont
.GetStyle();
648 fontSize
= m_fontData
.m_initialFont
.GetPointSize();
649 fontUnderline
= m_fontData
.m_initialFont
.GetUnderlined();
650 fontName
= m_fontData
.m_initialFont
.GetFaceName();
653 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
654 fontWeight
, fontUnderline
, fontName
);
657 m_previewCtrl
->SetFont(m_dialogFont
);
659 m_fontData
.SetChosenFont(m_dialogFont
);
662 /// Set controls according to current font
663 void wxFontDialog::InitializeControls()
665 m_suppressUpdates
= true;
667 if (m_underlinedCtrl
)
668 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
670 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
671 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
672 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
674 wxString facename
= m_dialogFont
.GetFaceName();
675 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
677 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
679 m_facenameCtrl
->SetStringSelection(facename
);
681 if (m_colourCtrl
&& m_fontData
.GetColour().Ok())
683 m_colourCtrl
->SetColour(m_fontData
.GetColour());
684 m_colourCtrl
->Refresh();
687 m_suppressUpdates
= false;
690 /// Respond to font change
691 void wxFontDialog::ChangeFont()
693 if (m_suppressUpdates
)
696 bool underlined
= m_underlinedCtrl
? m_underlinedCtrl
->GetValue() : false;
697 bool italic
= m_italicCtrl
->GetValue();
698 bool bold
= m_boldCtrl
->GetValue();
699 int size
= m_sizeCtrl
->GetValue();
700 wxString facename
= m_facenameCtrl
->GetStringSelection();
702 int family
= FontFamilyStringToInt(facename
);
706 facename
= wxEmptyString
;
708 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
709 underlined
, facename
);
711 m_fontData
.SetChosenFont(m_dialogFont
);
713 m_previewCtrl
->SetFont(m_dialogFont
);
714 m_previewCtrl
->Refresh();
717 void wxFontDialog::SetData(const wxFontData
& fontdata
)
719 m_fontData
= fontdata
;
722 bool wxFontDialog::IsShown() const
727 int wxFontDialog::ShowModal()
729 return wxDialog::ShowModal();
732 void wxFontDialog::OnPanelClose()
736 const wxChar
*FontFamilyIntToString(int family
)
741 return _("<Any Roman>");
743 return _("<Any Decorative>");
745 return _("<Any Modern>");
747 return _("<Any Script>");
749 return _("<Any Teletype>");
752 return _("<Any Swiss>");
756 int FontFamilyStringToInt(const wxChar
*family
)
761 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
763 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
765 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
767 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
769 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
771 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
776 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX