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"
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
} ,
62 wxMacCarbonFontPanelHandler(EventHandlerCallRef
WXUNUSED(nextHandler
),
66 OSStatus result
= eventNotHandledErr
;
67 wxFontDialog
*fontdialog
= (wxFontDialog
*) userData
;
68 wxFontData
& fontdata
= fontdialog
->GetFontData() ;
70 wxMacCarbonEvent
cEvent( event
);
71 switch(cEvent
.GetKind())
73 case kEventFontSelection
:
75 ATSUFontID fontId
= 0 ;
76 if ( cEvent
.GetParameter
<ATSUFontID
>(kEventParamATSUFontID
, &fontId
) == noErr
)
78 FMFontStyle fontStyle
= cEvent
.GetParameter
<FMFontStyle
>(kEventParamFMFontStyle
);
79 FMFontSize fontSize
= cEvent
.GetParameter
<FMFontSize
>(kEventParamFMFontSize
);
81 CFStringRef cfName
= NULL
;
83 FMFontFamily fontFamily
= cEvent
.GetParameter
<FMFontFamily
>(kEventParamFMFontFamily
);
84 ATSFontFamilyRef atsfontfamilyref
= FMGetATSFontFamilyRefFromFontFamily( fontFamily
) ;
85 OSStatus err
= ATSFontFamilyGetName( atsfontfamilyref
, kATSOptionFlagsDefault
, &cfName
) ;
86 wxASSERT_MSG( err
== noErr
, wxT("ATSFontFamilyGetName failed") );
88 // we don't use the ATSU naming anymore
89 ByteCount actualLength
= 0;
91 OSStatus err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
92 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
96 char *c
= (char*)malloc( actualLength
);
97 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
98 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
99 cfName
= CFStringCreateWithCharacters(NULL
, (UniChar
*) c
, (actualLength
-1) >> 1);
103 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
104 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
108 c
= (char*)malloc(actualLength
);
109 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
110 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
111 c
[actualLength
-1] = 0;
112 cfName
= CFStringCreateWithCString(NULL
, c
, kCFStringEncodingMacRoman
);
121 fontdata
.m_chosenFont
.SetFaceName(wxMacCFStringHolder(cfName
).AsString(wxLocale::GetSystemEncoding()));
122 fontdata
.m_chosenFont
.SetPointSize(fontSize
);
123 fontdata
.m_chosenFont
.SetStyle(fontStyle
& italic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
);
124 fontdata
.m_chosenFont
.SetUnderlined((fontStyle
& underline
)!=0);
125 fontdata
.m_chosenFont
.SetWeight(fontStyle
& bold
? wxFONTWEIGHT_BOLD
: wxFONTWEIGHT_NORMAL
);
130 if ( cEvent
.GetParameter
<RGBColor
>(kEventParamFontColor
, &fontColor
) == noErr
)
132 fontdata
.m_fontColour
= fontColor
;
136 CFDictionaryRef dict
;
137 if ( cEvent
.GetParameter
<CFDictionaryRef
>(kEventParamDictionary
, &dict
) == noErr
)
139 CFDictionaryRef attributesDict
;
140 if ( CFDictionaryGetValueIfPresent(dict
, kFontPanelAttributesKey
, (const void **)&attributesDict
) )
144 CFDataRef valuesData
;
145 if ( CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeTagsKey
, (const void **)&tagsData
) &&
146 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeSizesKey
, (const void **)&sizesData
) &&
147 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeValuesKey
, (const void **)&valuesData
) )
149 ItemCount count
= CFDataGetLength(tagsData
)/sizeof(ATSUAttributeTag
);
150 ATSUAttributeTag
*tagPtr
= (ATSUAttributeTag
*)CFDataGetBytePtr(tagsData
);
151 ByteCount
*sizePtr
= (ByteCount
*)CFDataGetBytePtr(sizesData
);
152 UInt32
*bytePtr
= (UInt32
*)CFDataGetBytePtr(valuesData
);
153 ATSUAttributeValuePtr valuesPtr
= bytePtr
;
154 for ( ItemCount i
= 0 ; i
< count
; ++i
)
156 if ( tagPtr
[i
] == kATSUColorTag
&& sizePtr
[i
] == sizeof(RGBColor
))
158 fontdata
.m_fontColour
= *(RGBColor
*)valuesPtr
;
161 bytePtr
= (UInt32
*)( (UInt8
*)bytePtr
+ sizePtr
[i
]);
174 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler
)
176 wxFontDialog::wxFontDialog()
180 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
182 Create(parent
, data
);
185 wxFontDialog::~wxFontDialog()
189 bool wxFontDialog::Create(wxWindow
*WXUNUSED(parent
), const wxFontData
& data
)
195 int wxFontDialog::ShowModal()
198 wxFont font
= *wxNORMAL_FONT
;
199 if ( m_fontData
.m_initialFont
.Ok() )
201 font
= m_fontData
.m_initialFont
;
204 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
205 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
206 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
207 // that field is already correct
208 m_fontData
.m_chosenFont
= font
;
210 EventHandlerRef handler
;
212 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
214 if ( !FPIsFontPanelVisible() )
215 FPShowHideFontPanel();
217 int retval
= RunMixedFontDialog(this);
219 ::RemoveEventHandler(handler
);
226 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
230 #include "wx/mac/fontdlg.h"
232 #include "wx/fontenum.h"
233 #include "wx/colordlg.h"
234 #include "wx/spinctrl.h"
236 // ---------------------------------------------------------------------------
237 // wxFontDialog stub for mac OS's without a native font dialog
238 // ---------------------------------------------------------------------------
240 static const wxChar
*FontFamilyIntToString(int family
);
241 static int FontFamilyStringToInt(const wxChar
*family
);
244 //-----------------------------------------------------------------------------
245 // helper class - wxFontPreviewCtrl
246 //-----------------------------------------------------------------------------
248 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
251 wxFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
252 wxWindow(parent
, id
, pos
, sz
, style
)
254 SetBackgroundColour(*wxWHITE
);
258 void OnPaint(wxPaintEvent
& event
);
259 DECLARE_EVENT_TABLE()
262 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
263 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
266 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
270 wxSize size
= GetSize();
271 wxFont font
= GetFont();
276 // Calculate vertical centre
278 dc
.GetTextExtent( wxT("X"), &w
, &h
);
279 dc
.SetTextForeground(GetForegroundColour());
280 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
281 dc
.DrawText(_("ABCDEFGabcdefg12345"),
283 dc
.DestroyClippingRegion();
288 * A control for displaying a small preview of a colour or bitmap
291 class wxFontColourSwatchCtrl
: public wxControl
293 DECLARE_CLASS(wxFontColourSwatchCtrl
)
295 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
296 virtual ~wxFontColourSwatchCtrl();
298 void OnPaint(wxPaintEvent
& event
);
299 void OnMouseEvent(wxMouseEvent
& event
);
301 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
303 wxColour
& GetColour() { return m_colour
; }
305 virtual wxSize
DoGetBestSize() const { return GetSize(); }
310 DECLARE_EVENT_TABLE()
314 * A control for displaying a small preview of a colour or bitmap
317 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
318 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
321 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
323 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
324 wxControl(parent
, id
, pos
, size
, style
)
326 SetColour(* wxWHITE
);
327 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
330 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
334 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
336 if (event
.LeftDown())
338 wxWindow
* parent
= GetParent();
339 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
340 parent
= parent
->GetParent();
343 data
.SetChooseFull(true);
344 data
.SetColour(m_colour
);
345 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
346 // Crashes on wxMac (no m_peer)
348 dialog
->SetTitle(_("Background colour"));
350 if (dialog
->ShowModal() == wxID_OK
)
352 wxColourData retData
= dialog
->GetColourData();
353 m_colour
= retData
.GetColour();
354 SetBackgroundColour(m_colour
);
359 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
360 GetEventHandler()->ProcessEvent(event
);
365 * wxFontDialog type definition
368 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
371 * wxFontDialog event table definition
374 BEGIN_EVENT_TABLE( wxFontDialog
, wxDialog
)
375 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME
, wxFontDialog::OnFontdialogFacenameSelected
)
376 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeUpdated
)
377 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeTextUpdated
)
378 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD
, wxFontDialog::OnFontdialogBoldClick
)
379 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC
, wxFontDialog::OnFontdialogItalicClick
)
380 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED
, wxFontDialog::OnFontdialogUnderlinedClick
)
381 EVT_BUTTON( wxID_OK
, wxFontDialog::OnOkClick
)
382 EVT_BUTTON(wxID_FONTDIALOG_COLOUR
, wxFontDialog::OnColourChanged
)
386 * wxFontDialog constructors
389 wxFontDialog::wxFontDialog( )
391 m_dialogParent
= NULL
;
394 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
396 m_dialogParent
= NULL
;
398 Create(parent
, fontData
);
401 wxFontDialog::~wxFontDialog()
407 * wxFontDialog creator
410 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
412 m_fontData
= fontData
;
413 m_suppressUpdates
= false;
415 wxString caption
= _("Font");
417 m_facenameCtrl
= NULL
;
421 m_underlinedCtrl
= NULL
;
423 m_previewCtrl
= NULL
;
427 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
428 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
431 GetSizer()->Fit(this);
432 GetSizer()->SetSizeHints(this);
439 * Control creation for wxFontDialog
442 void wxFontDialog::CreateControls()
444 wxFontDialog
* itemDialog1
= this;
446 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
447 itemDialog1
->SetSizer(itemBoxSizer2
);
449 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
450 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
452 wxFlexGridSizer
* itemFlexGridSizer4
= new wxFlexGridSizer(6, 2, 10, 0);
453 itemFlexGridSizer4
->AddGrowableRow(4);
454 itemFlexGridSizer4
->AddGrowableCol(1);
455 itemBoxSizer3
->Add(itemFlexGridSizer4
, 1, wxGROW
|wxALL
, 5);
457 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
458 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
460 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
461 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
|wxGROW
, 5);
463 wxString
* m_facenameCtrlStrings
= NULL
;
464 m_facenameCtrl
= new wxListBox( itemDialog1
, wxID_FONTDIALOG_FACENAME
, wxDefaultPosition
, wxSize(320, 100), 0, m_facenameCtrlStrings
, wxLB_SINGLE
);
465 itemBoxSizer6
->Add(m_facenameCtrl
, 0, wxGROW
|wxALL
, 5);
467 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
468 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
470 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, _T("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
471 m_sizeCtrl
->SetHelpText(_("The font size in points."));
473 m_sizeCtrl
->SetToolTip(_("The font size in points."));
474 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
476 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
477 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
479 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
480 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
482 m_boldCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_BOLD
, _("Bold"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
483 m_boldCtrl
->SetValue(false);
484 m_boldCtrl
->SetHelpText(_("Check to make the font bold."));
486 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
487 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
489 m_italicCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_ITALIC
, _("Italic"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
490 m_italicCtrl
->SetValue(false);
491 m_italicCtrl
->SetHelpText(_("Check to make the font italic."));
493 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
494 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
496 if (m_fontData
.GetEnableEffects())
498 m_underlinedCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_UNDERLINED
, _("Underlined"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
499 m_underlinedCtrl
->SetValue(false);
500 m_underlinedCtrl
->SetHelpText(_("Check to make the font underlined."));
502 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
503 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
506 if (m_fontData
.GetEnableEffects())
508 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
509 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
511 m_colourCtrl
= new wxFontColourSwatchCtrl( itemDialog1
, wxID_FONTDIALOG_COLOUR
, wxDefaultPosition
, wxSize(-1, 30), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
512 m_colourCtrl
->SetHelpText(_("Click to change the font colour."));
514 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
515 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
518 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
519 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
, 5);
521 m_previewCtrl
= new wxFontPreviewCtrl( itemDialog1
, wxID_FONTDIALOG_PREVIEW
, wxDefaultPosition
, wxSize(-1, 70), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
522 m_previewCtrl
->SetHelpText(_("Shows a preview of the font."));
524 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
525 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
527 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
528 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
530 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
531 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
533 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
534 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
536 wxButton
* itemButton21
= new wxButton( itemDialog1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
537 itemButton21
->SetDefault();
538 itemButton21
->SetHelpText(_("Click to confirm changes to the font."));
540 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
541 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
543 wxFontEnumerator enumerator
;
544 enumerator
.EnumerateFacenames();
545 wxArrayString facenames
= enumerator
.GetFacenames();
548 facenames
.Add(_("<Any>"));
549 facenames
.Add(_("<Any Roman>"));
550 facenames
.Add(_("<Any Decorative>"));
551 facenames
.Add(_("<Any Modern>"));
552 facenames
.Add(_("<Any Script>"));
553 facenames
.Add(_("<Any Swiss>"));
554 facenames
.Add(_("<Any Teletype>"));
556 m_facenameCtrl
->Append(facenames
);
559 InitializeControls();
560 m_previewCtrl
->SetFont(m_dialogFont
);
561 if (m_fontData
.GetColour().Ok())
563 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
565 m_previewCtrl
->Refresh();
569 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
572 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
578 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
581 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
587 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
590 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
596 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
599 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
605 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
608 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
614 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
617 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
624 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
627 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
632 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
634 m_fontData
.SetColour(m_colourCtrl
->GetColour());
635 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
636 m_previewCtrl
->Refresh();
640 * Should we show tooltips?
643 bool wxFontDialog::ShowToolTips()
648 void wxFontDialog::InitializeFont()
650 int fontFamily
= wxSWISS
;
651 int fontWeight
= wxNORMAL
;
652 int fontStyle
= wxNORMAL
;
654 bool fontUnderline
= false;
657 if (m_fontData
.m_initialFont
.Ok())
659 fontFamily
= m_fontData
.m_initialFont
.GetFamily();
660 fontWeight
= m_fontData
.m_initialFont
.GetWeight();
661 fontStyle
= m_fontData
.m_initialFont
.GetStyle();
662 fontSize
= m_fontData
.m_initialFont
.GetPointSize();
663 fontUnderline
= m_fontData
.m_initialFont
.GetUnderlined();
664 fontName
= m_fontData
.m_initialFont
.GetFaceName();
667 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
668 fontWeight
, fontUnderline
, fontName
);
671 m_previewCtrl
->SetFont(m_dialogFont
);
673 m_fontData
.SetChosenFont(m_dialogFont
);
676 /// Set controls according to current font
677 void wxFontDialog::InitializeControls()
679 m_suppressUpdates
= true;
681 if (m_underlinedCtrl
)
682 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
684 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
685 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
686 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
688 wxString facename
= m_dialogFont
.GetFaceName();
689 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
691 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
693 m_facenameCtrl
->SetStringSelection(facename
);
695 if (m_colourCtrl
&& m_fontData
.GetColour().Ok())
697 m_colourCtrl
->SetColour(m_fontData
.GetColour());
698 m_colourCtrl
->Refresh();
701 m_suppressUpdates
= false;
704 /// Respond to font change
705 void wxFontDialog::ChangeFont()
707 if (m_suppressUpdates
)
710 bool underlined
= m_underlinedCtrl
? m_underlinedCtrl
->GetValue() : false;
711 bool italic
= m_italicCtrl
->GetValue();
712 bool bold
= m_boldCtrl
->GetValue();
713 int size
= m_sizeCtrl
->GetValue();
714 wxString facename
= m_facenameCtrl
->GetStringSelection();
716 int family
= FontFamilyStringToInt(facename
);
720 facename
= wxEmptyString
;
722 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
723 underlined
, facename
);
725 m_fontData
.SetChosenFont(m_dialogFont
);
727 m_previewCtrl
->SetFont(m_dialogFont
);
728 m_previewCtrl
->Refresh();
731 void wxFontDialog::SetData(const wxFontData
& fontdata
)
733 m_fontData
= fontdata
;
736 bool wxFontDialog::IsShown() const
741 int wxFontDialog::ShowModal()
743 return wxDialog::ShowModal();
746 void wxFontDialog::OnPanelClose()
750 const wxChar
*FontFamilyIntToString(int family
)
755 return _("<Any Roman>");
757 return _("<Any Decorative>");
759 return _("<Any Modern>");
761 return _("<Any Script>");
763 return _("<Any Teletype>");
766 return _("<Any Swiss>");
770 int FontFamilyStringToInt(const wxChar
*family
)
775 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
777 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
779 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
781 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
783 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
785 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
790 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
792 #endif // wxMAC_USE_EXPERIMENTAL_FONTDIALOG
794 #endif // wxUSE_FONTDLG