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