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