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
)
129 fontdata
.m_fontColour
= fontColor
;
133 CFDictionaryRef dict
;
134 if ( cEvent
.GetParameter
<CFDictionaryRef
>(kEventParamDictionary
, &dict
) == noErr
)
136 CFDictionaryRef attributesDict
;
137 if ( CFDictionaryGetValueIfPresent(dict
, kFontPanelAttributesKey
, (const void **)&attributesDict
) )
141 CFDataRef valuesData
;
142 if ( CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeTagsKey
, (const void **)&tagsData
) &&
143 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeSizesKey
, (const void **)&sizesData
) &&
144 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeValuesKey
, (const void **)&valuesData
) )
146 ItemCount count
= CFDataGetLength(tagsData
)/sizeof(ATSUAttributeTag
);
147 ATSUAttributeTag
*tagPtr
= (ATSUAttributeTag
*)CFDataGetBytePtr(tagsData
);
148 ByteCount
*sizePtr
= (ByteCount
*)CFDataGetBytePtr(sizesData
);
149 UInt32
*bytePtr
= (UInt32
*)CFDataGetBytePtr(valuesData
);
150 ATSUAttributeValuePtr valuesPtr
= bytePtr
;
151 for ( ItemCount i
= 0 ; i
< count
; ++i
)
153 if ( tagPtr
[i
] == kATSUColorTag
&& sizePtr
[i
] == sizeof(RGBColor
))
155 fontdata
.m_fontColour
= *(RGBColor
*)valuesPtr
;
158 bytePtr
= (UInt32
*)( (UInt8
*)bytePtr
+ sizePtr
[i
]);
171 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler
)
173 wxFontDialog::wxFontDialog()
177 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
179 Create(parent
, data
);
182 wxFontDialog::~wxFontDialog()
186 bool wxFontDialog::Create(wxWindow
*parent
, const wxFontData
& data
)
192 int wxFontDialog::ShowModal()
195 wxFont font
= *wxNORMAL_FONT
;
196 if ( m_fontData
.m_initialFont
.Ok() )
198 font
= m_fontData
.m_initialFont
;
201 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
202 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
203 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
204 // that field is already correct
205 m_fontData
.m_chosenFont
= font
;
207 EventHandlerRef handler
;
209 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
211 if ( !FPIsFontPanelVisible() )
212 FPShowHideFontPanel();
214 int retval
= RunMixedFontDialog(this);
216 ::RemoveEventHandler(handler
);
223 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
227 #include "wx/mac/fontdlg.h"
229 #include "wx/fontenum.h"
230 #include "wx/colordlg.h"
231 #include "wx/spinctrl.h"
233 // ---------------------------------------------------------------------------
234 // wxFontDialog stub for mac OS's without a native font dialog
235 // ---------------------------------------------------------------------------
237 static const wxChar
*FontFamilyIntToString(int family
);
238 static int FontFamilyStringToInt(const wxChar
*family
);
241 //-----------------------------------------------------------------------------
242 // helper class - wxFontPreviewCtrl
243 //-----------------------------------------------------------------------------
245 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
248 wxFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
249 wxWindow(parent
, id
, pos
, sz
, style
)
251 SetBackgroundColour(*wxWHITE
);
255 void OnPaint(wxPaintEvent
& event
);
256 DECLARE_EVENT_TABLE()
259 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
260 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
263 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
267 wxSize size
= GetSize();
268 wxFont font
= GetFont();
273 // Calculate vertical centre
275 dc
.GetTextExtent( wxT("X"), &w
, &h
);
276 dc
.SetTextForeground(GetForegroundColour());
277 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
278 dc
.DrawText(_("ABCDEFGabcdefg12345"),
280 dc
.DestroyClippingRegion();
285 * A control for displaying a small preview of a colour or bitmap
288 class wxFontColourSwatchCtrl
: public wxControl
290 DECLARE_CLASS(wxFontColourSwatchCtrl
)
292 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
293 virtual ~wxFontColourSwatchCtrl();
295 void OnPaint(wxPaintEvent
& event
);
296 void OnMouseEvent(wxMouseEvent
& event
);
298 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
300 wxColour
& GetColour() { return m_colour
; }
302 virtual wxSize
DoGetBestSize() const { return GetSize(); }
307 DECLARE_EVENT_TABLE()
311 * A control for displaying a small preview of a colour or bitmap
314 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
315 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
318 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
320 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
321 wxControl(parent
, id
, pos
, size
, style
)
323 SetColour(* wxWHITE
);
324 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
327 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
331 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
333 if (event
.LeftDown())
335 wxWindow
* parent
= GetParent();
336 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
337 parent
= parent
->GetParent();
340 data
.SetChooseFull(true);
341 data
.SetColour(m_colour
);
342 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
343 // Crashes on wxMac (no m_peer)
345 dialog
->SetTitle(_("Background colour"));
347 if (dialog
->ShowModal() == wxID_OK
)
349 wxColourData retData
= dialog
->GetColourData();
350 m_colour
= retData
.GetColour();
351 SetBackgroundColour(m_colour
);
356 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
357 GetEventHandler()->ProcessEvent(event
);
362 * wxFontDialog type definition
365 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
368 * wxFontDialog event table definition
371 BEGIN_EVENT_TABLE( wxFontDialog
, wxDialog
)
372 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME
, wxFontDialog::OnFontdialogFacenameSelected
)
373 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeUpdated
)
374 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeTextUpdated
)
375 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD
, wxFontDialog::OnFontdialogBoldClick
)
376 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC
, wxFontDialog::OnFontdialogItalicClick
)
377 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED
, wxFontDialog::OnFontdialogUnderlinedClick
)
378 EVT_BUTTON( wxID_OK
, wxFontDialog::OnOkClick
)
379 EVT_BUTTON(wxID_FONTDIALOG_COLOUR
, wxFontDialog::OnColourChanged
)
383 * wxFontDialog constructors
386 wxFontDialog::wxFontDialog( )
388 m_dialogParent
= NULL
;
391 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
393 m_dialogParent
= NULL
;
395 Create(parent
, fontData
);
398 wxFontDialog::~wxFontDialog()
404 * wxFontDialog creator
407 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
409 m_fontData
= fontData
;
410 m_suppressUpdates
= false;
412 wxString caption
= _("Font");
414 m_facenameCtrl
= NULL
;
418 m_underlinedCtrl
= NULL
;
420 m_previewCtrl
= NULL
;
424 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
425 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
428 GetSizer()->Fit(this);
429 GetSizer()->SetSizeHints(this);
436 * Control creation for wxFontDialog
439 void wxFontDialog::CreateControls()
441 wxFontDialog
* itemDialog1
= this;
443 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
444 itemDialog1
->SetSizer(itemBoxSizer2
);
446 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
447 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
449 wxFlexGridSizer
* itemFlexGridSizer4
= new wxFlexGridSizer(6, 2, 10, 0);
450 itemFlexGridSizer4
->AddGrowableRow(4);
451 itemFlexGridSizer4
->AddGrowableCol(1);
452 itemBoxSizer3
->Add(itemFlexGridSizer4
, 1, wxGROW
|wxALL
, 5);
454 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
455 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
457 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
458 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
|wxGROW
, 5);
460 wxString
* m_facenameCtrlStrings
= NULL
;
461 m_facenameCtrl
= new wxListBox( itemDialog1
, wxID_FONTDIALOG_FACENAME
, wxDefaultPosition
, wxSize(320, 100), 0, m_facenameCtrlStrings
, wxLB_SINGLE
);
462 itemBoxSizer6
->Add(m_facenameCtrl
, 0, wxGROW
|wxALL
, 5);
464 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
465 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
467 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, _T("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
468 m_sizeCtrl
->SetHelpText(_("The font size in points."));
470 m_sizeCtrl
->SetToolTip(_("The font size in points."));
471 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
473 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
474 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
476 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
477 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
479 m_boldCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_BOLD
, _("Bold"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
480 m_boldCtrl
->SetValue(false);
481 m_boldCtrl
->SetHelpText(_("Check to make the font bold."));
483 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
484 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
486 m_italicCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_ITALIC
, _("Italic"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
487 m_italicCtrl
->SetValue(false);
488 m_italicCtrl
->SetHelpText(_("Check to make the font italic."));
490 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
491 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
493 if (m_fontData
.GetEnableEffects())
495 m_underlinedCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_UNDERLINED
, _("Underlined"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
496 m_underlinedCtrl
->SetValue(false);
497 m_underlinedCtrl
->SetHelpText(_("Check to make the font underlined."));
499 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
500 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
503 if (m_fontData
.GetEnableEffects())
505 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
506 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
508 m_colourCtrl
= new wxFontColourSwatchCtrl( itemDialog1
, wxID_FONTDIALOG_COLOUR
, wxDefaultPosition
, wxSize(-1, 30), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
509 m_colourCtrl
->SetHelpText(_("Click to change the font colour."));
511 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
512 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
515 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
516 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
518 m_previewCtrl
= new wxFontPreviewCtrl( itemDialog1
, wxID_FONTDIALOG_PREVIEW
, wxDefaultPosition
, wxSize(-1, 70), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
519 m_previewCtrl
->SetHelpText(_("Shows a preview of the font."));
521 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
522 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
524 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
525 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
527 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
528 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
530 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
531 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
533 wxButton
* itemButton21
= new wxButton( itemDialog1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
534 itemButton21
->SetDefault();
535 itemButton21
->SetHelpText(_("Click to confirm changes to the font."));
537 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
538 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
540 wxFontEnumerator enumerator
;
541 enumerator
.EnumerateFacenames();
542 wxArrayString facenames
= enumerator
.GetFacenames();
545 facenames
.Add(_("<Any>"));
546 facenames
.Add(_("<Any Roman>"));
547 facenames
.Add(_("<Any Decorative>"));
548 facenames
.Add(_("<Any Modern>"));
549 facenames
.Add(_("<Any Script>"));
550 facenames
.Add(_("<Any Swiss>"));
551 facenames
.Add(_("<Any Teletype>"));
553 m_facenameCtrl
->Append(facenames
);
556 InitializeControls();
557 m_previewCtrl
->SetFont(m_dialogFont
);
558 if (m_fontData
.GetColour().Ok())
560 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
562 m_previewCtrl
->Refresh();
566 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
569 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
575 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
578 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
584 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
587 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
593 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
596 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
602 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
605 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
611 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
614 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
621 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
624 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
629 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
631 m_fontData
.SetColour(m_colourCtrl
->GetColour());
632 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
633 m_previewCtrl
->Refresh();
637 * Should we show tooltips?
640 bool wxFontDialog::ShowToolTips()
645 void wxFontDialog::InitializeFont()
647 int fontFamily
= wxSWISS
;
648 int fontWeight
= wxNORMAL
;
649 int fontStyle
= wxNORMAL
;
651 bool fontUnderline
= false;
654 if (m_fontData
.m_initialFont
.Ok())
656 fontFamily
= m_fontData
.m_initialFont
.GetFamily();
657 fontWeight
= m_fontData
.m_initialFont
.GetWeight();
658 fontStyle
= m_fontData
.m_initialFont
.GetStyle();
659 fontSize
= m_fontData
.m_initialFont
.GetPointSize();
660 fontUnderline
= m_fontData
.m_initialFont
.GetUnderlined();
661 fontName
= m_fontData
.m_initialFont
.GetFaceName();
664 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
665 fontWeight
, fontUnderline
, fontName
);
668 m_previewCtrl
->SetFont(m_dialogFont
);
670 m_fontData
.SetChosenFont(m_dialogFont
);
673 /// Set controls according to current font
674 void wxFontDialog::InitializeControls()
676 m_suppressUpdates
= true;
678 if (m_underlinedCtrl
)
679 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
681 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
682 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
683 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
685 wxString facename
= m_dialogFont
.GetFaceName();
686 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
688 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
690 m_facenameCtrl
->SetStringSelection(facename
);
692 if (m_colourCtrl
&& m_fontData
.GetColour().Ok())
694 m_colourCtrl
->SetColour(m_fontData
.GetColour());
695 m_colourCtrl
->Refresh();
698 m_suppressUpdates
= false;
701 /// Respond to font change
702 void wxFontDialog::ChangeFont()
704 if (m_suppressUpdates
)
707 bool underlined
= m_underlinedCtrl
? m_underlinedCtrl
->GetValue() : false;
708 bool italic
= m_italicCtrl
->GetValue();
709 bool bold
= m_boldCtrl
->GetValue();
710 int size
= m_sizeCtrl
->GetValue();
711 wxString facename
= m_facenameCtrl
->GetStringSelection();
713 int family
= FontFamilyStringToInt(facename
);
717 facename
= wxEmptyString
;
719 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
720 underlined
, facename
);
722 m_fontData
.SetChosenFont(m_dialogFont
);
724 m_previewCtrl
->SetFont(m_dialogFont
);
725 m_previewCtrl
->Refresh();
728 void wxFontDialog::SetData(const wxFontData
& fontdata
)
730 m_fontData
= fontdata
;
733 bool wxFontDialog::IsShown() const
738 int wxFontDialog::ShowModal()
740 return wxDialog::ShowModal();
743 void wxFontDialog::OnPanelClose()
747 const wxChar
*FontFamilyIntToString(int family
)
752 return _("<Any Roman>");
754 return _("<Any Decorative>");
756 return _("<Any Modern>");
758 return _("<Any Script>");
760 return _("<Any Teletype>");
763 return _("<Any Swiss>");
767 int FontFamilyStringToInt(const wxChar
*family
)
772 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
774 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
776 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
778 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
780 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
782 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
787 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
789 #endif // wxMAC_USE_EXPERIMENTAL_FONTDIALOG
791 #endif // wxUSE_FONTDLG