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