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"
28 #include "wx/cmndata.h"
31 #include "wx/fontdlg.h"
33 #if wxMAC_USE_EXPERIMENTAL_FONTDIALOG
35 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
37 #include "wx/mac/private.h"
39 // ---------------------------------------------------------------------------
41 // ---------------------------------------------------------------------------
43 static const EventTypeSpec eventList
[] =
45 { kEventClassFont
, kEventFontSelection
} ,
49 pascal OSStatus
wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler
, EventRef event
, void *userData
)
51 OSStatus result
= eventNotHandledErr
;
52 wxFontDialog
*fontdialog
= (wxFontDialog
*) userData
;
53 wxFontData
& fontdata
= fontdialog
->GetFontData() ;
55 wxMacCarbonEvent
cEvent( event
);
56 switch(cEvent
.GetKind())
58 case kEventFontSelection
:
61 if ( cEvent
.GetParameter
<ATSUFontID
>(kEventParamATSUFontID
, &fontId
) == noErr
)
63 FMFontStyle fontStyle
= cEvent
.GetParameter
<FMFontStyle
>(kEventParamFMFontStyle
);
64 FMFontSize fontSize
= cEvent
.GetParameter
<FMFontSize
>(kEventParamFMFontSize
);
66 ByteCount actualLength
= 0;
67 CFStringRef cfName
= NULL
;
69 OSStatus err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
70 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
74 char *c
= (char*)malloc( actualLength
);
75 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
76 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
77 cfName
= CFStringCreateWithCharacters(NULL
, (UniChar
*) c
, (actualLength
-1) >> 1);
81 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
82 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
86 c
= (char*)malloc(actualLength
);
87 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
88 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
89 c
[actualLength
-1] = 0;
90 cfName
= CFStringCreateWithCString(NULL
, c
, kCFStringEncodingMacRoman
);
98 fontdata
.m_chosenFont
.SetFaceName(wxMacCFStringHolder(cfName
).AsString(wxLocale::GetSystemEncoding()));
99 fontdata
.m_chosenFont
.SetPointSize(fontSize
);
100 fontdata
.m_chosenFont
.SetStyle(fontStyle
& italic
? wxFONTSTYLE_ITALIC
: 0);
101 fontdata
.m_chosenFont
.SetUnderlined(fontStyle
& underline
? wxFONTSTYLE_ITALIC
: 0);
102 fontdata
.m_chosenFont
.SetWeight(fontStyle
& bold
? wxBOLD
: wxNORMAL
);
107 if ( cEvent
.GetParameter
<RGBColor
>(kEventParamFontColor
, &fontColor
) == noErr
)
108 fontdata
.m_fontColour
.Set((WXCOLORREF
*) &fontColor
);
111 CFDictionaryRef dict
;
112 if ( cEvent
.GetParameter
<CFDictionaryRef
>(kEventParamDictionary
, &dict
) == noErr
)
114 CFDictionaryRef attributesDict
;
115 if ( CFDictionaryGetValueIfPresent(dict
, kFontPanelAttributesKey
, (const void **)&attributesDict
) )
119 CFDataRef valuesData
;
120 if ( CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeTagsKey
, (const void **)&tagsData
) &&
121 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeSizesKey
, (const void **)&sizesData
) &&
122 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeValuesKey
, (const void **)&valuesData
) )
124 ItemCount count
= CFDataGetLength(tagsData
)/sizeof(ATSUAttributeTag
);
125 ATSUAttributeTag
*tagPtr
= (ATSUAttributeTag
*)CFDataGetBytePtr(tagsData
);
126 ByteCount
*sizePtr
= (ByteCount
*)CFDataGetBytePtr(sizesData
);
127 UInt32
*bytePtr
= (UInt32
*)CFDataGetBytePtr(valuesData
);
128 ATSUAttributeValuePtr valuesPtr
= bytePtr
;
129 for ( ItemCount i
= 0 ; i
< count
; ++i
)
131 if ( tagPtr
[i
] == kATSUColorTag
&& sizePtr
[i
] == sizeof(RGBColor
))
133 fontdata
.m_fontColour
.Set((WXCOLORREF
*) valuesPtr
);
136 bytePtr
= (UInt32
*)( (UInt8
*)bytePtr
+ sizePtr
[i
]);
149 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler
)
151 wxFontDialog::wxFontDialog()
155 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
157 Create(parent
, data
);
160 wxFontDialog::~wxFontDialog()
164 bool wxFontDialog::Create(wxWindow
*parent
, const wxFontData
& data
)
170 int wxFontDialog::ShowModal()
173 wxFont font
= *wxNORMAL_FONT
;
174 if ( m_fontData
.m_initialFont
.Ok() )
176 font
= m_fontData
.m_initialFont
;
179 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
180 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
181 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
182 // that field is already correct
183 m_fontData
.m_chosenFont
= font
;
185 EventHandlerRef handler
;
187 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
189 if ( !FPIsFontPanelVisible() )
190 FPShowHideFontPanel();
192 int retval
= RunMixedFontDialog(this);
194 ::RemoveEventHandler(handler
);
201 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
205 #include "wx/mac/fontdlg.h"
207 #include "wx/fontenum.h"
208 #include "wx/colordlg.h"
209 #include "wx/spinctrl.h"
211 // ---------------------------------------------------------------------------
212 // wxFontDialog stub for mac OS's without a native font dialog
213 // ---------------------------------------------------------------------------
215 static const wxChar
*FontFamilyIntToString(int family
);
216 static int FontFamilyStringToInt(const wxChar
*family
);
219 //-----------------------------------------------------------------------------
220 // helper class - wxFontPreviewCtrl
221 //-----------------------------------------------------------------------------
223 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
226 wxFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
227 wxWindow(parent
, id
, pos
, sz
, style
)
229 SetBackgroundColour(*wxWHITE
);
233 void OnPaint(wxPaintEvent
& event
);
234 DECLARE_EVENT_TABLE()
237 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
238 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
241 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
245 wxSize size
= GetSize();
246 wxFont font
= GetFont();
251 // Calculate vertical centre
253 dc
.GetTextExtent( wxT("X"), &w
, &h
);
254 dc
.SetTextForeground(GetForegroundColour());
255 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
256 dc
.DrawText(_("ABCDEFGabcdefg12345"),
258 dc
.DestroyClippingRegion();
263 * A control for displaying a small preview of a colour or bitmap
266 class wxFontColourSwatchCtrl
: public wxControl
268 DECLARE_CLASS(wxFontColourSwatchCtrl
)
270 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
271 ~wxFontColourSwatchCtrl();
273 void OnPaint(wxPaintEvent
& event
);
274 void OnMouseEvent(wxMouseEvent
& event
);
276 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
278 wxColour
& GetColour() { return m_colour
; }
280 virtual wxSize
DoGetBestSize() const { return GetSize(); }
285 DECLARE_EVENT_TABLE()
289 * A control for displaying a small preview of a colour or bitmap
292 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
293 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
296 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
298 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
299 wxControl(parent
, id
, pos
, size
, style
)
301 SetColour(* wxWHITE
);
302 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
305 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
309 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
311 if (event
.LeftDown())
313 wxWindow
* parent
= GetParent();
314 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
315 parent
= parent
->GetParent();
318 data
.SetChooseFull(TRUE
);
319 data
.SetColour(m_colour
);
320 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
321 // Crashes on wxMac (no m_peer)
323 dialog
->SetTitle(_("Background colour"));
325 if (dialog
->ShowModal() == wxID_OK
)
327 wxColourData retData
= dialog
->GetColourData();
328 m_colour
= retData
.GetColour();
329 SetBackgroundColour(m_colour
);
334 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
335 GetEventHandler()->ProcessEvent(event
);
340 * wxFontDialog type definition
343 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
346 * wxFontDialog event table definition
349 BEGIN_EVENT_TABLE( wxFontDialog
, wxDialog
)
350 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME
, wxFontDialog::OnFontdialogFacenameSelected
)
351 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeUpdated
)
352 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeTextUpdated
)
353 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD
, wxFontDialog::OnFontdialogBoldClick
)
354 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC
, wxFontDialog::OnFontdialogItalicClick
)
355 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED
, wxFontDialog::OnFontdialogUnderlinedClick
)
356 EVT_BUTTON( wxID_OK
, wxFontDialog::OnOkClick
)
357 EVT_BUTTON(wxID_FONTDIALOG_COLOUR
, wxFontDialog::OnColourChanged
)
361 * wxFontDialog constructors
364 wxFontDialog::wxFontDialog( )
366 m_dialogParent
= NULL
;
369 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
371 m_dialogParent
= NULL
;
373 Create(parent
, fontData
);
376 wxFontDialog::~wxFontDialog()
382 * wxFontDialog creator
385 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
387 m_fontData
= fontData
;
388 m_suppressUpdates
= false;
390 wxString caption
= _("Font");
392 m_facenameCtrl
= NULL
;
396 m_underlinedCtrl
= NULL
;
398 m_previewCtrl
= NULL
;
402 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
403 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
406 GetSizer()->Fit(this);
407 GetSizer()->SetSizeHints(this);
414 * Control creation for wxFontDialog
417 void wxFontDialog::CreateControls()
419 wxFontDialog
* itemDialog1
= this;
421 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
422 itemDialog1
->SetSizer(itemBoxSizer2
);
424 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
425 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
427 wxFlexGridSizer
* itemFlexGridSizer4
= new wxFlexGridSizer(6, 2, 10, 0);
428 itemFlexGridSizer4
->AddGrowableRow(4);
429 itemFlexGridSizer4
->AddGrowableCol(1);
430 itemBoxSizer3
->Add(itemFlexGridSizer4
, 1, wxGROW
|wxALL
, 5);
432 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
433 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
435 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
436 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
|wxGROW
, 5);
438 wxString
* m_facenameCtrlStrings
= NULL
;
439 m_facenameCtrl
= new wxListBox( itemDialog1
, wxID_FONTDIALOG_FACENAME
, wxDefaultPosition
, wxSize(320, 100), 0, m_facenameCtrlStrings
, wxLB_SINGLE
);
440 itemBoxSizer6
->Add(m_facenameCtrl
, 0, wxGROW
|wxALL
, 5);
442 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
443 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
|wxADJUST_MINSIZE
, 5);
445 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, _T("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
446 m_sizeCtrl
->SetHelpText(_("The font size in points."));
448 m_sizeCtrl
->SetToolTip(_("The font size in points."));
449 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
451 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
452 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
|wxADJUST_MINSIZE
, 5);
454 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
455 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
457 m_boldCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_BOLD
, _("Bold"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
458 m_boldCtrl
->SetValue(false);
459 m_boldCtrl
->SetHelpText(_("Check to make the font bold."));
461 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
462 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
464 m_italicCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_ITALIC
, _("Italic"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
465 m_italicCtrl
->SetValue(false);
466 m_italicCtrl
->SetHelpText(_("Check to make the font italic."));
468 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
469 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
471 if (m_fontData
.GetEnableEffects())
473 m_underlinedCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_UNDERLINED
, _("Underlined"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
474 m_underlinedCtrl
->SetValue(false);
475 m_underlinedCtrl
->SetHelpText(_("Check to make the font underlined."));
477 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
478 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
481 if (m_fontData
.GetEnableEffects())
483 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
484 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
486 m_colourCtrl
= new wxFontColourSwatchCtrl( itemDialog1
, wxID_FONTDIALOG_COLOUR
, wxDefaultPosition
, wxSize(-1, 30), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
487 m_colourCtrl
->SetHelpText(_("Click to change the font colour."));
489 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
490 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
493 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
494 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
496 m_previewCtrl
= new wxFontPreviewCtrl( itemDialog1
, wxID_FONTDIALOG_PREVIEW
, wxDefaultPosition
, wxSize(-1, 70), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
497 m_previewCtrl
->SetHelpText(_("Shows a preview of the font."));
499 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
500 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
502 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
503 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
505 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
506 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
508 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
509 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
511 wxButton
* itemButton21
= new wxButton( itemDialog1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
512 itemButton21
->SetDefault();
513 itemButton21
->SetHelpText(_("Click to confirm changes to the font."));
515 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
516 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
518 wxFontEnumerator enumerator
;
519 enumerator
.EnumerateFacenames();
520 wxArrayString
* facenames
= enumerator
.GetFacenames();
523 facenames
->Add(_("<Any>"));
524 facenames
->Add(_("<Any Roman>"));
525 facenames
->Add(_("<Any Decorative>"));
526 facenames
->Add(_("<Any Modern>"));
527 facenames
->Add(_("<Any Script>"));
528 facenames
->Add(_("<Any Swiss>"));
529 facenames
->Add(_("<Any Teletype>"));
531 m_facenameCtrl
->Append(*facenames
);
534 InitializeControls();
535 m_previewCtrl
->SetFont(m_dialogFont
);
536 if (m_fontData
.GetColour().Ok())
538 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
540 m_previewCtrl
->Refresh();
544 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
547 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
553 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
556 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
562 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
565 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
571 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
574 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
580 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
583 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
589 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
592 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
599 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
602 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
607 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
609 m_fontData
.SetColour(m_colourCtrl
->GetColour());
610 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
611 m_previewCtrl
->Refresh();
615 * Should we show tooltips?
618 bool wxFontDialog::ShowToolTips()
623 void wxFontDialog::InitializeFont()
625 int fontFamily
= wxSWISS
;
626 int fontWeight
= wxNORMAL
;
627 int fontStyle
= wxNORMAL
;
629 bool fontUnderline
= false;
632 if (m_fontData
.m_initialFont
.Ok())
634 fontFamily
= m_fontData
.m_initialFont
.GetFamily();
635 fontWeight
= m_fontData
.m_initialFont
.GetWeight();
636 fontStyle
= m_fontData
.m_initialFont
.GetStyle();
637 fontSize
= m_fontData
.m_initialFont
.GetPointSize();
638 fontUnderline
= m_fontData
.m_initialFont
.GetUnderlined();
639 fontName
= m_fontData
.m_initialFont
.GetFaceName();
642 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
643 fontWeight
, fontUnderline
, fontName
);
646 m_previewCtrl
->SetFont(m_dialogFont
);
648 m_fontData
.SetChosenFont(m_dialogFont
);
651 /// Set controls according to current font
652 void wxFontDialog::InitializeControls()
654 m_suppressUpdates
= true;
656 if (m_underlinedCtrl
)
657 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
659 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
660 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
661 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
663 wxString facename
= m_dialogFont
.GetFaceName();
664 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
666 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
668 m_facenameCtrl
->SetStringSelection(facename
);
670 if (m_colourCtrl
&& m_fontData
.GetColour().Ok())
672 m_colourCtrl
->SetColour(m_fontData
.GetColour());
673 m_colourCtrl
->Refresh();
676 m_suppressUpdates
= false;
679 /// Respond to font change
680 void wxFontDialog::ChangeFont()
682 if (m_suppressUpdates
)
685 bool underlined
= m_underlinedCtrl
? m_underlinedCtrl
->GetValue() : false;
686 bool italic
= m_italicCtrl
->GetValue();
687 bool bold
= m_boldCtrl
->GetValue();
688 int size
= m_sizeCtrl
->GetValue();
689 wxString facename
= m_facenameCtrl
->GetStringSelection();
691 int family
= FontFamilyStringToInt(facename
);
695 facename
= wxEmptyString
;
697 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
698 underlined
, facename
);
700 m_fontData
.SetChosenFont(m_dialogFont
);
702 m_previewCtrl
->SetFont(m_dialogFont
);
703 m_previewCtrl
->Refresh();
706 void wxFontDialog::SetData(const wxFontData
& fontdata
)
708 m_fontData
= fontdata
;
711 bool wxFontDialog::IsShown() const
716 int wxFontDialog::ShowModal()
718 return wxDialog::ShowModal();
721 void wxFontDialog::OnPanelClose()
725 const wxChar
*FontFamilyIntToString(int family
)
730 return _("<Any Roman>");
732 return _("<Any Decorative>");
734 return _("<Any Modern>");
736 return _("<Any Script>");
738 return _("<Any Teletype>");
741 return _("<Any Swiss>");
745 int FontFamilyStringToInt(const wxChar
*family
)
750 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
752 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
754 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
756 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
758 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
760 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
765 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX