]> git.saurik.com Git - wxWidgets.git/blame - src/richtext/richtextfontpage.cpp
Converted wxVariant to use wxObject's reference counting facilities. Should make...
[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
42688aea 140 m_faceTextCtrl = new wxTextCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_FACETEXTCTRL, _T(""), 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
42688aea 158 m_sizeTextCtrl = new wxTextCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_SIZETEXTCTRL, _T(""), 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;
50283a51 181 m_styleCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_STYLECTRL, _T(""), 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;
50283a51 194 m_weightCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_WEIGHTCTRL, _T(""), 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;
50283a51 207 m_underliningCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL, _T(""), 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{
575 wxFont font(*wxNORMAL_FONT);
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());
586 font.SetFaceName(faceName);
587 }
588
589 wxString strSize = m_sizeTextCtrl->GetValue();
590 if (!strSize.IsEmpty())
591 {
592 int sz = wxAtoi(strSize);
593 if (sz > 0)
594 font.SetPointSize(sz);
595 }
596
597 if (m_styleCtrl->GetSelection() != wxNOT_FOUND)
598 {
599 int style;
600 if (m_styleCtrl->GetStringSelection() == _("Italic"))
601 style = wxITALIC;
602 else
603 style = wxNORMAL;
604
605 font.SetStyle(style);
606 }
607
608 if (m_weightCtrl->GetSelection() != wxNOT_FOUND)
609 {
610 int weight;
611 if (m_weightCtrl->GetStringSelection() == _("Bold"))
612 weight = wxBOLD;
613 else
614 weight = wxNORMAL;
615
616 font.SetWeight(weight);
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
627 font.SetUnderlined(underlined);
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
97ff49b3 647 m_previewCtrl->SetFont(font);
42688aea 648 m_previewCtrl->SetTextEffects(textEffects);
97ff49b3
JS
649 m_previewCtrl->Refresh();
650}
651
652/*!
653 * Should we show tooltips?
654 */
655
656bool wxRichTextFontPage::ShowToolTips()
657{
dadd4f55 658 return wxRichTextFormattingDialog::ShowToolTips();
97ff49b3
JS
659}
660
661/*!
662 * Get bitmap resources
663 */
664
665wxBitmap wxRichTextFontPage::GetBitmapResource( const wxString& name )
666{
667 // Bitmap retrieval
668////@begin wxRichTextFontPage bitmap retrieval
669 wxUnusedVar(name);
670 return wxNullBitmap;
671////@end wxRichTextFontPage bitmap retrieval
672}
673
674/*!
675 * Get icon resources
676 */
677
678wxIcon wxRichTextFontPage::GetIconResource( const wxString& name )
679{
680 // Icon retrieval
681////@begin wxRichTextFontPage icon retrieval
682 wxUnusedVar(name);
683 return wxNullIcon;
684////@end wxRichTextFontPage icon retrieval
685}
686
687/*!
688 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_FACETEXTCTRL
689 */
690
691void wxRichTextFontPage::OnFaceTextCtrlUpdated( wxCommandEvent& WXUNUSED(event) )
692{
693 if (m_dontUpdate)
694 return;
695
696 wxString facename = m_faceTextCtrl->GetValue();
697 if (!facename.IsEmpty())
698 {
699 if (m_faceListBox->HasFaceName(facename))
700 {
701 m_faceListBox->SetFaceNameSelection(facename);
702 UpdatePreview();
703 }
704 else
705 {
706 // Try to find a partial match
707 const wxArrayString& arr = m_faceListBox->GetFaceNames();
708 size_t i;
709 for (i = 0; i < arr.GetCount(); i++)
710 {
711 if (arr[i].Mid(0, facename.Length()).Lower() == facename.Lower())
712 {
f18eaf26 713 m_faceListBox->ScrollToRow(i);
97ff49b3
JS
714 break;
715 }
716 }
717 }
718 }
719}
720
721
722/*!
723 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_SIZETEXTCTRL
724 */
725
726void wxRichTextFontPage::OnSizeTextCtrlUpdated( wxCommandEvent& WXUNUSED(event) )
727{
728 if (m_dontUpdate)
729 return;
730
731 wxString strSize = m_sizeTextCtrl->GetValue();
732 if (!strSize.IsEmpty() && m_sizeListBox->FindString(strSize) != wxNOT_FOUND)
733 m_sizeListBox->SetStringSelection(strSize);
734 UpdatePreview();
735}
736
737
738/*!
739 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_SIZELISTBOX
740 */
741
742void wxRichTextFontPage::OnSizeListBoxSelected( wxCommandEvent& event )
743{
744 m_dontUpdate = true;
745
746 m_sizeTextCtrl->SetValue(event.GetString());
747
748 m_dontUpdate = false;
749
750 UpdatePreview();
751}
752
753/*!
754 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_FACELISTBOX
755 */
756
757void wxRichTextFontPage::OnFaceListBoxSelected( wxCommandEvent& WXUNUSED(event) )
758{
759 m_dontUpdate = true;
760
761 m_faceTextCtrl->SetValue(m_faceListBox->GetFaceName(m_faceListBox->GetSelection()));
762
763 m_dontUpdate = false;
764
765 UpdatePreview();
766}
767
768/*!
769 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_STYLECTRL
770 */
771
772void wxRichTextFontPage::OnStyleCtrlSelected( wxCommandEvent& WXUNUSED(event) )
773{
774 UpdatePreview();
775}
776
777
778/*!
779 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL
780 */
781
782void wxRichTextFontPage::OnUnderliningCtrlSelected( wxCommandEvent& WXUNUSED(event) )
783{
784 UpdatePreview();
785}
786
787
788/*!
789 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_WEIGHTCTRL
790 */
791
792void wxRichTextFontPage::OnWeightCtrlSelected( wxCommandEvent& WXUNUSED(event) )
793{
794 UpdatePreview();
795}
796
50283a51 797void wxRichTextFontPage::OnColourClicked( wxCommandEvent& event )
97ff49b3 798{
50283a51
JS
799 if (event.GetId() == m_colourCtrl->GetId())
800 m_colourPresent = true;
801 else if (event.GetId() == m_bgColourCtrl->GetId())
802 m_bgColourPresent = true;
97ff49b3
JS
803
804 UpdatePreview();
805}
42688aea
JS
806/*!
807 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL
808 */
809
810void wxRichTextFontPage::OnStrikethroughctrlClick( wxCommandEvent& WXUNUSED(event) )
811{
812 UpdatePreview();
813}
814
815/*!
816 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_CAPSCTRL
817 */
818
819void wxRichTextFontPage::OnCapsctrlClick( wxCommandEvent& WXUNUSED(event) )
820{
821 UpdatePreview();
822}
823
30bf7630
JS
824/*!
825 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUPERSCRIPT
826 */
827
828void wxRichTextFontPage::OnRichtextfontpageSuperscriptClick( wxCommandEvent& WXUNUSED(event) )
829{
d1e5be0e 830 if ( m_superscriptCtrl->Get3StateValue() == wxCHK_CHECKED)
30bf7630 831 m_subscriptCtrl->Set3StateValue( wxCHK_UNCHECKED );
d1e5be0e 832
30bf7630
JS
833 UpdatePreview();
834}
835
836/*!
837 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUBSCRIPT
838 */
42688aea 839
30bf7630
JS
840void wxRichTextFontPage::OnRichtextfontpageSubscriptClick( wxCommandEvent& WXUNUSED(event) )
841{
d1e5be0e 842 if ( m_subscriptCtrl->Get3StateValue() == wxCHK_CHECKED)
30bf7630 843 m_superscriptCtrl->Set3StateValue( wxCHK_UNCHECKED );
d1e5be0e 844
30bf7630
JS
845 UpdatePreview();
846}