]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/fontdlg.cpp
add wxUSE_DATAVIEWCTRL check to fix a hundred compilation errors
[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
49#include "wx/mac/private.h"
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() ;
76b49cf4 69
509b4ecc
SC
70 wxMacCarbonEvent cEvent( event );
71 switch(cEvent.GetKind())
72 {
73 case kEventFontSelection :
74 {
ec8a8e04 75 ATSUFontID fontId = 0 ;
509b4ecc 76 if ( cEvent.GetParameter<ATSUFontID>(kEventParamATSUFontID, &fontId) == noErr )
76b49cf4 77 {
509b4ecc
SC
78 FMFontStyle fontStyle = cEvent.GetParameter<FMFontStyle>(kEventParamFMFontStyle);
79 FMFontSize fontSize = cEvent.GetParameter<FMFontSize>(kEventParamFMFontSize);
80
509b4ecc 81 CFStringRef cfName = NULL;
ec8a8e04
SC
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;
509b4ecc 90 char *c = NULL;
76b49cf4 91 OSStatus err = ATSUFindFontName(fontId , kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
509b4ecc
SC
92 kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
93 if ( err == noErr)
94 {
95 actualLength += 1 ;
96 char *c = (char*)malloc( actualLength );
76b49cf4 97 err = ATSUFindFontName(fontId, kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
509b4ecc
SC
98 kFontNoLanguageCode, actualLength, c , NULL, NULL);
99 cfName = CFStringCreateWithCharacters(NULL, (UniChar*) c, (actualLength-1) >> 1);
100 }
101 else
102 {
76b49cf4 103 err = ATSUFindFontName(fontId , kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
509b4ecc
SC
104 kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
105 if ( err == noErr )
106 {
107 actualLength += 1 ;
108 c = (char*)malloc(actualLength);
76b49cf4 109 err = ATSUFindFontName(fontId, kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
509b4ecc
SC
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);
ec8a8e04
SC
117#endif
118
509b4ecc
SC
119 if ( cfName!=NULL )
120 {
121 fontdata.m_chosenFont.SetFaceName(wxMacCFStringHolder(cfName).AsString(wxLocale::GetSystemEncoding()));
122 fontdata.m_chosenFont.SetPointSize(fontSize);
f3ba97e8
SC
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);
509b4ecc
SC
126 }
127 }
128
129 RGBColor fontColor ;
130 if ( cEvent.GetParameter<RGBColor>(kEventParamFontColor, &fontColor) == noErr )
055de350
VZ
131 {
132 fontdata.m_fontColour = fontColor;
133 }
509b4ecc
SC
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 ;
cc59d939 154 for ( ItemCount i = 0 ; i < count ; ++i)
509b4ecc
SC
155 {
156 if ( tagPtr[i] == kATSUColorTag && sizePtr[i] == sizeof(RGBColor))
157 {
81741494 158 fontdata.m_fontColour = *(RGBColor *)valuesPtr;
509b4ecc
SC
159 break ;
160 }
161 bytePtr = (UInt32*)( (UInt8*)bytePtr + sizePtr[i]);
162 }
163 }
164 }
165 }
166 }
167 }
168 break ;
169 } ;
76b49cf4 170
509b4ecc
SC
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
89954433 189bool wxFontDialog::Create(wxWindow *WXUNUSED(parent), const wxFontData& data)
509b4ecc
SC
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 }
76b49cf4 203
509b4ecc
SC
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
76b49cf4 214 if ( !FPIsFontPanelVisible() )
509b4ecc 215 FPShowHideFontPanel();
76b49cf4 216
509b4ecc 217 int retval = RunMixedFontDialog(this);
76b49cf4 218
509b4ecc 219 ::RemoveEventHandler(handler);
76b49cf4 220
509b4ecc
SC
221 return retval ;
222}
223
224#else
356c775f
RN
225
226#if !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
227
551caf8b
RN
228#undef wxFontDialog
229
230#include "wx/mac/fontdlg.h"
231
cfe590ae
JS
232#include "wx/fontenum.h"
233#include "wx/colordlg.h"
234#include "wx/spinctrl.h"
72fcdc75 235
1553abf4
RN
236// ---------------------------------------------------------------------------
237// wxFontDialog stub for mac OS's without a native font dialog
238// ---------------------------------------------------------------------------
e9576ca5 239
f75ae77c
JS
240static const wxChar *FontFamilyIntToString(int family);
241static int FontFamilyStringToInt(const wxChar *family);
cfe590ae
JS
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);
d3c7fc99 296 virtual ~wxFontColourSwatchCtrl();
cfe590ae
JS
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;
76b49cf4 343 data.SetChooseFull(true);
cfe590ae
JS
344 data.SetColour(m_colour);
345 wxColourDialog *dialog = new wxColourDialog(parent, &data);
346 // Crashes on wxMac (no m_peer)
76b49cf4 347#ifndef __WXMAC__
cfe590ae
JS
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( )
e9576ca5
SC
390{
391 m_dialogParent = NULL;
392}
393
cfe590ae 394wxFontDialog::wxFontDialog(wxWindow* parent, const wxFontData& fontData)
e9576ca5 395{
cfe590ae
JS
396 m_dialogParent = NULL;
397
398 Create(parent, fontData);
e9576ca5
SC
399}
400
b9242cc7
DS
401wxFontDialog::~wxFontDialog()
402{
403 // empty
404}
405
cfe590ae
JS
406/*!
407 * wxFontDialog creator
408 */
409
410bool wxFontDialog::Create(wxWindow* parent, const wxFontData& fontData)
72fcdc75 411{
cfe590ae
JS
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;
72fcdc75
RN
436}
437
cfe590ae
JS
438/*!
439 * Control creation for wxFontDialog
440 */
441
442void wxFontDialog::CreateControls()
76b49cf4 443{
cfe590ae
JS
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 );
69ce77e2 458 itemFlexGridSizer4->Add(itemStaticText5, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5);
cfe590ae
JS
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 );
69ce77e2 468 itemFlexGridSizer4->Add(itemStaticText8, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
cfe590ae
JS
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 );
69ce77e2 477 itemFlexGridSizer4->Add(itemStaticText10, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
cfe590ae
JS
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 }
76b49cf4 505
cfe590ae
JS
506 if (m_fontData.GetEnableEffects())
507 {
508 wxStaticText* itemStaticText15 = new wxStaticText( itemDialog1, wxID_STATIC, _("Colour:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 509 itemFlexGridSizer4->Add(itemStaticText15, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5);
76b49cf4 510
cfe590ae
JS
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 );
69ce77e2 519 itemFlexGridSizer4->Add(itemStaticText17, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5);
cfe590ae
JS
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();
89bb8035 545 wxArrayString facenames = enumerator.GetFacenames();
cfe590ae
JS
546 if (facenames)
547 {
89bb8035
VZ
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);
cfe590ae
JS
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) )
e9576ca5 582{
cfe590ae
JS
583 ChangeFont();
584}
e9576ca5 585
cfe590ae
JS
586/*!
587 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for wxID_FONTDIALOG_BOLD
588 */
e9576ca5 589
cfe590ae
JS
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());
76b49cf4 687
cfe590ae
JS
688 wxString facename = m_dialogFont.GetFaceName();
689 if (facename.empty() || m_facenameCtrl->FindString(facename) == wxNOT_FOUND)
690 {
f75ae77c 691 facename = FontFamilyIntToString(m_dialogFont.GetFamily());
cfe590ae
JS
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
f75ae77c 716 int family = FontFamilyStringToInt(facename);
cfe590ae
JS
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;
e9576ca5
SC
734}
735
72fcdc75
RN
736bool wxFontDialog::IsShown() const
737{
738 return false;
739}
740
e9576ca5
SC
741int wxFontDialog::ShowModal()
742{
cfe590ae
JS
743 return wxDialog::ShowModal();
744}
745
746void wxFontDialog::OnPanelClose()
747{
e9576ca5
SC
748}
749
f75ae77c 750const wxChar *FontFamilyIntToString(int family)
cfe590ae
JS
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
f75ae77c 770int FontFamilyStringToInt(const wxChar *family)
cfe590ae
JS
771{
772 if (!family)
773 return wxSWISS;
774
22d29469 775 if (wxStrcmp(family, _("<Any Roman>")) == 0)
cfe590ae
JS
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
72c1ba98
VZ
792#endif // wxMAC_USE_EXPERIMENTAL_FONTDIALOG
793
794#endif // wxUSE_FONTDLG