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
:
70 ATSUFontID fontId
= 0 ;
71 if ( cEvent
.GetParameter
<ATSUFontID
>(kEventParamATSUFontID
, &fontId
) == noErr
)
73 FMFontStyle fontStyle
= cEvent
.GetParameter
<FMFontStyle
>(kEventParamFMFontStyle
);
74 FMFontSize fontSize
= cEvent
.GetParameter
<FMFontSize
>(kEventParamFMFontSize
);
76 CFStringRef cfName
= NULL
;
78 FMFontFamily fontFamily
= cEvent
.GetParameter
<FMFontFamily
>(kEventParamFMFontFamily
);
79 ATSFontFamilyRef atsfontfamilyref
= FMGetATSFontFamilyRefFromFontFamily( fontFamily
) ;
80 OSStatus err
= ATSFontFamilyGetName( atsfontfamilyref
, kATSOptionFlagsDefault
, &cfName
) ;
81 wxASSERT_MSG( err
== noErr
, wxT("ATSFontFamilyGetName failed") );
83 // we don't use the ATSU naming anymore
84 ByteCount actualLength
= 0;
86 OSStatus err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
87 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
91 char *c
= (char*)malloc( actualLength
);
92 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontUnicodePlatform
, kFontNoScriptCode
,
93 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
94 cfName
= CFStringCreateWithCharacters(NULL
, (UniChar
*) c
, (actualLength
-1) >> 1);
98 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
99 kFontNoLanguageCode
, 0 , NULL
, &actualLength
, NULL
);
103 c
= (char*)malloc(actualLength
);
104 err
= ATSUFindFontName(fontId
, kFontFamilyName
, kFontNoPlatformCode
, kFontNoScriptCode
,
105 kFontNoLanguageCode
, actualLength
, c
, NULL
, NULL
);
106 c
[actualLength
-1] = 0;
107 cfName
= CFStringCreateWithCString(NULL
, c
, kCFStringEncodingMacRoman
);
116 fontdata
.m_chosenFont
.SetFaceName(wxMacCFStringHolder(cfName
).AsString(wxLocale::GetSystemEncoding()));
117 fontdata
.m_chosenFont
.SetPointSize(fontSize
);
118 fontdata
.m_chosenFont
.SetStyle(fontStyle
& italic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
);
119 fontdata
.m_chosenFont
.SetUnderlined((fontStyle
& underline
)!=0);
120 fontdata
.m_chosenFont
.SetWeight(fontStyle
& bold
? wxFONTWEIGHT_BOLD
: wxFONTWEIGHT_NORMAL
);
125 if ( cEvent
.GetParameter
<RGBColor
>(kEventParamFontColor
, &fontColor
) == noErr
)
126 fontdata
.m_fontColour
.FromRGBColor((WXCOLORREF
*) &fontColor
);
129 CFDictionaryRef dict
;
130 if ( cEvent
.GetParameter
<CFDictionaryRef
>(kEventParamDictionary
, &dict
) == noErr
)
132 CFDictionaryRef attributesDict
;
133 if ( CFDictionaryGetValueIfPresent(dict
, kFontPanelAttributesKey
, (const void **)&attributesDict
) )
137 CFDataRef valuesData
;
138 if ( CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeTagsKey
, (const void **)&tagsData
) &&
139 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeSizesKey
, (const void **)&sizesData
) &&
140 CFDictionaryGetValueIfPresent(attributesDict
, kFontPanelAttributeValuesKey
, (const void **)&valuesData
) )
142 ItemCount count
= CFDataGetLength(tagsData
)/sizeof(ATSUAttributeTag
);
143 ATSUAttributeTag
*tagPtr
= (ATSUAttributeTag
*)CFDataGetBytePtr(tagsData
);
144 ByteCount
*sizePtr
= (ByteCount
*)CFDataGetBytePtr(sizesData
);
145 UInt32
*bytePtr
= (UInt32
*)CFDataGetBytePtr(valuesData
);
146 ATSUAttributeValuePtr valuesPtr
= bytePtr
;
147 for ( ItemCount i
= 0 ; i
< count
; ++i
)
149 if ( tagPtr
[i
] == kATSUColorTag
&& sizePtr
[i
] == sizeof(RGBColor
))
151 fontdata
.m_fontColour
.FromRGBColor((WXCOLORREF
*) valuesPtr
);
154 bytePtr
= (UInt32
*)( (UInt8
*)bytePtr
+ sizePtr
[i
]);
167 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler
)
169 wxFontDialog::wxFontDialog()
173 wxFontDialog::wxFontDialog(wxWindow
*parent
, const wxFontData
& data
)
175 Create(parent
, data
);
178 wxFontDialog::~wxFontDialog()
182 bool wxFontDialog::Create(wxWindow
*parent
, const wxFontData
& data
)
188 int wxFontDialog::ShowModal()
191 wxFont font
= *wxNORMAL_FONT
;
192 if ( m_fontData
.m_initialFont
.Ok() )
194 font
= m_fontData
.m_initialFont
;
197 ATSUStyle style
= (ATSUStyle
)font
.MacGetATSUStyle();
198 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,1, &style
, NULL
);
199 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
200 // that field is already correct
201 m_fontData
.m_chosenFont
= font
;
203 EventHandlerRef handler
;
205 err
= InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList
), eventList
, this , &handler
);
207 if ( !FPIsFontPanelVisible() )
208 FPShowHideFontPanel();
210 int retval
= RunMixedFontDialog(this);
212 ::RemoveEventHandler(handler
);
219 #if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
223 #include "wx/mac/fontdlg.h"
225 #include "wx/fontenum.h"
226 #include "wx/colordlg.h"
227 #include "wx/spinctrl.h"
229 // ---------------------------------------------------------------------------
230 // wxFontDialog stub for mac OS's without a native font dialog
231 // ---------------------------------------------------------------------------
233 static const wxChar
*FontFamilyIntToString(int family
);
234 static int FontFamilyStringToInt(const wxChar
*family
);
237 //-----------------------------------------------------------------------------
238 // helper class - wxFontPreviewCtrl
239 //-----------------------------------------------------------------------------
241 class WXDLLEXPORT wxFontPreviewCtrl
: public wxWindow
244 wxFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
245 wxWindow(parent
, id
, pos
, sz
, style
)
247 SetBackgroundColour(*wxWHITE
);
251 void OnPaint(wxPaintEvent
& event
);
252 DECLARE_EVENT_TABLE()
255 BEGIN_EVENT_TABLE(wxFontPreviewCtrl
, wxWindow
)
256 EVT_PAINT(wxFontPreviewCtrl::OnPaint
)
259 void wxFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
263 wxSize size
= GetSize();
264 wxFont font
= GetFont();
269 // Calculate vertical centre
271 dc
.GetTextExtent( wxT("X"), &w
, &h
);
272 dc
.SetTextForeground(GetForegroundColour());
273 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
274 dc
.DrawText(_("ABCDEFGabcdefg12345"),
276 dc
.DestroyClippingRegion();
281 * A control for displaying a small preview of a colour or bitmap
284 class wxFontColourSwatchCtrl
: public wxControl
286 DECLARE_CLASS(wxFontColourSwatchCtrl
)
288 wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
289 ~wxFontColourSwatchCtrl();
291 void OnPaint(wxPaintEvent
& event
);
292 void OnMouseEvent(wxMouseEvent
& event
);
294 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
296 wxColour
& GetColour() { return m_colour
; }
298 virtual wxSize
DoGetBestSize() const { return GetSize(); }
303 DECLARE_EVENT_TABLE()
307 * A control for displaying a small preview of a colour or bitmap
310 BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl
, wxControl
)
311 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent
)
314 IMPLEMENT_CLASS(wxFontColourSwatchCtrl
, wxControl
)
316 wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
):
317 wxControl(parent
, id
, pos
, size
, style
)
319 SetColour(* wxWHITE
);
320 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
323 wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
327 void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
329 if (event
.LeftDown())
331 wxWindow
* parent
= GetParent();
332 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
333 parent
= parent
->GetParent();
336 data
.SetChooseFull(true);
337 data
.SetColour(m_colour
);
338 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
339 // Crashes on wxMac (no m_peer)
341 dialog
->SetTitle(_("Background colour"));
343 if (dialog
->ShowModal() == wxID_OK
)
345 wxColourData retData
= dialog
->GetColourData();
346 m_colour
= retData
.GetColour();
347 SetBackgroundColour(m_colour
);
352 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
353 GetEventHandler()->ProcessEvent(event
);
358 * wxFontDialog type definition
361 IMPLEMENT_DYNAMIC_CLASS( wxFontDialog
, wxDialog
)
364 * wxFontDialog event table definition
367 BEGIN_EVENT_TABLE( wxFontDialog
, wxDialog
)
368 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME
, wxFontDialog::OnFontdialogFacenameSelected
)
369 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeUpdated
)
370 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE
, wxFontDialog::OnFontdialogFontsizeTextUpdated
)
371 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD
, wxFontDialog::OnFontdialogBoldClick
)
372 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC
, wxFontDialog::OnFontdialogItalicClick
)
373 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED
, wxFontDialog::OnFontdialogUnderlinedClick
)
374 EVT_BUTTON( wxID_OK
, wxFontDialog::OnOkClick
)
375 EVT_BUTTON(wxID_FONTDIALOG_COLOUR
, wxFontDialog::OnColourChanged
)
379 * wxFontDialog constructors
382 wxFontDialog::wxFontDialog( )
384 m_dialogParent
= NULL
;
387 wxFontDialog::wxFontDialog(wxWindow
* parent
, const wxFontData
& fontData
)
389 m_dialogParent
= NULL
;
391 Create(parent
, fontData
);
394 wxFontDialog::~wxFontDialog()
400 * wxFontDialog creator
403 bool wxFontDialog::Create(wxWindow
* parent
, const wxFontData
& fontData
)
405 m_fontData
= fontData
;
406 m_suppressUpdates
= false;
408 wxString caption
= _("Font");
410 m_facenameCtrl
= NULL
;
414 m_underlinedCtrl
= NULL
;
416 m_previewCtrl
= NULL
;
420 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
);
421 wxDialog::Create( parent
, wxID_ANY
, caption
, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
424 GetSizer()->Fit(this);
425 GetSizer()->SetSizeHints(this);
432 * Control creation for wxFontDialog
435 void wxFontDialog::CreateControls()
437 wxFontDialog
* itemDialog1
= this;
439 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
440 itemDialog1
->SetSizer(itemBoxSizer2
);
442 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
443 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
445 wxFlexGridSizer
* itemFlexGridSizer4
= new wxFlexGridSizer(6, 2, 10, 0);
446 itemFlexGridSizer4
->AddGrowableRow(4);
447 itemFlexGridSizer4
->AddGrowableCol(1);
448 itemBoxSizer3
->Add(itemFlexGridSizer4
, 1, wxGROW
|wxALL
, 5);
450 wxStaticText
* itemStaticText5
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
451 itemFlexGridSizer4
->Add(itemStaticText5
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
453 wxBoxSizer
* itemBoxSizer6
= new wxBoxSizer(wxVERTICAL
);
454 itemFlexGridSizer4
->Add(itemBoxSizer6
, 0, wxGROW
|wxGROW
, 5);
456 wxString
* m_facenameCtrlStrings
= NULL
;
457 m_facenameCtrl
= new wxListBox( itemDialog1
, wxID_FONTDIALOG_FACENAME
, wxDefaultPosition
, wxSize(320, 100), 0, m_facenameCtrlStrings
, wxLB_SINGLE
);
458 itemBoxSizer6
->Add(m_facenameCtrl
, 0, wxGROW
|wxALL
, 5);
460 wxStaticText
* itemStaticText8
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
461 itemFlexGridSizer4
->Add(itemStaticText8
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
|wxADJUST_MINSIZE
, 5);
463 m_sizeCtrl
= new wxSpinCtrl( itemDialog1
, wxID_FONTDIALOG_FONTSIZE
, _T("12"), wxDefaultPosition
, wxSize(60, -1), wxSP_ARROW_KEYS
, 1, 300, 12 );
464 m_sizeCtrl
->SetHelpText(_("The font size in points."));
466 m_sizeCtrl
->SetToolTip(_("The font size in points."));
467 itemFlexGridSizer4
->Add(m_sizeCtrl
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
469 wxStaticText
* itemStaticText10
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
470 itemFlexGridSizer4
->Add(itemStaticText10
, 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxALL
|wxADJUST_MINSIZE
, 5);
472 wxBoxSizer
* itemBoxSizer11
= new wxBoxSizer(wxHORIZONTAL
);
473 itemFlexGridSizer4
->Add(itemBoxSizer11
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
, 5);
475 m_boldCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_BOLD
, _("Bold"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
476 m_boldCtrl
->SetValue(false);
477 m_boldCtrl
->SetHelpText(_("Check to make the font bold."));
479 m_boldCtrl
->SetToolTip(_("Check to make the font bold."));
480 itemBoxSizer11
->Add(m_boldCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
482 m_italicCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_ITALIC
, _("Italic"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
483 m_italicCtrl
->SetValue(false);
484 m_italicCtrl
->SetHelpText(_("Check to make the font italic."));
486 m_italicCtrl
->SetToolTip(_("Check to make the font italic."));
487 itemBoxSizer11
->Add(m_italicCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
489 if (m_fontData
.GetEnableEffects())
491 m_underlinedCtrl
= new wxCheckBox( itemDialog1
, wxID_FONTDIALOG_UNDERLINED
, _("Underlined"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
492 m_underlinedCtrl
->SetValue(false);
493 m_underlinedCtrl
->SetHelpText(_("Check to make the font underlined."));
495 m_underlinedCtrl
->SetToolTip(_("Check to make the font underlined."));
496 itemBoxSizer11
->Add(m_underlinedCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
499 if (m_fontData
.GetEnableEffects())
501 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
502 itemFlexGridSizer4
->Add(itemStaticText15
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
504 m_colourCtrl
= new wxFontColourSwatchCtrl( itemDialog1
, wxID_FONTDIALOG_COLOUR
, wxDefaultPosition
, wxSize(-1, 30), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
505 m_colourCtrl
->SetHelpText(_("Click to change the font colour."));
507 m_colourCtrl
->SetToolTip(_("Click to change the font colour."));
508 itemFlexGridSizer4
->Add(m_colourCtrl
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
511 wxStaticText
* itemStaticText17
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("Preview:"), wxDefaultPosition
, wxDefaultSize
, 0 );
512 itemFlexGridSizer4
->Add(itemStaticText17
, 0, wxALIGN_RIGHT
|wxALIGN_TOP
|wxALL
|wxADJUST_MINSIZE
, 5);
514 m_previewCtrl
= new wxFontPreviewCtrl( itemDialog1
, wxID_FONTDIALOG_PREVIEW
, wxDefaultPosition
, wxSize(-1, 70), wxSUNKEN_BORDER
|wxTAB_TRAVERSAL
);
515 m_previewCtrl
->SetHelpText(_("Shows a preview of the font."));
517 m_previewCtrl
->SetToolTip(_("Shows a preview of the font."));
518 itemFlexGridSizer4
->Add(m_previewCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
520 wxBoxSizer
* itemBoxSizer19
= new wxBoxSizer(wxHORIZONTAL
);
521 itemBoxSizer3
->Add(itemBoxSizer19
, 0, wxALIGN_RIGHT
|wxALL
, 5);
523 wxButton
* itemButton20
= new wxButton( itemDialog1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
524 itemButton20
->SetHelpText(_("Click to cancel changes to the font."));
526 itemButton20
->SetToolTip(_("Click to cancel changes to the font."));
527 itemBoxSizer19
->Add(itemButton20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
529 wxButton
* itemButton21
= new wxButton( itemDialog1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
530 itemButton21
->SetDefault();
531 itemButton21
->SetHelpText(_("Click to confirm changes to the font."));
533 itemButton21
->SetToolTip(_("Click to confirm changes to the font."));
534 itemBoxSizer19
->Add(itemButton21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
536 wxFontEnumerator enumerator
;
537 enumerator
.EnumerateFacenames();
538 wxArrayString facenames
= enumerator
.GetFacenames();
541 facenames
.Add(_("<Any>"));
542 facenames
.Add(_("<Any Roman>"));
543 facenames
.Add(_("<Any Decorative>"));
544 facenames
.Add(_("<Any Modern>"));
545 facenames
.Add(_("<Any Script>"));
546 facenames
.Add(_("<Any Swiss>"));
547 facenames
.Add(_("<Any Teletype>"));
549 m_facenameCtrl
->Append(facenames
);
552 InitializeControls();
553 m_previewCtrl
->SetFont(m_dialogFont
);
554 if (m_fontData
.GetColour().Ok())
556 m_previewCtrl
->SetForegroundColour(m_fontData
.GetColour());
558 m_previewCtrl
->Refresh();
562 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
565 void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent
& WXUNUSED(event
) )
571 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
574 void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent
& WXUNUSED(event
) )
580 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
583 void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent
& WXUNUSED(event
) )
589 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
592 void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent
& WXUNUSED(event
) )
598 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
601 void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent
& WXUNUSED(event
) )
607 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
610 void wxFontDialog::OnOkClick( wxCommandEvent
& event
)
617 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
620 void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent
& WXUNUSED(event
) )
625 void wxFontDialog::OnColourChanged(wxCommandEvent
& WXUNUSED(event
))
627 m_fontData
.SetColour(m_colourCtrl
->GetColour());
628 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
629 m_previewCtrl
->Refresh();
633 * Should we show tooltips?
636 bool wxFontDialog::ShowToolTips()
641 void wxFontDialog::InitializeFont()
643 int fontFamily
= wxSWISS
;
644 int fontWeight
= wxNORMAL
;
645 int fontStyle
= wxNORMAL
;
647 bool fontUnderline
= false;
650 if (m_fontData
.m_initialFont
.Ok())
652 fontFamily
= m_fontData
.m_initialFont
.GetFamily();
653 fontWeight
= m_fontData
.m_initialFont
.GetWeight();
654 fontStyle
= m_fontData
.m_initialFont
.GetStyle();
655 fontSize
= m_fontData
.m_initialFont
.GetPointSize();
656 fontUnderline
= m_fontData
.m_initialFont
.GetUnderlined();
657 fontName
= m_fontData
.m_initialFont
.GetFaceName();
660 m_dialogFont
= wxFont(fontSize
, fontFamily
, fontStyle
,
661 fontWeight
, fontUnderline
, fontName
);
664 m_previewCtrl
->SetFont(m_dialogFont
);
666 m_fontData
.SetChosenFont(m_dialogFont
);
669 /// Set controls according to current font
670 void wxFontDialog::InitializeControls()
672 m_suppressUpdates
= true;
674 if (m_underlinedCtrl
)
675 m_underlinedCtrl
->SetValue(m_dialogFont
.GetUnderlined());
677 m_boldCtrl
->SetValue(m_dialogFont
.GetWeight() == wxBOLD
);
678 m_italicCtrl
->SetValue(m_dialogFont
.GetStyle() == wxITALIC
);
679 m_sizeCtrl
->SetValue(m_dialogFont
.GetPointSize());
681 wxString facename
= m_dialogFont
.GetFaceName();
682 if (facename
.empty() || m_facenameCtrl
->FindString(facename
) == wxNOT_FOUND
)
684 facename
= FontFamilyIntToString(m_dialogFont
.GetFamily());
686 m_facenameCtrl
->SetStringSelection(facename
);
688 if (m_colourCtrl
&& m_fontData
.GetColour().Ok())
690 m_colourCtrl
->SetColour(m_fontData
.GetColour());
691 m_colourCtrl
->Refresh();
694 m_suppressUpdates
= false;
697 /// Respond to font change
698 void wxFontDialog::ChangeFont()
700 if (m_suppressUpdates
)
703 bool underlined
= m_underlinedCtrl
? m_underlinedCtrl
->GetValue() : false;
704 bool italic
= m_italicCtrl
->GetValue();
705 bool bold
= m_boldCtrl
->GetValue();
706 int size
= m_sizeCtrl
->GetValue();
707 wxString facename
= m_facenameCtrl
->GetStringSelection();
709 int family
= FontFamilyStringToInt(facename
);
713 facename
= wxEmptyString
;
715 m_dialogFont
= wxFont(size
, family
, italic
? wxITALIC
: wxNORMAL
, bold
? wxBOLD
: wxNORMAL
,
716 underlined
, facename
);
718 m_fontData
.SetChosenFont(m_dialogFont
);
720 m_previewCtrl
->SetFont(m_dialogFont
);
721 m_previewCtrl
->Refresh();
724 void wxFontDialog::SetData(const wxFontData
& fontdata
)
726 m_fontData
= fontdata
;
729 bool wxFontDialog::IsShown() const
734 int wxFontDialog::ShowModal()
736 return wxDialog::ShowModal();
739 void wxFontDialog::OnPanelClose()
743 const wxChar
*FontFamilyIntToString(int family
)
748 return _("<Any Roman>");
750 return _("<Any Decorative>");
752 return _("<Any Modern>");
754 return _("<Any Script>");
756 return _("<Any Teletype>");
759 return _("<Any Swiss>");
763 int FontFamilyStringToInt(const wxChar
*family
)
768 if (wxStrcmp(family
, _("<Any Roman>")) == 0)
770 else if (wxStrcmp(family
, _("<Any Decorative>")) == 0)
772 else if (wxStrcmp(family
, _("<Any Modern>")) == 0)
774 else if (wxStrcmp(family
, _("<Any Script>")) == 0)
776 else if (wxStrcmp(family
, _("<Any Teletype>")) == 0)
778 else if (wxStrcmp(family
, _("<Any Swiss>")) == 0)
783 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX