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