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