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