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