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