]> git.saurik.com Git - wxWidgets.git/blame - src/richtext/richtextfontpage.cpp
don't do anything before including the PCH header
[wxWidgets.git] / src / richtext / richtextfontpage.cpp
CommitLineData
97ff49b3
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/richtext/richeditfontpage.cpp
3// Purpose: Font page for wxRichTextFormattingDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 2006-10-02
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
41a85215 12#include "wx/richtext/richtextfontpage.h"
97ff49b3 13
97ff49b3
JS
14/*!
15 * wxRichTextFontPage type definition
16 */
17
18IMPLEMENT_DYNAMIC_CLASS( wxRichTextFontPage, wxPanel )
19
20/*!
21 * wxRichTextFontPage event table definition
22 */
23
24BEGIN_EVENT_TABLE( wxRichTextFontPage, wxPanel )
25 EVT_LISTBOX( ID_RICHTEXTFONTPAGE_FACELISTBOX, wxRichTextFontPage::OnFaceListBoxSelected )
26 EVT_BUTTON( ID_RICHTEXTFONTPAGE_COLOURCTRL, wxRichTextFontPage::OnColourClicked )
27
28////@begin wxRichTextFontPage event table entries
29 EVT_TEXT( ID_RICHTEXTFONTPAGE_FACETEXTCTRL, wxRichTextFontPage::OnFaceTextCtrlUpdated )
30
31 EVT_TEXT( ID_RICHTEXTFONTPAGE_SIZETEXTCTRL, wxRichTextFontPage::OnSizeTextCtrlUpdated )
32
33 EVT_LISTBOX( ID_RICHTEXTFONTPAGE_SIZELISTBOX, wxRichTextFontPage::OnSizeListBoxSelected )
34
35 EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_STYLECTRL, wxRichTextFontPage::OnStyleCtrlSelected )
36
37 EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_WEIGHTCTRL, wxRichTextFontPage::OnWeightCtrlSelected )
38
39 EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL, wxRichTextFontPage::OnUnderliningCtrlSelected )
40
42688aea
JS
41 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL, wxRichTextFontPage::OnStrikethroughctrlClick )
42
43 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_CAPSCTRL, wxRichTextFontPage::OnCapsctrlClick )
44
97ff49b3
JS
45////@end wxRichTextFontPage event table entries
46
47END_EVENT_TABLE()
48
49/*!
50 * wxRichTextFontPage constructors
51 */
52
53wxRichTextFontPage::wxRichTextFontPage( )
54{
55 Init();
56}
57
58wxRichTextFontPage::wxRichTextFontPage( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
59{
60 Init();
61 Create(parent, id, pos, size, style);
62}
63
64/*!
65 * Initialise members
66 */
5778b3c8 67
97ff49b3
JS
68void wxRichTextFontPage::Init()
69{
70 m_dontUpdate = false;
71 m_colourPresent = false;
72
73////@begin wxRichTextFontPage member initialisation
74 m_faceTextCtrl = NULL;
75 m_faceListBox = NULL;
76 m_sizeTextCtrl = NULL;
77 m_sizeListBox = NULL;
78 m_styleCtrl = NULL;
79 m_weightCtrl = NULL;
80 m_underliningCtrl = NULL;
81 m_colourCtrl = NULL;
42688aea
JS
82 m_strikethroughCtrl = NULL;
83 m_capitalsCtrl = NULL;
97ff49b3
JS
84 m_previewCtrl = NULL;
85////@end wxRichTextFontPage member initialisation
86}
87
88/*!
89 * wxRichTextFontPage creator
90 */
91
92bool wxRichTextFontPage::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
93{
94////@begin wxRichTextFontPage creation
95 wxPanel::Create( parent, id, pos, size, style );
96
97 CreateControls();
98 if (GetSizer())
99 {
100 GetSizer()->SetSizeHints(this);
101 }
102 Centre();
103////@end wxRichTextFontPage creation
104 return true;
105}
106
107/*!
108 * Control creation for wxRichTextFontPage
109 */
110
111void wxRichTextFontPage::CreateControls()
112{
113////@begin wxRichTextFontPage content construction
114 wxRichTextFontPage* itemPanel1 = this;
115
116 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
117 itemPanel1->SetSizer(itemBoxSizer2);
118
119 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
120 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
121
122 wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
123 itemBoxSizer3->Add(itemBoxSizer4, 1, wxGROW, 5);
124
125 wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
126 itemBoxSizer4->Add(itemBoxSizer5, 1, wxGROW, 5);
127
128 wxStaticText* itemStaticText6 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Font:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 129 itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3 130
42688aea 131 m_faceTextCtrl = new wxTextCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_FACETEXTCTRL, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
97ff49b3
JS
132 m_faceTextCtrl->SetHelpText(_("Type a font name."));
133 if (ShowToolTips())
134 m_faceTextCtrl->SetToolTip(_("Type a font name."));
135 itemBoxSizer5->Add(m_faceTextCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
136
137 m_faceListBox = new wxRichTextFontListBox( itemPanel1, ID_RICHTEXTFONTPAGE_FACELISTBOX, wxDefaultPosition, wxSize(200, 140), wxSIMPLE_BORDER );
138 m_faceListBox->SetHelpText(_("Lists the available fonts."));
139 if (ShowToolTips())
140 m_faceListBox->SetToolTip(_("Lists the available fonts."));
141 itemBoxSizer5->Add(m_faceListBox, 1, wxGROW|wxALL|wxFIXED_MINSIZE, 5);
142
143 wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxVERTICAL);
144 itemBoxSizer4->Add(itemBoxSizer9, 0, wxGROW, 5);
145
146 wxStaticText* itemStaticText10 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Size:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 147 itemBoxSizer9->Add(itemStaticText10, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3 148
42688aea 149 m_sizeTextCtrl = new wxTextCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_SIZETEXTCTRL, _T(""), wxDefaultPosition, wxSize(50, -1), 0 );
97ff49b3
JS
150 m_sizeTextCtrl->SetHelpText(_("Type a size in points."));
151 if (ShowToolTips())
152 m_sizeTextCtrl->SetToolTip(_("Type a size in points."));
153 itemBoxSizer9->Add(m_sizeTextCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
154
155 wxString* m_sizeListBoxStrings = NULL;
156 m_sizeListBox = new wxListBox( itemPanel1, ID_RICHTEXTFONTPAGE_SIZELISTBOX, wxDefaultPosition, wxSize(50, -1), 0, m_sizeListBoxStrings, wxLB_SINGLE );
157 m_sizeListBox->SetHelpText(_("Lists font sizes in points."));
158 if (ShowToolTips())
159 m_sizeListBox->SetToolTip(_("Lists font sizes in points."));
160 itemBoxSizer9->Add(m_sizeListBox, 1, wxALIGN_CENTER_HORIZONTAL|wxALL|wxFIXED_MINSIZE, 5);
161
162 wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
163 itemBoxSizer3->Add(itemBoxSizer13, 0, wxGROW, 5);
164
165 wxBoxSizer* itemBoxSizer14 = new wxBoxSizer(wxVERTICAL);
166 itemBoxSizer13->Add(itemBoxSizer14, 1, wxGROW, 5);
167
168 wxStaticText* itemStaticText15 = new wxStaticText( itemPanel1, wxID_STATIC, _("Font st&yle:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 169 itemBoxSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3
JS
170
171 wxString* m_styleCtrlStrings = NULL;
42688aea 172 m_styleCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_STYLECTRL, _T(""), wxDefaultPosition, wxDefaultSize, 0, m_styleCtrlStrings, wxCB_READONLY );
97ff49b3
JS
173 m_styleCtrl->SetHelpText(_("Select regular or italic style."));
174 if (ShowToolTips())
175 m_styleCtrl->SetToolTip(_("Select regular or italic style."));
176 itemBoxSizer14->Add(m_styleCtrl, 0, wxGROW|wxALL, 5);
177
178 wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxVERTICAL);
179 itemBoxSizer13->Add(itemBoxSizer17, 1, wxGROW, 5);
180
181 wxStaticText* itemStaticText18 = new wxStaticText( itemPanel1, wxID_STATIC, _("Font &weight:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 182 itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3
JS
183
184 wxString* m_weightCtrlStrings = NULL;
42688aea 185 m_weightCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_WEIGHTCTRL, _T(""), wxDefaultPosition, wxDefaultSize, 0, m_weightCtrlStrings, wxCB_READONLY );
97ff49b3
JS
186 m_weightCtrl->SetHelpText(_("Select regular or bold."));
187 if (ShowToolTips())
188 m_weightCtrl->SetToolTip(_("Select regular or bold."));
189 itemBoxSizer17->Add(m_weightCtrl, 0, wxGROW|wxALL, 5);
190
191 wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL);
192 itemBoxSizer13->Add(itemBoxSizer20, 1, wxGROW, 5);
193
194 wxStaticText* itemStaticText21 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Underlining:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 195 itemBoxSizer20->Add(itemStaticText21, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3
JS
196
197 wxString* m_underliningCtrlStrings = NULL;
42688aea 198 m_underliningCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL, _T(""), wxDefaultPosition, wxDefaultSize, 0, m_underliningCtrlStrings, wxCB_READONLY );
97ff49b3
JS
199 m_underliningCtrl->SetHelpText(_("Select underlining or no underlining."));
200 if (ShowToolTips())
201 m_underliningCtrl->SetToolTip(_("Select underlining or no underlining."));
202 itemBoxSizer20->Add(m_underliningCtrl, 0, wxGROW|wxALL, 5);
203
204 wxBoxSizer* itemBoxSizer23 = new wxBoxSizer(wxVERTICAL);
205 itemBoxSizer13->Add(itemBoxSizer23, 0, wxGROW, 5);
206
207 wxStaticText* itemStaticText24 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Colour:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 208 itemBoxSizer23->Add(itemStaticText24, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3
JS
209
210 m_colourCtrl = new wxRichTextColourSwatchCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_COLOURCTRL, wxDefaultPosition, wxSize(40, 20), wxSIMPLE_BORDER );
211 m_colourCtrl->SetHelpText(_("Click to change the text colour."));
212 if (ShowToolTips())
213 m_colourCtrl->SetToolTip(_("Click to change the text colour."));
214 itemBoxSizer23->Add(m_colourCtrl, 0, wxALIGN_LEFT|wxALL, 5);
215
42688aea
JS
216 wxBoxSizer* itemBoxSizer26 = new wxBoxSizer(wxHORIZONTAL);
217 itemBoxSizer3->Add(itemBoxSizer26, 0, wxGROW, 5);
218
219 m_strikethroughCtrl = new wxCheckBox( itemPanel1, ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL, _("&Strikethrough"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE );
220 m_strikethroughCtrl->SetValue(false);
221 m_strikethroughCtrl->SetHelpText(_("Check to show a line through the text."));
222 if (ShowToolTips())
223 m_strikethroughCtrl->SetToolTip(_("Check to show a line through the text."));
224 itemBoxSizer26->Add(m_strikethroughCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
225
226 m_capitalsCtrl = new wxCheckBox( itemPanel1, ID_RICHTEXTFONTPAGE_CAPSCTRL, _("Ca&pitals"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE );
227 m_capitalsCtrl->SetValue(false);
228 m_capitalsCtrl->SetHelpText(_("Check to show the text in capitals."));
229 if (ShowToolTips())
230 m_capitalsCtrl->SetToolTip(_("Check to show the text in capitals."));
231 itemBoxSizer26->Add(m_capitalsCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
232
97ff49b3
JS
233 itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
234
235 m_previewCtrl = new wxRichTextFontPreviewCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_PREVIEWCTRL, wxDefaultPosition, wxSize(100, 80), wxSIMPLE_BORDER );
236 m_previewCtrl->SetHelpText(_("Shows a preview of the font settings."));
237 if (ShowToolTips())
238 m_previewCtrl->SetToolTip(_("Shows a preview of the font settings."));
239 itemBoxSizer3->Add(m_previewCtrl, 0, wxGROW|wxALL, 5);
240
241////@end wxRichTextFontPage content construction
242
243 m_faceListBox->UpdateFonts();
244
245 m_styleCtrl->Append(_("Regular"));
246 m_styleCtrl->Append(_("Italic"));
247
248 m_weightCtrl->Append(_("Regular"));
249 m_weightCtrl->Append(_("Bold"));
250
251 m_underliningCtrl->Append(_("Not underlined"));
252 m_underliningCtrl->Append(_("Underlined"));
253
254 wxString nStr;
255 int i;
256 for (i = 8; i < 40; i++)
257 {
258 nStr.Printf(wxT("%d"), i);
259 m_sizeListBox->Append(nStr);
260 }
261 m_sizeListBox->Append(wxT("48"));
262 m_sizeListBox->Append(wxT("72"));
263}
264
265/// Transfer data from/to window
266bool wxRichTextFontPage::TransferDataFromWindow()
267{
268 wxPanel::TransferDataFromWindow();
269
270 wxTextAttrEx* attr = GetAttributes();
271
272 if (m_faceListBox->GetSelection() != wxNOT_FOUND)
273 {
274 wxString faceName = m_faceListBox->GetFaceName(m_faceListBox->GetSelection());
275 if (!faceName.IsEmpty())
276 {
277 wxFont font(attr->GetFont().Ok() ? attr->GetFont() : *wxNORMAL_FONT);
278 font.SetFaceName(faceName);
279 wxSetFontPreservingStyles(*attr, font);
280 attr->SetFlags(attr->GetFlags() | wxTEXT_ATTR_FONT_FACE);
281 }
282 }
283 else
284 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_FACE));
285
286 wxString strSize = m_sizeTextCtrl->GetValue();
287 if (!strSize.IsEmpty())
288 {
289 int sz = wxAtoi(strSize);
290 if (sz > 0)
291 {
292 wxFont font(attr->GetFont().Ok() ? attr->GetFont() : *wxNORMAL_FONT);
293 font.SetPointSize(sz);
294 wxSetFontPreservingStyles(*attr, font);
295 attr->SetFlags(attr->GetFlags() | wxTEXT_ATTR_FONT_SIZE);
296 }
297 }
298 else
299 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_SIZE));
300
301 if (m_styleCtrl->GetSelection() != wxNOT_FOUND)
302 {
303 int style;
304 if (m_styleCtrl->GetStringSelection() == _("Italic"))
305 style = wxITALIC;
306 else
307 style = wxNORMAL;
308
309 wxFont font(attr->GetFont().Ok() ? attr->GetFont() : *wxNORMAL_FONT);
310 font.SetStyle(style);
311 wxSetFontPreservingStyles(*attr, font);
312 attr->SetFlags(attr->GetFlags() | wxTEXT_ATTR_FONT_ITALIC);
313 }
314 else
315 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_ITALIC));
316
317 if (m_weightCtrl->GetSelection() != wxNOT_FOUND)
318 {
319 int weight;
320 if (m_weightCtrl->GetStringSelection() == _("Bold"))
321 weight = wxBOLD;
322 else
323 weight = wxNORMAL;
324
325 wxFont font(attr->GetFont().Ok() ? attr->GetFont() : *wxNORMAL_FONT);
326 font.SetWeight(weight);
327 wxSetFontPreservingStyles(*attr, font);
328 attr->SetFlags(attr->GetFlags() | wxTEXT_ATTR_FONT_WEIGHT);
329 }
330 else
331 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_WEIGHT));
332
333 if (m_underliningCtrl->GetSelection() != wxNOT_FOUND)
334 {
335 bool underlined;
336 if (m_underliningCtrl->GetStringSelection() == _("Underlined"))
337 underlined = true;
338 else
339 underlined = false;
340
341 wxFont font(attr->GetFont().Ok() ? attr->GetFont() : *wxNORMAL_FONT);
342 font.SetUnderlined(underlined);
343 wxSetFontPreservingStyles(*attr, font);
344 attr->SetFlags(attr->GetFlags() | wxTEXT_ATTR_FONT_UNDERLINE);
345 }
346 else
347 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_UNDERLINE));
348
349 if (m_colourPresent)
350 {
351 attr->SetTextColour(m_colourCtrl->GetBackgroundColour());
352 }
353 else
354 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_TEXT_COLOUR));
42688aea
JS
355
356 if (m_strikethroughCtrl->Get3StateValue() != wxCHK_UNDETERMINED)
357 {
358 attr->SetTextEffectFlags(attr->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_STRIKETHROUGH);
359
360 if (m_strikethroughCtrl->Get3StateValue() == wxCHK_CHECKED)
361 attr->SetTextEffects(attr->GetTextEffects() | wxTEXT_ATTR_EFFECT_STRIKETHROUGH);
362 else
363 attr->SetTextEffects(attr->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_STRIKETHROUGH);
364 }
365
366 if (m_capitalsCtrl->Get3StateValue() != wxCHK_UNDETERMINED)
367 {
368 attr->SetTextEffectFlags(attr->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_CAPITALS);
369
370 if (m_capitalsCtrl->Get3StateValue() == wxCHK_CHECKED)
371 attr->SetTextEffects(attr->GetTextEffects() | wxTEXT_ATTR_EFFECT_CAPITALS);
372 else
373 attr->SetTextEffects(attr->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_CAPITALS);
374 }
97ff49b3
JS
375
376 return true;
377}
378
379bool wxRichTextFontPage::TransferDataToWindow()
380{
381 wxPanel::TransferDataToWindow();
382
383 m_dontUpdate = true;
384 wxTextAttrEx* attr = GetAttributes();
385
336d8ae9 386 if (attr->HasFont() && attr->HasFontFaceName())
97ff49b3
JS
387 {
388 m_faceTextCtrl->SetValue(attr->GetFont().GetFaceName());
389 m_faceListBox->SetFaceNameSelection(attr->GetFont().GetFaceName());
390 }
391 else
392 {
393 m_faceTextCtrl->SetValue(wxEmptyString);
394 m_faceListBox->SetFaceNameSelection(wxEmptyString);
395 }
396
336d8ae9 397 if (attr->HasFont() && attr->HasFontSize())
97ff49b3
JS
398 {
399 wxString strSize = wxString::Format(wxT("%d"), attr->GetFont().GetPointSize());
400 m_sizeTextCtrl->SetValue(strSize);
401 if (m_sizeListBox->FindString(strSize) != wxNOT_FOUND)
402 m_sizeListBox->SetStringSelection(strSize);
403 }
404 else
405 {
406 m_sizeTextCtrl->SetValue(wxEmptyString);
407 m_sizeListBox->SetSelection(wxNOT_FOUND);
408 }
409
336d8ae9 410 if (attr->HasFont() && attr->HasFontWeight())
97ff49b3
JS
411 {
412 if (attr->GetFont().GetWeight() == wxBOLD)
413 m_weightCtrl->SetSelection(1);
414 else
415 m_weightCtrl->SetSelection(0);
416 }
417 else
418 {
419 m_weightCtrl->SetSelection(wxNOT_FOUND);
420 }
421
336d8ae9 422 if (attr->HasFont() && attr->HasFontItalic())
97ff49b3
JS
423 {
424 if (attr->GetFont().GetStyle() == wxITALIC)
425 m_styleCtrl->SetSelection(1);
426 else
427 m_styleCtrl->SetSelection(0);
428 }
429 else
430 {
431 m_styleCtrl->SetSelection(wxNOT_FOUND);
432 }
433
336d8ae9 434 if (attr->HasFont() && attr->HasFontUnderlined())
97ff49b3
JS
435 {
436 if (attr->GetFont().GetUnderlined())
437 m_underliningCtrl->SetSelection(1);
438 else
439 m_underliningCtrl->SetSelection(0);
440 }
441 else
442 {
443 m_underliningCtrl->SetSelection(wxNOT_FOUND);
444 }
445
446 if (attr->HasTextColour())
447 {
448 m_colourCtrl->SetBackgroundColour(attr->GetTextColour());
449 m_colourPresent = true;
450 }
451
42688aea
JS
452 if (attr->HasTextEffects())
453 {
454 if (attr->GetTextEffectFlags() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH)
455 {
456 if (attr->GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH)
457 m_strikethroughCtrl->Set3StateValue(wxCHK_CHECKED);
458 else
459 m_strikethroughCtrl->Set3StateValue(wxCHK_UNCHECKED);
460 }
461 else
462 m_strikethroughCtrl->Set3StateValue(wxCHK_UNDETERMINED);
463
464 if (attr->GetTextEffectFlags() & wxTEXT_ATTR_EFFECT_CAPITALS)
465 {
466 if (attr->GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS)
467 m_capitalsCtrl->Set3StateValue(wxCHK_CHECKED);
468 else
469 m_capitalsCtrl->Set3StateValue(wxCHK_UNCHECKED);
470 }
471 else
472 m_capitalsCtrl->Set3StateValue(wxCHK_UNDETERMINED);
473 }
474 else
475 {
476 m_strikethroughCtrl->Set3StateValue(wxCHK_UNDETERMINED);
477 m_capitalsCtrl->Set3StateValue(wxCHK_UNDETERMINED);
478 }
479
97ff49b3
JS
480 UpdatePreview();
481
482 m_dontUpdate = false;
483
484 return true;
485}
486
487wxTextAttrEx* wxRichTextFontPage::GetAttributes()
488{
489 return wxRichTextFormattingDialog::GetDialogAttributes(this);
490}
491
492/// Updates the font preview
493void wxRichTextFontPage::UpdatePreview()
494{
495 wxFont font(*wxNORMAL_FONT);
496
497 if (m_colourPresent)
498 m_previewCtrl->SetForegroundColour(m_colourCtrl->GetBackgroundColour());
499
500 if (m_faceListBox->GetSelection() != wxNOT_FOUND)
501 {
502 wxString faceName = m_faceListBox->GetFaceName(m_faceListBox->GetSelection());
503 font.SetFaceName(faceName);
504 }
505
506 wxString strSize = m_sizeTextCtrl->GetValue();
507 if (!strSize.IsEmpty())
508 {
509 int sz = wxAtoi(strSize);
510 if (sz > 0)
511 font.SetPointSize(sz);
512 }
513
514 if (m_styleCtrl->GetSelection() != wxNOT_FOUND)
515 {
516 int style;
517 if (m_styleCtrl->GetStringSelection() == _("Italic"))
518 style = wxITALIC;
519 else
520 style = wxNORMAL;
521
522 font.SetStyle(style);
523 }
524
525 if (m_weightCtrl->GetSelection() != wxNOT_FOUND)
526 {
527 int weight;
528 if (m_weightCtrl->GetStringSelection() == _("Bold"))
529 weight = wxBOLD;
530 else
531 weight = wxNORMAL;
532
533 font.SetWeight(weight);
534 }
535
536 if (m_underliningCtrl->GetSelection() != wxNOT_FOUND)
537 {
538 bool underlined;
539 if (m_underliningCtrl->GetStringSelection() == _("Underlined"))
540 underlined = true;
541 else
542 underlined = false;
543
544 font.SetUnderlined(underlined);
545 }
42688aea
JS
546
547 int textEffects = 0;
548
549 if (m_strikethroughCtrl->Get3StateValue() == wxCHK_CHECKED)
550 {
551 textEffects |= wxTEXT_ATTR_EFFECT_STRIKETHROUGH;
552 }
553
554 if (m_capitalsCtrl->Get3StateValue() == wxCHK_CHECKED)
555 {
556 textEffects |= wxTEXT_ATTR_EFFECT_CAPITALS;
557 }
97ff49b3
JS
558
559 m_previewCtrl->SetFont(font);
42688aea 560 m_previewCtrl->SetTextEffects(textEffects);
97ff49b3
JS
561 m_previewCtrl->Refresh();
562}
563
564/*!
565 * Should we show tooltips?
566 */
567
568bool wxRichTextFontPage::ShowToolTips()
569{
dadd4f55 570 return wxRichTextFormattingDialog::ShowToolTips();
97ff49b3
JS
571}
572
573/*!
574 * Get bitmap resources
575 */
576
577wxBitmap wxRichTextFontPage::GetBitmapResource( const wxString& name )
578{
579 // Bitmap retrieval
580////@begin wxRichTextFontPage bitmap retrieval
581 wxUnusedVar(name);
582 return wxNullBitmap;
583////@end wxRichTextFontPage bitmap retrieval
584}
585
586/*!
587 * Get icon resources
588 */
589
590wxIcon wxRichTextFontPage::GetIconResource( const wxString& name )
591{
592 // Icon retrieval
593////@begin wxRichTextFontPage icon retrieval
594 wxUnusedVar(name);
595 return wxNullIcon;
596////@end wxRichTextFontPage icon retrieval
597}
598
599/*!
600 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_FACETEXTCTRL
601 */
602
603void wxRichTextFontPage::OnFaceTextCtrlUpdated( wxCommandEvent& WXUNUSED(event) )
604{
605 if (m_dontUpdate)
606 return;
607
608 wxString facename = m_faceTextCtrl->GetValue();
609 if (!facename.IsEmpty())
610 {
611 if (m_faceListBox->HasFaceName(facename))
612 {
613 m_faceListBox->SetFaceNameSelection(facename);
614 UpdatePreview();
615 }
616 else
617 {
618 // Try to find a partial match
619 const wxArrayString& arr = m_faceListBox->GetFaceNames();
620 size_t i;
621 for (i = 0; i < arr.GetCount(); i++)
622 {
623 if (arr[i].Mid(0, facename.Length()).Lower() == facename.Lower())
624 {
f18eaf26 625 m_faceListBox->ScrollToRow(i);
97ff49b3
JS
626 break;
627 }
628 }
629 }
630 }
631}
632
633
634/*!
635 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_SIZETEXTCTRL
636 */
637
638void wxRichTextFontPage::OnSizeTextCtrlUpdated( wxCommandEvent& WXUNUSED(event) )
639{
640 if (m_dontUpdate)
641 return;
642
643 wxString strSize = m_sizeTextCtrl->GetValue();
644 if (!strSize.IsEmpty() && m_sizeListBox->FindString(strSize) != wxNOT_FOUND)
645 m_sizeListBox->SetStringSelection(strSize);
646 UpdatePreview();
647}
648
649
650/*!
651 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_SIZELISTBOX
652 */
653
654void wxRichTextFontPage::OnSizeListBoxSelected( wxCommandEvent& event )
655{
656 m_dontUpdate = true;
657
658 m_sizeTextCtrl->SetValue(event.GetString());
659
660 m_dontUpdate = false;
661
662 UpdatePreview();
663}
664
665/*!
666 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_FACELISTBOX
667 */
668
669void wxRichTextFontPage::OnFaceListBoxSelected( wxCommandEvent& WXUNUSED(event) )
670{
671 m_dontUpdate = true;
672
673 m_faceTextCtrl->SetValue(m_faceListBox->GetFaceName(m_faceListBox->GetSelection()));
674
675 m_dontUpdate = false;
676
677 UpdatePreview();
678}
679
680/*!
681 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_STYLECTRL
682 */
683
684void wxRichTextFontPage::OnStyleCtrlSelected( wxCommandEvent& WXUNUSED(event) )
685{
686 UpdatePreview();
687}
688
689
690/*!
691 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL
692 */
693
694void wxRichTextFontPage::OnUnderliningCtrlSelected( wxCommandEvent& WXUNUSED(event) )
695{
696 UpdatePreview();
697}
698
699
700/*!
701 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_WEIGHTCTRL
702 */
703
704void wxRichTextFontPage::OnWeightCtrlSelected( wxCommandEvent& WXUNUSED(event) )
705{
706 UpdatePreview();
707}
708
709void wxRichTextFontPage::OnColourClicked( wxCommandEvent& WXUNUSED(event) )
710{
711 m_colourPresent = true;
712
713 UpdatePreview();
714}
42688aea
JS
715/*!
716 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL
717 */
718
719void wxRichTextFontPage::OnStrikethroughctrlClick( wxCommandEvent& WXUNUSED(event) )
720{
721 UpdatePreview();
722}
723
724/*!
725 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_CAPSCTRL
726 */
727
728void wxRichTextFontPage::OnCapsctrlClick( wxCommandEvent& WXUNUSED(event) )
729{
730 UpdatePreview();
731}
732
733