]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/fontdlg.cpp
don't provide unnecessary (as default) arguments to wxPen ctor, this incidentally...
[wxWidgets.git] / src / mac / carbon / fontdlg.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
76b49cf4 2// Name: src/mac/carbon/fontdlg.cpp
72fcdc75
RN
3// Purpose: wxFontDialog class for carbon 10.2+.
4// Author: Ryan Norton
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
72fcdc75
RN
8// Copyright: (c) Ryan Norton
9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
1553abf4
RN
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
1553abf4
RN
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
72c1ba98
VZ
23#if wxUSE_FONTDLG
24
1553abf4
RN
25#ifdef __BORLANDC__
26 #pragma hdrstop
27#endif
28
29#ifndef WX_PRECOMP
76b49cf4 30 #include "wx/intl.h"
3a3dde0d 31 #include "wx/crt.h"
76b49cf4
WS
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"
1553abf4 41#endif
e9576ca5 42
356c775f 43#include "wx/fontdlg.h"
76b49cf4 44
509b4ecc
SC
45#if wxMAC_USE_EXPERIMENTAL_FONTDIALOG
46
47IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
48
b7dbd50c 49#include "wx/mac/uma.h"
509b4ecc
SC
50
51// ---------------------------------------------------------------------------
76b49cf4 52// wxFontDialog
509b4ecc
SC
53// ---------------------------------------------------------------------------
54
55static const EventTypeSpec eventList[] =
56{
57 { kEventClassFont, kEventFontSelection } ,
58} ;
59
60
89954433
VZ
61pascal OSStatus
62wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler),
63 EventRef event,
64 void *userData)
509b4ecc
SC
65{
66 OSStatus result = eventNotHandledErr ;
67 wxFontDialog *fontdialog = (wxFontDialog*) userData ;
68 wxFontData& fontdata= fontdialog->GetFontData() ;
b7dbd50c 69
509b4ecc
SC
70 wxMacCarbonEvent cEvent( event );
71 switch(cEvent.GetKind())
72 {
73 case kEventFontSelection :
74 {
b7dbd50c
SC
75 bool setup = false ;
76#if wxMAC_USE_CORE_TEXT
77 if ( UMAGetSystemVersion() >= 0x1050 )
78 {
79 CTFontDescriptorRef descr;
80 if ( cEvent.GetParameter<CTFontDescriptorRef>( kEventParamCTFontDescriptor, typeCTFontDescriptorRef, &descr ) == noErr )
81 {
82 wxFont font;
83 font.MacCreateFromCTFontDescriptor(descr);
84 fontdata.SetChosenFont( font ) ;
85 setup = true;
86 }
87 }
88#endif
89#if wxMAC_USE_ATSU_TEXT
ec8a8e04 90 ATSUFontID fontId = 0 ;
b7dbd50c 91 if ( !setup && (cEvent.GetParameter<ATSUFontID>(kEventParamATSUFontID, &fontId) == noErr) )
76b49cf4 92 {
509b4ecc
SC
93 FMFontStyle fontStyle = cEvent.GetParameter<FMFontStyle>(kEventParamFMFontStyle);
94 FMFontSize fontSize = cEvent.GetParameter<FMFontSize>(kEventParamFMFontSize);
b7dbd50c 95
509b4ecc 96 CFStringRef cfName = NULL;
ec8a8e04
SC
97#if 1
98 FMFontFamily fontFamily = cEvent.GetParameter<FMFontFamily>(kEventParamFMFontFamily);
99 ATSFontFamilyRef atsfontfamilyref = FMGetATSFontFamilyRefFromFontFamily( fontFamily ) ;
100 OSStatus err = ATSFontFamilyGetName( atsfontfamilyref , kATSOptionFlagsDefault , &cfName ) ;
101 wxASSERT_MSG( err == noErr , wxT("ATSFontFamilyGetName failed") );
102#else
103 // we don't use the ATSU naming anymore
104 ByteCount actualLength = 0;
509b4ecc 105 char *c = NULL;
76b49cf4 106 OSStatus err = ATSUFindFontName(fontId , kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
b7dbd50c 107 kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
509b4ecc
SC
108 if ( err == noErr)
109 {
110 actualLength += 1 ;
111 char *c = (char*)malloc( actualLength );
76b49cf4 112 err = ATSUFindFontName(fontId, kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
b7dbd50c 113 kFontNoLanguageCode, actualLength, c , NULL, NULL);
509b4ecc
SC
114 cfName = CFStringCreateWithCharacters(NULL, (UniChar*) c, (actualLength-1) >> 1);
115 }
116 else
117 {
76b49cf4 118 err = ATSUFindFontName(fontId , kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
b7dbd50c 119 kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
509b4ecc
SC
120 if ( err == noErr )
121 {
122 actualLength += 1 ;
123 c = (char*)malloc(actualLength);
76b49cf4 124 err = ATSUFindFontName(fontId, kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
b7dbd50c 125 kFontNoLanguageCode, actualLength, c , NULL, NULL);
509b4ecc
SC
126 c[actualLength-1] = 0;
127 cfName = CFStringCreateWithCString(NULL, c, kCFStringEncodingMacRoman );
128 }
129 }
130 if ( c!=NULL )
131 free(c);
ec8a8e04 132#endif
509b4ecc
SC
133 if ( cfName!=NULL )
134 {
dbe4a80c 135 fontdata.m_chosenFont.SetFaceName(wxCFStringRef(cfName).AsString(wxLocale::GetSystemEncoding()));
509b4ecc 136 fontdata.m_chosenFont.SetPointSize(fontSize);
f3ba97e8
SC
137 fontdata.m_chosenFont.SetStyle(fontStyle & italic ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL);
138 fontdata.m_chosenFont.SetUnderlined((fontStyle & underline)!=0);
139 fontdata.m_chosenFont.SetWeight(fontStyle & bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
509b4ecc
SC
140 }
141 }
b7dbd50c
SC
142#endif // wxMAC_USE_ATSU_TEXT
143
144 // retrieving the color
509b4ecc
SC
145 RGBColor fontColor ;
146 if ( cEvent.GetParameter<RGBColor>(kEventParamFontColor, &fontColor) == noErr )
055de350
VZ
147 {
148 fontdata.m_fontColour = fontColor;
149 }
509b4ecc
SC
150 else
151 {
152 CFDictionaryRef dict ;
153 if ( cEvent.GetParameter<CFDictionaryRef>(kEventParamDictionary, &dict) == noErr )
154 {
155 CFDictionaryRef attributesDict ;
156 if ( CFDictionaryGetValueIfPresent(dict, kFontPanelAttributesKey, (const void **)&attributesDict) )
157 {
158 CFDataRef tagsData;
159 CFDataRef sizesData;
160 CFDataRef valuesData;
161 if ( CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeTagsKey, (const void **)&tagsData) &&
b7dbd50c
SC
162 CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeSizesKey, (const void **)&sizesData) &&
163 CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeValuesKey, (const void **)&valuesData) )
509b4ecc
SC
164 {
165 ItemCount count = CFDataGetLength(tagsData)/sizeof(ATSUAttributeTag);
166 ATSUAttributeTag *tagPtr = (ATSUAttributeTag *)CFDataGetBytePtr(tagsData);
167 ByteCount *sizePtr = (ByteCount *)CFDataGetBytePtr(sizesData);
168 UInt32 *bytePtr = (UInt32*)CFDataGetBytePtr(valuesData);
169 ATSUAttributeValuePtr valuesPtr = bytePtr ;
cc59d939 170 for ( ItemCount i = 0 ; i < count ; ++i)
509b4ecc
SC
171 {
172 if ( tagPtr[i] == kATSUColorTag && sizePtr[i] == sizeof(RGBColor))
173 {
81741494 174 fontdata.m_fontColour = *(RGBColor *)valuesPtr;
509b4ecc
SC
175 break ;
176 }
177 bytePtr = (UInt32*)( (UInt8*)bytePtr + sizePtr[i]);
178 }
179 }
180 }
181 }
182 }
183 }
184 break ;
185 } ;
b7dbd50c 186
509b4ecc
SC
187 return result ;
188}
189
190DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler )
191
192wxFontDialog::wxFontDialog()
193{
194}
195
196wxFontDialog::wxFontDialog(wxWindow *parent, const wxFontData& data)
197{
198 Create(parent, data);
199}
200
201wxFontDialog::~wxFontDialog()
202{
203}
204
89954433 205bool wxFontDialog::Create(wxWindow *WXUNUSED(parent), const wxFontData& data)
509b4ecc
SC
206{
207 m_fontData = data;
208 return true ;
209}
210
211int wxFontDialog::ShowModal()
212{
213 OSStatus err ;
214 wxFont font = *wxNORMAL_FONT ;
215 if ( m_fontData.m_initialFont.Ok() )
216 {
217 font = m_fontData.m_initialFont ;
218 }
76b49cf4 219
b7dbd50c
SC
220 bool setup = false;
221#if wxMAC_USE_CORE_TEXT
222 if ( UMAGetSystemVersion() >= 0x1050 )
223 {
224 CTFontDescriptorRef descr = (CTFontDescriptorRef)font.MacGetCTFontDescriptor();
225 err = SetFontInfoForSelection (kFontSelectionCoreTextType,1, &descr , NULL);
226 setup = true;
227 }
228#endif
229#if wxMAC_USE_ATSU_TEXT
230 if ( !setup )
231 {
232 ATSUStyle style = (ATSUStyle)font.MacGetATSUStyle();
233 err = SetFontInfoForSelection (kFontSelectionATSUIType,1, &style , NULL);
234 setup = true;
235 }
236#endif
509b4ecc
SC
237 // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
238 // that field is already correct
239 m_fontData.m_chosenFont = font ;
240
241 EventHandlerRef handler ;
242
243 err = InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList), eventList, this , &handler );
244
76b49cf4 245 if ( !FPIsFontPanelVisible() )
509b4ecc 246 FPShowHideFontPanel();
76b49cf4 247
509b4ecc 248 int retval = RunMixedFontDialog(this);
76b49cf4 249
509b4ecc 250 ::RemoveEventHandler(handler);
76b49cf4 251
509b4ecc
SC
252 return retval ;
253}
254
255#else
356c775f
RN
256
257#if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
258
551caf8b
RN
259#undef wxFontDialog
260
261#include "wx/mac/fontdlg.h"
262
cfe590ae
JS
263#include "wx/fontenum.h"
264#include "wx/colordlg.h"
265#include "wx/spinctrl.h"
72fcdc75 266
1553abf4
RN
267// ---------------------------------------------------------------------------
268// wxFontDialog stub for mac OS's without a native font dialog
269// ---------------------------------------------------------------------------
e9576ca5 270
f75ae77c
JS
271static const wxChar *FontFamilyIntToString(int family);
272static int FontFamilyStringToInt(const wxChar *family);
cfe590ae
JS
273
274
275//-----------------------------------------------------------------------------
276// helper class - wxFontPreviewCtrl
277//-----------------------------------------------------------------------------
278
279class WXDLLEXPORT wxFontPreviewCtrl : public wxWindow
280{
281public:
282 wxFontPreviewCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = 0) :
283 wxWindow(parent, id, pos, sz, style)
284 {
285 SetBackgroundColour(*wxWHITE);
286 }
287
288private:
289 void OnPaint(wxPaintEvent& event);
290 DECLARE_EVENT_TABLE()
291};
292
293BEGIN_EVENT_TABLE(wxFontPreviewCtrl, wxWindow)
294 EVT_PAINT(wxFontPreviewCtrl::OnPaint)
295END_EVENT_TABLE()
296
297void wxFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
298{
299 wxPaintDC dc(this);
300
301 wxSize size = GetSize();
302 wxFont font = GetFont();
303
304 if ( font.Ok() )
305 {
306 dc.SetFont(font);
307 // Calculate vertical centre
308 long w = 0, h = 0;
309 dc.GetTextExtent( wxT("X"), &w, &h);
310 dc.SetTextForeground(GetForegroundColour());
311 dc.SetClippingRegion(2, 2, size.x-4, size.y-4);
312 dc.DrawText(_("ABCDEFGabcdefg12345"),
313 10, size.y/2 - h/2);
314 dc.DestroyClippingRegion();
315 }
316}
317
318/*
319 * A control for displaying a small preview of a colour or bitmap
320 */
321
322class wxFontColourSwatchCtrl: public wxControl
323{
324 DECLARE_CLASS(wxFontColourSwatchCtrl)
325public:
326 wxFontColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
d3c7fc99 327 virtual ~wxFontColourSwatchCtrl();
cfe590ae
JS
328
329 void OnPaint(wxPaintEvent& event);
330 void OnMouseEvent(wxMouseEvent& event);
331
332 void SetColour(const wxColour& colour) { m_colour = colour; SetBackgroundColour(m_colour); }
333
334 wxColour& GetColour() { return m_colour; }
335
336 virtual wxSize DoGetBestSize() const { return GetSize(); }
337
338protected:
339 wxColour m_colour;
340
341DECLARE_EVENT_TABLE()
342};
343
344/*
345 * A control for displaying a small preview of a colour or bitmap
346 */
347
348BEGIN_EVENT_TABLE(wxFontColourSwatchCtrl, wxControl)
349 EVT_MOUSE_EVENTS(wxFontColourSwatchCtrl::OnMouseEvent)
350END_EVENT_TABLE()
351
352IMPLEMENT_CLASS(wxFontColourSwatchCtrl, wxControl)
353
354wxFontColourSwatchCtrl::wxFontColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
355 wxControl(parent, id, pos, size, style)
356{
357 SetColour(* wxWHITE);
358 SetBackgroundStyle(wxBG_STYLE_COLOUR);
359}
360
361wxFontColourSwatchCtrl::~wxFontColourSwatchCtrl()
362{
363}
364
365void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent& event)
366{
367 if (event.LeftDown())
368 {
369 wxWindow* parent = GetParent();
370 while (parent != NULL && !parent->IsKindOf(CLASSINFO(wxDialog)) && !parent->IsKindOf(CLASSINFO(wxFrame)))
371 parent = parent->GetParent();
372
373 wxColourData data;
76b49cf4 374 data.SetChooseFull(true);
cfe590ae
JS
375 data.SetColour(m_colour);
376 wxColourDialog *dialog = new wxColourDialog(parent, &data);
377 // Crashes on wxMac (no m_peer)
76b49cf4 378#ifndef __WXMAC__
cfe590ae
JS
379 dialog->SetTitle(_("Background colour"));
380#endif
381 if (dialog->ShowModal() == wxID_OK)
382 {
383 wxColourData retData = dialog->GetColourData();
384 m_colour = retData.GetColour();
385 SetBackgroundColour(m_colour);
386 }
387 dialog->Destroy();
388 Refresh();
389
390 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
937013e0 391 HandleWindowEvent(event);
cfe590ae
JS
392 }
393}
394
395/*!
396 * wxFontDialog type definition
397 */
398
399IMPLEMENT_DYNAMIC_CLASS( wxFontDialog, wxDialog )
400
401/*!
402 * wxFontDialog event table definition
403 */
404
405BEGIN_EVENT_TABLE( wxFontDialog, wxDialog )
406 EVT_LISTBOX( wxID_FONTDIALOG_FACENAME, wxFontDialog::OnFontdialogFacenameSelected )
407 EVT_SPINCTRL( wxID_FONTDIALOG_FONTSIZE, wxFontDialog::OnFontdialogFontsizeUpdated )
408 EVT_TEXT( wxID_FONTDIALOG_FONTSIZE, wxFontDialog::OnFontdialogFontsizeTextUpdated )
409 EVT_CHECKBOX( wxID_FONTDIALOG_BOLD, wxFontDialog::OnFontdialogBoldClick )
410 EVT_CHECKBOX( wxID_FONTDIALOG_ITALIC, wxFontDialog::OnFontdialogItalicClick )
411 EVT_CHECKBOX( wxID_FONTDIALOG_UNDERLINED, wxFontDialog::OnFontdialogUnderlinedClick )
412 EVT_BUTTON( wxID_OK, wxFontDialog::OnOkClick )
413 EVT_BUTTON(wxID_FONTDIALOG_COLOUR, wxFontDialog::OnColourChanged)
414END_EVENT_TABLE()
415
416/*!
417 * wxFontDialog constructors
418 */
419
420wxFontDialog::wxFontDialog( )
e9576ca5
SC
421{
422 m_dialogParent = NULL;
423}
424
cfe590ae 425wxFontDialog::wxFontDialog(wxWindow* parent, const wxFontData& fontData)
e9576ca5 426{
cfe590ae
JS
427 m_dialogParent = NULL;
428
429 Create(parent, fontData);
e9576ca5
SC
430}
431
b9242cc7
DS
432wxFontDialog::~wxFontDialog()
433{
434 // empty
435}
436
cfe590ae
JS
437/*!
438 * wxFontDialog creator
439 */
440
441bool wxFontDialog::Create(wxWindow* parent, const wxFontData& fontData)
72fcdc75 442{
cfe590ae
JS
443 m_fontData = fontData;
444 m_suppressUpdates = false;
445
446 wxString caption = _("Font");
447
448 m_facenameCtrl = NULL;
449 m_sizeCtrl = NULL;
450 m_boldCtrl = NULL;
451 m_italicCtrl = NULL;
452 m_underlinedCtrl = NULL;
453 m_colourCtrl = NULL;
454 m_previewCtrl = NULL;
455
456 InitializeFont();
457
458 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
459 wxDialog::Create( parent, wxID_ANY, caption, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
460
461 CreateControls();
462 GetSizer()->Fit(this);
463 GetSizer()->SetSizeHints(this);
464 Centre();
465
466 return true;
72fcdc75
RN
467}
468
cfe590ae
JS
469/*!
470 * Control creation for wxFontDialog
471 */
472
473void wxFontDialog::CreateControls()
76b49cf4 474{
cfe590ae
JS
475 wxFontDialog* itemDialog1 = this;
476
477 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
478 itemDialog1->SetSizer(itemBoxSizer2);
479
480 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
481 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
482
483 wxFlexGridSizer* itemFlexGridSizer4 = new wxFlexGridSizer(6, 2, 10, 0);
484 itemFlexGridSizer4->AddGrowableRow(4);
485 itemFlexGridSizer4->AddGrowableCol(1);
486 itemBoxSizer3->Add(itemFlexGridSizer4, 1, wxGROW|wxALL, 5);
487
488 wxStaticText* itemStaticText5 = new wxStaticText( itemDialog1, wxID_STATIC, _("Font:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 489 itemFlexGridSizer4->Add(itemStaticText5, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5);
cfe590ae
JS
490
491 wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxVERTICAL);
492 itemFlexGridSizer4->Add(itemBoxSizer6, 0, wxGROW|wxGROW, 5);
493
494 wxString* m_facenameCtrlStrings = NULL;
495 m_facenameCtrl = new wxListBox( itemDialog1, wxID_FONTDIALOG_FACENAME, wxDefaultPosition, wxSize(320, 100), 0, m_facenameCtrlStrings, wxLB_SINGLE );
496 itemBoxSizer6->Add(m_facenameCtrl, 0, wxGROW|wxALL, 5);
497
498 wxStaticText* itemStaticText8 = new wxStaticText( itemDialog1, wxID_STATIC, _("Size:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 499 itemFlexGridSizer4->Add(itemStaticText8, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
cfe590ae
JS
500
501 m_sizeCtrl = new wxSpinCtrl( itemDialog1, wxID_FONTDIALOG_FONTSIZE, _T("12"), wxDefaultPosition, wxSize(60, -1), wxSP_ARROW_KEYS, 1, 300, 12 );
502 m_sizeCtrl->SetHelpText(_("The font size in points."));
503 if (ShowToolTips())
504 m_sizeCtrl->SetToolTip(_("The font size in points."));
505 itemFlexGridSizer4->Add(m_sizeCtrl, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
506
507 wxStaticText* itemStaticText10 = new wxStaticText( itemDialog1, wxID_STATIC, _("Style:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 508 itemFlexGridSizer4->Add(itemStaticText10, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
cfe590ae
JS
509
510 wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
511 itemFlexGridSizer4->Add(itemBoxSizer11, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
512
513 m_boldCtrl = new wxCheckBox( itemDialog1, wxID_FONTDIALOG_BOLD, _("Bold"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE );
514 m_boldCtrl->SetValue(false);
515 m_boldCtrl->SetHelpText(_("Check to make the font bold."));
516 if (ShowToolTips())
517 m_boldCtrl->SetToolTip(_("Check to make the font bold."));
518 itemBoxSizer11->Add(m_boldCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
519
520 m_italicCtrl = new wxCheckBox( itemDialog1, wxID_FONTDIALOG_ITALIC, _("Italic"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE );
521 m_italicCtrl->SetValue(false);
522 m_italicCtrl->SetHelpText(_("Check to make the font italic."));
523 if (ShowToolTips())
524 m_italicCtrl->SetToolTip(_("Check to make the font italic."));
525 itemBoxSizer11->Add(m_italicCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
526
527 if (m_fontData.GetEnableEffects())
528 {
529 m_underlinedCtrl = new wxCheckBox( itemDialog1, wxID_FONTDIALOG_UNDERLINED, _("Underlined"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE );
530 m_underlinedCtrl->SetValue(false);
531 m_underlinedCtrl->SetHelpText(_("Check to make the font underlined."));
532 if (ShowToolTips())
533 m_underlinedCtrl->SetToolTip(_("Check to make the font underlined."));
534 itemBoxSizer11->Add(m_underlinedCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
535 }
76b49cf4 536
cfe590ae
JS
537 if (m_fontData.GetEnableEffects())
538 {
539 wxStaticText* itemStaticText15 = new wxStaticText( itemDialog1, wxID_STATIC, _("Colour:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 540 itemFlexGridSizer4->Add(itemStaticText15, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5);
76b49cf4 541
cfe590ae
JS
542 m_colourCtrl = new wxFontColourSwatchCtrl( itemDialog1, wxID_FONTDIALOG_COLOUR, wxDefaultPosition, wxSize(-1, 30), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
543 m_colourCtrl->SetHelpText(_("Click to change the font colour."));
544 if (ShowToolTips())
545 m_colourCtrl->SetToolTip(_("Click to change the font colour."));
546 itemFlexGridSizer4->Add(m_colourCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
547 }
548
549 wxStaticText* itemStaticText17 = new wxStaticText( itemDialog1, wxID_STATIC, _("Preview:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 550 itemFlexGridSizer4->Add(itemStaticText17, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5);
cfe590ae
JS
551
552 m_previewCtrl = new wxFontPreviewCtrl( itemDialog1, wxID_FONTDIALOG_PREVIEW, wxDefaultPosition, wxSize(-1, 70), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
553 m_previewCtrl->SetHelpText(_("Shows a preview of the font."));
554 if (ShowToolTips())
555 m_previewCtrl->SetToolTip(_("Shows a preview of the font."));
556 itemFlexGridSizer4->Add(m_previewCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
557
558 wxBoxSizer* itemBoxSizer19 = new wxBoxSizer(wxHORIZONTAL);
559 itemBoxSizer3->Add(itemBoxSizer19, 0, wxALIGN_RIGHT|wxALL, 5);
560
561 wxButton* itemButton20 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
562 itemButton20->SetHelpText(_("Click to cancel changes to the font."));
563 if (ShowToolTips())
564 itemButton20->SetToolTip(_("Click to cancel changes to the font."));
565 itemBoxSizer19->Add(itemButton20, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
566
567 wxButton* itemButton21 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
568 itemButton21->SetDefault();
569 itemButton21->SetHelpText(_("Click to confirm changes to the font."));
570 if (ShowToolTips())
571 itemButton21->SetToolTip(_("Click to confirm changes to the font."));
572 itemBoxSizer19->Add(itemButton21, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
573
574 wxFontEnumerator enumerator;
575 enumerator.EnumerateFacenames();
89bb8035 576 wxArrayString facenames = enumerator.GetFacenames();
cfe590ae
JS
577 if (facenames)
578 {
89bb8035
VZ
579 facenames.Add(_("<Any>"));
580 facenames.Add(_("<Any Roman>"));
581 facenames.Add(_("<Any Decorative>"));
582 facenames.Add(_("<Any Modern>"));
583 facenames.Add(_("<Any Script>"));
584 facenames.Add(_("<Any Swiss>"));
585 facenames.Add(_("<Any Teletype>"));
586 facenames.Sort();
587 m_facenameCtrl->Append(facenames);
cfe590ae
JS
588 }
589
590 InitializeControls();
591 m_previewCtrl->SetFont(m_dialogFont);
592 if (m_fontData.GetColour().Ok())
593 {
594 m_previewCtrl->SetForegroundColour(m_fontData.GetColour());
595 }
596 m_previewCtrl->Refresh();
597}
598
599/*!
600 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
601 */
602
603void wxFontDialog::OnFontdialogFontsizeUpdated( wxSpinEvent& WXUNUSED(event) )
604{
605 ChangeFont();
606}
607
608/*!
609 * wxEVT_COMMAND_TEXT_UPDATED event handler for wxID_FONTDIALOG_FONTSIZE
610 */
611
612void wxFontDialog::OnFontdialogFontsizeTextUpdated( wxCommandEvent& WXUNUSED(event) )
e9576ca5 613{
cfe590ae
JS
614 ChangeFont();
615}
e9576ca5 616
cfe590ae
JS
617/*!
618 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
619 */
e9576ca5 620
cfe590ae
JS
621void wxFontDialog::OnFontdialogBoldClick( wxCommandEvent& WXUNUSED(event) )
622{
623 ChangeFont();
624}
625
626/*!
627 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_ITALIC
628 */
629
630void wxFontDialog::OnFontdialogItalicClick( wxCommandEvent& WXUNUSED(event) )
631{
632 ChangeFont();
633}
634
635/*!
636 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_UNDERLINED
637 */
638
639void wxFontDialog::OnFontdialogUnderlinedClick( wxCommandEvent& WXUNUSED(event) )
640{
641 ChangeFont();
642}
643
644/*!
645 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
646 */
647
648void wxFontDialog::OnOkClick( wxCommandEvent& event )
649{
650 event.Skip();
651}
652
653
654/*!
655 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for wxID_FONTDIALOG_FACENAME
656 */
657
658void wxFontDialog::OnFontdialogFacenameSelected( wxCommandEvent& WXUNUSED(event) )
659{
660 ChangeFont();
661}
662
663void wxFontDialog::OnColourChanged(wxCommandEvent & WXUNUSED(event))
664{
665 m_fontData.SetColour(m_colourCtrl->GetColour());
666 m_previewCtrl->SetForegroundColour(m_colourCtrl->GetColour());
667 m_previewCtrl->Refresh();
668}
669
670/*!
671 * Should we show tooltips?
672 */
673
674bool wxFontDialog::ShowToolTips()
675{
676 return true;
677}
678
679void wxFontDialog::InitializeFont()
680{
681 int fontFamily = wxSWISS;
682 int fontWeight = wxNORMAL;
683 int fontStyle = wxNORMAL;
684 int fontSize = 12;
685 bool fontUnderline = false;
686 wxString fontName;
687
688 if (m_fontData.m_initialFont.Ok())
689 {
690 fontFamily = m_fontData.m_initialFont.GetFamily();
691 fontWeight = m_fontData.m_initialFont.GetWeight();
692 fontStyle = m_fontData.m_initialFont.GetStyle();
693 fontSize = m_fontData.m_initialFont.GetPointSize();
694 fontUnderline = m_fontData.m_initialFont.GetUnderlined();
695 fontName = m_fontData.m_initialFont.GetFaceName();
696 }
697
698 m_dialogFont = wxFont(fontSize, fontFamily, fontStyle,
699 fontWeight, fontUnderline, fontName);
700
701 if (m_previewCtrl)
702 m_previewCtrl->SetFont(m_dialogFont);
703
704 m_fontData.SetChosenFont(m_dialogFont);
705}
706
707/// Set controls according to current font
708void wxFontDialog::InitializeControls()
709{
710 m_suppressUpdates = true;
711
712 if (m_underlinedCtrl)
713 m_underlinedCtrl->SetValue(m_dialogFont.GetUnderlined());
714
715 m_boldCtrl->SetValue(m_dialogFont.GetWeight() == wxBOLD);
716 m_italicCtrl->SetValue(m_dialogFont.GetStyle() == wxITALIC);
717 m_sizeCtrl->SetValue(m_dialogFont.GetPointSize());
76b49cf4 718
cfe590ae
JS
719 wxString facename = m_dialogFont.GetFaceName();
720 if (facename.empty() || m_facenameCtrl->FindString(facename) == wxNOT_FOUND)
721 {
f75ae77c 722 facename = FontFamilyIntToString(m_dialogFont.GetFamily());
cfe590ae
JS
723 }
724 m_facenameCtrl->SetStringSelection(facename);
725
726 if (m_colourCtrl && m_fontData.GetColour().Ok())
727 {
728 m_colourCtrl->SetColour(m_fontData.GetColour());
729 m_colourCtrl->Refresh();
730 }
731
732 m_suppressUpdates = false;
733}
734
735/// Respond to font change
736void wxFontDialog::ChangeFont()
737{
738 if (m_suppressUpdates)
739 return;
740
741 bool underlined = m_underlinedCtrl ? m_underlinedCtrl->GetValue() : false;
742 bool italic = m_italicCtrl->GetValue();
743 bool bold = m_boldCtrl->GetValue();
744 int size = m_sizeCtrl->GetValue();
745 wxString facename = m_facenameCtrl->GetStringSelection();
746
f75ae77c 747 int family = FontFamilyStringToInt(facename);
cfe590ae
JS
748 if (family == -1)
749 family = wxDEFAULT;
750 else
751 facename = wxEmptyString;
752
753 m_dialogFont = wxFont(size, family, italic ? wxITALIC : wxNORMAL, bold ? wxBOLD : wxNORMAL,
754 underlined, facename);
755
756 m_fontData.SetChosenFont(m_dialogFont);
757
758 m_previewCtrl->SetFont(m_dialogFont);
759 m_previewCtrl->Refresh();
760}
761
762void wxFontDialog::SetData(const wxFontData& fontdata)
763{
764 m_fontData = fontdata;
e9576ca5
SC
765}
766
72fcdc75
RN
767bool wxFontDialog::IsShown() const
768{
769 return false;
770}
771
e9576ca5
SC
772int wxFontDialog::ShowModal()
773{
cfe590ae
JS
774 return wxDialog::ShowModal();
775}
776
777void wxFontDialog::OnPanelClose()
778{
e9576ca5
SC
779}
780
f75ae77c 781const wxChar *FontFamilyIntToString(int family)
cfe590ae
JS
782{
783 switch (family)
784 {
785 case wxROMAN:
786 return _("<Any Roman>");
787 case wxDECORATIVE:
788 return _("<Any Decorative>");
789 case wxMODERN:
790 return _("<Any Modern>");
791 case wxSCRIPT:
792 return _("<Any Script>");
793 case wxTELETYPE:
794 return _("<Any Teletype>");
795 case wxSWISS:
796 default:
797 return _("<Any Swiss>");
798 }
799}
800
f75ae77c 801int FontFamilyStringToInt(const wxChar *family)
cfe590ae
JS
802{
803 if (!family)
804 return wxSWISS;
805
22d29469 806 if (wxStrcmp(family, _("<Any Roman>")) == 0)
cfe590ae
JS
807 return wxROMAN;
808 else if (wxStrcmp(family, _("<Any Decorative>")) == 0)
809 return wxDECORATIVE;
810 else if (wxStrcmp(family, _("<Any Modern>")) == 0)
811 return wxMODERN;
812 else if (wxStrcmp(family, _("<Any Script>")) == 0)
813 return wxSCRIPT;
814 else if (wxStrcmp(family, _("<Any Teletype>")) == 0)
815 return wxTELETYPE;
816 else if (wxStrcmp(family, _("<Any Swiss>")) == 0)
817 return wxSWISS;
818 else return -1;
819}
820
821#endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
822
72c1ba98
VZ
823#endif // wxMAC_USE_EXPERIMENTAL_FONTDIALOG
824
825#endif // wxUSE_FONTDLG