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