]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/fontdlg.cpp
guard code for mac / quickdraw
[wxWidgets.git] / src / mac / carbon / fontdlg.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/carbon/fontdlg.cpp
3// Purpose: wxFontDialog class for carbon 10.2+.
4// Author: Ryan Norton
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Ryan Norton
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#if wxUSE_FONTDLG
24
25#ifdef __BORLANDC__
26 #pragma hdrstop
27#endif
28
29#ifndef WX_PRECOMP
30 #include "wx/intl.h"
31 #include "wx/crt.h"
32 #include "wx/dcclient.h"
33 #include "wx/frame.h"
34 #include "wx/textctrl.h"
35 #include "wx/listbox.h"
36 #include "wx/checkbox.h"
37 #include "wx/choice.h"
38 #include "wx/sizer.h"
39 #include "wx/stattext.h"
40 #include "wx/button.h"
41#endif
42
43#include "wx/fontdlg.h"
44
45#if wxMAC_USE_EXPERIMENTAL_FONTDIALOG
46
47IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
48
49#include "wx/mac/private.h"
50
51// ---------------------------------------------------------------------------
52// wxFontDialog
53// ---------------------------------------------------------------------------
54
55static const EventTypeSpec eventList[] =
56{
57 { kEventClassFont, kEventFontSelection } ,
58} ;
59
60
61pascal OSStatus
62wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler),
63 EventRef event,
64 void *userData)
65{
66 OSStatus result = eventNotHandledErr ;
67 wxFontDialog *fontdialog = (wxFontDialog*) userData ;
68 wxFontData& fontdata= fontdialog->GetFontData() ;
69
70 wxMacCarbonEvent cEvent( event );
71 switch(cEvent.GetKind())
72 {
73 case kEventFontSelection :
74 {
75 ATSUFontID fontId = 0 ;
76 if ( cEvent.GetParameter<ATSUFontID>(kEventParamATSUFontID, &fontId) == noErr )
77 {
78 FMFontStyle fontStyle = cEvent.GetParameter<FMFontStyle>(kEventParamFMFontStyle);
79 FMFontSize fontSize = cEvent.GetParameter<FMFontSize>(kEventParamFMFontSize);
80
81 CFStringRef cfName = NULL;
82#if 1
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") );
87#else
88 // we don't use the ATSU naming anymore
89 ByteCount actualLength = 0;
90 char *c = NULL;
91 OSStatus err = ATSUFindFontName(fontId , kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
92 kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
93 if ( err == noErr)
94 {
95 actualLength += 1 ;
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);
100 }
101 else
102 {
103 err = ATSUFindFontName(fontId , kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
104 kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
105 if ( err == noErr )
106 {
107 actualLength += 1 ;
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 );
113 }
114 }
115 if ( c!=NULL )
116 free(c);
117#endif
118
119 if ( cfName!=NULL )
120 {
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);
126 }
127 }
128
129 RGBColor fontColor ;
130 if ( cEvent.GetParameter<RGBColor>(kEventParamFontColor, &fontColor) == noErr )
131 {
132 fontdata.m_fontColour = fontColor;
133 }
134 else
135 {
136 CFDictionaryRef dict ;
137 if ( cEvent.GetParameter<CFDictionaryRef>(kEventParamDictionary, &dict) == noErr )
138 {
139 CFDictionaryRef attributesDict ;
140 if ( CFDictionaryGetValueIfPresent(dict, kFontPanelAttributesKey, (const void **)&attributesDict) )
141 {
142 CFDataRef tagsData;
143 CFDataRef sizesData;
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) )
148 {
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)
155 {
156 if ( tagPtr[i] == kATSUColorTag && sizePtr[i] == sizeof(RGBColor))
157 {
158 fontdata.m_fontColour = *(RGBColor *)valuesPtr;
159 break ;
160 }
161 bytePtr = (UInt32*)( (UInt8*)bytePtr + sizePtr[i]);
162 }
163 }
164 }
165 }
166 }
167 }
168 break ;
169 } ;
170
171 return result ;
172}
173
174DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler )
175
176wxFontDialog::wxFontDialog()
177{
178}
179
180wxFontDialog::wxFontDialog(wxWindow *parent, const wxFontData& data)
181{
182 Create(parent, data);
183}
184
185wxFontDialog::~wxFontDialog()
186{
187}
188
189bool wxFontDialog::Create(wxWindow *WXUNUSED(parent), const wxFontData& data)
190{
191 m_fontData = data;
192 return true ;
193}
194
195int wxFontDialog::ShowModal()
196{
197 OSStatus err ;
198 wxFont font = *wxNORMAL_FONT ;
199 if ( m_fontData.m_initialFont.Ok() )
200 {
201 font = m_fontData.m_initialFont ;
202 }
203
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 ;
209
210 EventHandlerRef handler ;
211
212 err = InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList), eventList, this , &handler );
213
214 if ( !FPIsFontPanelVisible() )
215 FPShowHideFontPanel();
216
217 int retval = RunMixedFontDialog(this);
218
219 ::RemoveEventHandler(handler);
220
221 return retval ;
222}
223
224#else
225
226#if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
227
228#undef wxFontDialog
229
230#include "wx/mac/fontdlg.h"
231
232#include "wx/fontenum.h"
233#include "wx/colordlg.h"
234#include "wx/spinctrl.h"
235
236// ---------------------------------------------------------------------------
237// wxFontDialog stub for mac OS's without a native font dialog
238// ---------------------------------------------------------------------------
239
240static const wxChar *FontFamilyIntToString(int family);
241static int FontFamilyStringToInt(const wxChar *family);
242
243
244//-----------------------------------------------------------------------------
245// helper class - wxFontPreviewCtrl
246//-----------------------------------------------------------------------------
247
248class WXDLLEXPORT wxFontPreviewCtrl : public wxWindow
249{
250public:
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)
253 {
254 SetBackgroundColour(*wxWHITE);
255 }
256
257private:
258 void OnPaint(wxPaintEvent& event);
259 DECLARE_EVENT_TABLE()
260};
261
262BEGIN_EVENT_TABLE(wxFontPreviewCtrl, wxWindow)
263 EVT_PAINT(wxFontPreviewCtrl::OnPaint)
264END_EVENT_TABLE()
265
266void wxFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
267{
268 wxPaintDC dc(this);
269
270 wxSize size = GetSize();
271 wxFont font = GetFont();
272
273 if ( font.Ok() )
274 {
275 dc.SetFont(font);
276 // Calculate vertical centre
277 long w = 0, h = 0;
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"),
282 10, size.y/2 - h/2);
283 dc.DestroyClippingRegion();
284 }
285}
286
287/*
288 * A control for displaying a small preview of a colour or bitmap
289 */
290
291class wxFontColourSwatchCtrl: public wxControl
292{
293 DECLARE_CLASS(wxFontColourSwatchCtrl)
294public:
295 wxFontColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
296 virtual ~wxFontColourSwatchCtrl();
297
298 void OnPaint(wxPaintEvent& event);
299 void OnMouseEvent(wxMouseEvent& event);
300
301 void SetColour(const wxColour& colour) { m_colour = colour; SetBackgroundColour(m_colour); }
302
303 wxColour& GetColour() { return m_colour; }
304
305 virtual wxSize DoGetBestSize() const { return GetSize(); }
306
307protected:
308 wxColour m_colour;
309
310DECLARE_EVENT_TABLE()
311};
312
313/*
314 * A control for displaying a small preview of a colour or bitmap
315 */
316
317BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl, wxControl)
318 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent)
319END_EVENT_TABLE()
320
321IMPLEMENT_CLASS(wxFontColourSwatchCtrl, wxControl)
322
323wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
324 wxControl(parent, id, pos, size, style)
325{
326 SetColour(* wxWHITE);
327 SetBackgroundStyle(wxBG_STYLE_COLOUR);
328}
329
330wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
331{
332}
333
334void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent& event)
335{
336 if (event.LeftDown())
337 {
338 wxWindow* parent = GetParent();
339 while (parent != NULL && !parent->IsKindOf(CLASSINFO(wxDialog)) && !parent->IsKindOf(CLASSINFO(wxFrame)))
340 parent = parent->GetParent();
341
342 wxColourData data;
343 data.SetChooseFull(true);
344 data.SetColour(m_colour);
345 wxColourDialog *dialog = new wxColourDialog(parent, &data);
346 // Crashes on wxMac (no m_peer)
347#ifndef __WXMAC__
348 dialog->SetTitle(_("Background colour"));
349#endif
350 if (dialog->ShowModal() == wxID_OK)
351 {
352 wxColourData retData = dialog->GetColourData();
353 m_colour = retData.GetColour();
354 SetBackgroundColour(m_colour);
355 }
356 dialog->Destroy();
357 Refresh();
358
359 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
360 GetEventHandler()->ProcessEvent(event);
361 }
362}
363
364/*!
365 * wxFontDialog type definition
366 */
367
368IMPLEMENT_DYNAMIC_CLASS( wxFontDialog, wxDialog )
369
370/*!
371 * wxFontDialog event table definition
372 */
373
374BEGIN_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)
383END_EVENT_TABLE()
384
385/*!
386 * wxFontDialog constructors
387 */
388
389wxFontDialog::wxFontDialog( )
390{
391 m_dialogParent = NULL;
392}
393
394wxFontDialog::wxFontDialog(wxWindow* parent, const wxFontData& fontData)
395{
396 m_dialogParent = NULL;
397
398 Create(parent, fontData);
399}
400
401wxFontDialog::~wxFontDialog()
402{
403 // empty
404}
405
406/*!
407 * wxFontDialog creator
408 */
409
410bool wxFontDialog::Create(wxWindow* parent, const wxFontData& fontData)
411{
412 m_fontData = fontData;
413 m_suppressUpdates = false;
414
415 wxString caption = _("Font");
416
417 m_facenameCtrl = NULL;
418 m_sizeCtrl = NULL;
419 m_boldCtrl = NULL;
420 m_italicCtrl = NULL;
421 m_underlinedCtrl = NULL;
422 m_colourCtrl = NULL;
423 m_previewCtrl = NULL;
424
425 InitializeFont();
426
427 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
428 wxDialog::Create( parent, wxID_ANY, caption, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
429
430 CreateControls();
431 GetSizer()->Fit(this);
432 GetSizer()->SetSizeHints(this);
433 Centre();
434
435 return true;
436}
437
438/*!
439 * Control creation for wxFontDialog
440 */
441
442void wxFontDialog::CreateControls()
443{
444 wxFontDialog* itemDialog1 = this;
445
446 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
447 itemDialog1->SetSizer(itemBoxSizer2);
448
449 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
450 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
451
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);
456
457 wxStaticText* itemStaticText5 = new wxStaticText( itemDialog1, wxID_STATIC, _("Font:"), wxDefaultPosition, wxDefaultSize, 0 );
458 itemFlexGridSizer4->Add(itemStaticText5, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5);
459
460 wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxVERTICAL);
461 itemFlexGridSizer4->Add(itemBoxSizer6, 0, wxGROW|wxGROW, 5);
462
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);
466
467 wxStaticText* itemStaticText8 = new wxStaticText( itemDialog1, wxID_STATIC, _("Size:"), wxDefaultPosition, wxDefaultSize, 0 );
468 itemFlexGridSizer4->Add(itemStaticText8, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
469
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."));
472 if (ShowToolTips())
473 m_sizeCtrl->SetToolTip(_("The font size in points."));
474 itemFlexGridSizer4->Add(m_sizeCtrl, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
475
476 wxStaticText* itemStaticText10 = new wxStaticText( itemDialog1, wxID_STATIC, _("Style:"), wxDefaultPosition, wxDefaultSize, 0 );
477 itemFlexGridSizer4->Add(itemStaticText10, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
478
479 wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
480 itemFlexGridSizer4->Add(itemBoxSizer11, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
481
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."));
485 if (ShowToolTips())
486 m_boldCtrl->SetToolTip(_("Check to make the font bold."));
487 itemBoxSizer11->Add(m_boldCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
488
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."));
492 if (ShowToolTips())
493 m_italicCtrl->SetToolTip(_("Check to make the font italic."));
494 itemBoxSizer11->Add(m_italicCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
495
496 if (m_fontData.GetEnableEffects())
497 {
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."));
501 if (ShowToolTips())
502 m_underlinedCtrl->SetToolTip(_("Check to make the font underlined."));
503 itemBoxSizer11->Add(m_underlinedCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
504 }
505
506 if (m_fontData.GetEnableEffects())
507 {
508 wxStaticText* itemStaticText15 = new wxStaticText( itemDialog1, wxID_STATIC, _("Colour:"), wxDefaultPosition, wxDefaultSize, 0 );
509 itemFlexGridSizer4->Add(itemStaticText15, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5);
510
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."));
513 if (ShowToolTips())
514 m_colourCtrl->SetToolTip(_("Click to change the font colour."));
515 itemFlexGridSizer4->Add(m_colourCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
516 }
517
518 wxStaticText* itemStaticText17 = new wxStaticText( itemDialog1, wxID_STATIC, _("Preview:"), wxDefaultPosition, wxDefaultSize, 0 );
519 itemFlexGridSizer4->Add(itemStaticText17, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5);
520
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."));
523 if (ShowToolTips())
524 m_previewCtrl->SetToolTip(_("Shows a preview of the font."));
525 itemFlexGridSizer4->Add(m_previewCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
526
527 wxBoxSizer* itemBoxSizer19 = new wxBoxSizer(wxHORIZONTAL);
528 itemBoxSizer3->Add(itemBoxSizer19, 0, wxALIGN_RIGHT|wxALL, 5);
529
530 wxButton* itemButton20 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
531 itemButton20->SetHelpText(_("Click to cancel changes to the font."));
532 if (ShowToolTips())
533 itemButton20->SetToolTip(_("Click to cancel changes to the font."));
534 itemBoxSizer19->Add(itemButton20, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
535
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."));
539 if (ShowToolTips())
540 itemButton21->SetToolTip(_("Click to confirm changes to the font."));
541 itemBoxSizer19->Add(itemButton21, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
542
543 wxFontEnumerator enumerator;
544 enumerator.EnumerateFacenames();
545 wxArrayString facenames = enumerator.GetFacenames();
546 if (facenames)
547 {
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>"));
555 facenames.Sort();
556 m_facenameCtrl->Append(facenames);
557 }
558
559 InitializeControls();
560 m_previewCtrl->SetFont(m_dialogFont);
561 if (m_fontData.GetColour().Ok())
562 {
563 m_previewCtrl->SetForegroundColour(m_fontData.GetColour());
564 }
565 m_previewCtrl->Refresh();
566}
567
568/*!
569 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
570 */
571
572void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent& WXUNUSED(event) )
573{
574 ChangeFont();
575}
576
577/*!
578 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
579 */
580
581void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent& WXUNUSED(event) )
582{
583 ChangeFont();
584}
585
586/*!
587 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
588 */
589
590void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent& WXUNUSED(event) )
591{
592 ChangeFont();
593}
594
595/*!
596 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
597 */
598
599void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent& WXUNUSED(event) )
600{
601 ChangeFont();
602}
603
604/*!
605 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
606 */
607
608void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent& WXUNUSED(event) )
609{
610 ChangeFont();
611}
612
613/*!
614 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
615 */
616
617void wxFontDialog::OnOkClick( wxCommandEvent& event )
618{
619 event.Skip();
620}
621
622
623/*!
624 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
625 */
626
627void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent& WXUNUSED(event) )
628{
629 ChangeFont();
630}
631
632void wxFontDialog::OnColourChanged(wxCommandEvent & WXUNUSED(event))
633{
634 m_fontData.SetColour(m_colourCtrl->GetColour());
635 m_previewCtrl->SetForegroundColour(m_colourCtrl->GetColour());
636 m_previewCtrl->Refresh();
637}
638
639/*!
640 * Should we show tooltips?
641 */
642
643bool wxFontDialog::ShowToolTips()
644{
645 return true;
646}
647
648void wxFontDialog::InitializeFont()
649{
650 int fontFamily = wxSWISS;
651 int fontWeight = wxNORMAL;
652 int fontStyle = wxNORMAL;
653 int fontSize = 12;
654 bool fontUnderline = false;
655 wxString fontName;
656
657 if (m_fontData.m_initialFont.Ok())
658 {
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();
665 }
666
667 m_dialogFont = wxFont(fontSize, fontFamily, fontStyle,
668 fontWeight, fontUnderline, fontName);
669
670 if (m_previewCtrl)
671 m_previewCtrl->SetFont(m_dialogFont);
672
673 m_fontData.SetChosenFont(m_dialogFont);
674}
675
676/// Set controls according to current font
677void wxFontDialog::InitializeControls()
678{
679 m_suppressUpdates = true;
680
681 if (m_underlinedCtrl)
682 m_underlinedCtrl->SetValue(m_dialogFont.GetUnderlined());
683
684 m_boldCtrl->SetValue(m_dialogFont.GetWeight() == wxBOLD);
685 m_italicCtrl->SetValue(m_dialogFont.GetStyle() == wxITALIC);
686 m_sizeCtrl->SetValue(m_dialogFont.GetPointSize());
687
688 wxString facename = m_dialogFont.GetFaceName();
689 if (facename.empty() || m_facenameCtrl->FindString(facename) == wxNOT_FOUND)
690 {
691 facename = FontFamilyIntToString(m_dialogFont.GetFamily());
692 }
693 m_facenameCtrl->SetStringSelection(facename);
694
695 if (m_colourCtrl && m_fontData.GetColour().Ok())
696 {
697 m_colourCtrl->SetColour(m_fontData.GetColour());
698 m_colourCtrl->Refresh();
699 }
700
701 m_suppressUpdates = false;
702}
703
704/// Respond to font change
705void wxFontDialog::ChangeFont()
706{
707 if (m_suppressUpdates)
708 return;
709
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();
715
716 int family = FontFamilyStringToInt(facename);
717 if (family == -1)
718 family = wxDEFAULT;
719 else
720 facename = wxEmptyString;
721
722 m_dialogFont = wxFont(size, family, italic ? wxITALIC : wxNORMAL, bold ? wxBOLD : wxNORMAL,
723 underlined, facename);
724
725 m_fontData.SetChosenFont(m_dialogFont);
726
727 m_previewCtrl->SetFont(m_dialogFont);
728 m_previewCtrl->Refresh();
729}
730
731void wxFontDialog::SetData(const wxFontData& fontdata)
732{
733 m_fontData = fontdata;
734}
735
736bool wxFontDialog::IsShown() const
737{
738 return false;
739}
740
741int wxFontDialog::ShowModal()
742{
743 return wxDialog::ShowModal();
744}
745
746void wxFontDialog::OnPanelClose()
747{
748}
749
750const wxChar *FontFamilyIntToString(int family)
751{
752 switch (family)
753 {
754 case wxROMAN:
755 return _("<Any Roman>");
756 case wxDECORATIVE:
757 return _("<Any Decorative>");
758 case wxMODERN:
759 return _("<Any Modern>");
760 case wxSCRIPT:
761 return _("<Any Script>");
762 case wxTELETYPE:
763 return _("<Any Teletype>");
764 case wxSWISS:
765 default:
766 return _("<Any Swiss>");
767 }
768}
769
770int FontFamilyStringToInt(const wxChar *family)
771{
772 if (!family)
773 return wxSWISS;
774
775 if (wxStrcmp(family, _("<Any Roman>")) == 0)
776 return wxROMAN;
777 else if (wxStrcmp(family, _("<Any Decorative>")) == 0)
778 return wxDECORATIVE;
779 else if (wxStrcmp(family, _("<Any Modern>")) == 0)
780 return wxMODERN;
781 else if (wxStrcmp(family, _("<Any Script>")) == 0)
782 return wxSCRIPT;
783 else if (wxStrcmp(family, _("<Any Teletype>")) == 0)
784 return wxTELETYPE;
785 else if (wxStrcmp(family, _("<Any Swiss>")) == 0)
786 return wxSWISS;
787 else return -1;
788}
789
790#endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
791
792#endif // wxMAC_USE_EXPERIMENTAL_FONTDIALOG
793
794#endif // wxUSE_FONTDLG