]> git.saurik.com Git - wxWidgets.git/blame - src/richtext/richtextfontpage.cpp
Check for invalid items in generic wxDataViewCtrl::GetSelections().
[wxWidgets.git] / src / richtext / richtextfontpage.cpp
CommitLineData
97ff49b3 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/richtext/richtextfontpage.cpp
97ff49b3
JS
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
603f702b 18IMPLEMENT_DYNAMIC_CLASS( wxRichTextFontPage, wxRichTextDialogPage )
97ff49b3
JS
19
20/*!
21 * wxRichTextFontPage event table definition
22 */
23
603f702b 24BEGIN_EVENT_TABLE( wxRichTextFontPage, wxRichTextDialogPage )
97ff49b3
JS
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
603f702b 54IMPLEMENT_HELP_PROVISION(wxRichTextFontPage)
97ff49b3
JS
55/*!
56 * wxRichTextFontPage constructors
57 */
58
59wxRichTextFontPage::wxRichTextFontPage( )
60{
61 Init();
62}
63
64wxRichTextFontPage::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 */
5778b3c8 73
97ff49b3
JS
74void wxRichTextFontPage::Init()
75{
76 m_dontUpdate = false;
77 m_colourPresent = false;
50283a51 78 m_bgColourPresent = false;
97ff49b3
JS
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;
50283a51 89 m_bgColourCtrl = NULL;
42688aea
JS
90 m_strikethroughCtrl = NULL;
91 m_capitalsCtrl = NULL;
30bf7630
JS
92 m_superscriptCtrl = NULL;
93 m_subscriptCtrl = NULL;
97ff49b3
JS
94 m_previewCtrl = NULL;
95////@end wxRichTextFontPage member initialisation
96}
97
98/*!
99 * wxRichTextFontPage creator
100 */
101
102bool wxRichTextFontPage::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
103{
104////@begin wxRichTextFontPage creation
603f702b 105 wxRichTextDialogPage::Create( parent, id, pos, size, style );
97ff49b3
JS
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
121void wxRichTextFontPage::CreateControls()
122{
123////@begin wxRichTextFontPage content construction
603f702b 124 wxRichTextFontPage* itemRichTextDialogPage1 = this;
97ff49b3
JS
125
126 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
603f702b 127 itemRichTextDialogPage1->SetSizer(itemBoxSizer2);
97ff49b3
JS
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
603f702b 138 wxStaticText* itemStaticText6 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Font:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 139 itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3 140
603f702b 141 m_faceTextCtrl = new wxTextCtrl( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_FACETEXTCTRL, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
97ff49b3 142 m_faceTextCtrl->SetHelpText(_("Type a font name."));
2fce6547 143 if (wxRichTextFontPage::ShowToolTips())
97ff49b3
JS
144 m_faceTextCtrl->SetToolTip(_("Type a font name."));
145 itemBoxSizer5->Add(m_faceTextCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
146
603f702b 147 m_faceListBox = new wxRichTextFontListBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_FACELISTBOX, wxDefaultPosition, wxSize(200, 100), 0 );
97ff49b3 148 m_faceListBox->SetHelpText(_("Lists the available fonts."));
2fce6547 149 if (wxRichTextFontPage::ShowToolTips())
97ff49b3
JS
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
603f702b 156 wxStaticText* itemStaticText10 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Size:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 157 itemBoxSizer9->Add(itemStaticText10, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3 158
603f702b 159 m_sizeTextCtrl = new wxTextCtrl( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_SIZETEXTCTRL, wxEmptyString, wxDefaultPosition, wxSize(50, -1), 0 );
97ff49b3 160 m_sizeTextCtrl->SetHelpText(_("Type a size in points."));
2fce6547 161 if (wxRichTextFontPage::ShowToolTips())
97ff49b3
JS
162 m_sizeTextCtrl->SetToolTip(_("Type a size in points."));
163 itemBoxSizer9->Add(m_sizeTextCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
164
2fce6547 165 wxArrayString m_sizeListBoxStrings;
603f702b 166 m_sizeListBox = new wxListBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_SIZELISTBOX, wxDefaultPosition, wxSize(50, -1), m_sizeListBoxStrings, wxLB_SINGLE );
97ff49b3 167 m_sizeListBox->SetHelpText(_("Lists font sizes in points."));
2fce6547 168 if (wxRichTextFontPage::ShowToolTips())
97ff49b3
JS
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);
50283a51 176 itemBoxSizer13->Add(itemBoxSizer14, 0, wxGROW, 5);
97ff49b3 177
603f702b 178 wxStaticText* itemStaticText15 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("Font st&yle:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 179 itemBoxSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3 180
2fce6547 181 wxArrayString m_styleCtrlStrings;
603f702b 182 m_styleCtrl = new wxComboBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_STYLECTRL, wxEmptyString, wxDefaultPosition, wxSize(110, -1), m_styleCtrlStrings, wxCB_READONLY );
97ff49b3 183 m_styleCtrl->SetHelpText(_("Select regular or italic style."));
2fce6547 184 if (wxRichTextFontPage::ShowToolTips())
97ff49b3
JS
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);
50283a51 189 itemBoxSizer13->Add(itemBoxSizer17, 0, wxGROW, 5);
97ff49b3 190
603f702b 191 wxStaticText* itemStaticText18 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("Font &weight:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 192 itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3 193
2fce6547 194 wxArrayString m_weightCtrlStrings;
603f702b 195 m_weightCtrl = new wxComboBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_WEIGHTCTRL, wxEmptyString, wxDefaultPosition, wxSize(110, -1), m_weightCtrlStrings, wxCB_READONLY );
97ff49b3 196 m_weightCtrl->SetHelpText(_("Select regular or bold."));
2fce6547 197 if (wxRichTextFontPage::ShowToolTips())
97ff49b3
JS
198 m_weightCtrl->SetToolTip(_("Select regular or bold."));
199 itemBoxSizer17->Add(m_weightCtrl, 0, wxGROW|wxALL, 5);
200
201 wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL);
50283a51 202 itemBoxSizer13->Add(itemBoxSizer20, 0, wxGROW, 5);
97ff49b3 203
603f702b 204 wxStaticText* itemStaticText21 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Underlining:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 205 itemBoxSizer20->Add(itemStaticText21, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3 206
2fce6547 207 wxArrayString m_underliningCtrlStrings;
603f702b 208 m_underliningCtrl = new wxComboBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL, wxEmptyString, wxDefaultPosition, wxSize(110, -1), m_underliningCtrlStrings, wxCB_READONLY );
97ff49b3 209 m_underliningCtrl->SetHelpText(_("Select underlining or no underlining."));
2fce6547 210 if (wxRichTextFontPage::ShowToolTips())
97ff49b3
JS
211 m_underliningCtrl->SetToolTip(_("Select underlining or no underlining."));
212 itemBoxSizer20->Add(m_underliningCtrl, 0, wxGROW|wxALL, 5);
213
50283a51 214 itemBoxSizer13->Add(0, 0, 1, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5);
97ff49b3 215
50283a51
JS
216 wxBoxSizer* itemBoxSizer24 = new wxBoxSizer(wxVERTICAL);
217 itemBoxSizer13->Add(itemBoxSizer24, 0, wxGROW, 5);
97ff49b3 218
603f702b 219 wxStaticText* itemStaticText25 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Colour:"), wxDefaultPosition, wxDefaultSize, 0 );
50283a51
JS
220 itemBoxSizer24->Add(itemStaticText25, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
221
603f702b 222 m_colourCtrl = new wxRichTextColourSwatchCtrl( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_COLOURCTRL, wxDefaultPosition, wxSize(40, 20), 0 );
97ff49b3 223 m_colourCtrl->SetHelpText(_("Click to change the text colour."));
2fce6547 224 if (wxRichTextFontPage::ShowToolTips())
97ff49b3 225 m_colourCtrl->SetToolTip(_("Click to change the text colour."));
50283a51
JS
226 itemBoxSizer24->Add(m_colourCtrl, 0, wxGROW|wxALL, 5);
227
228 wxBoxSizer* itemBoxSizer27 = new wxBoxSizer(wxVERTICAL);
229 itemBoxSizer13->Add(itemBoxSizer27, 0, wxGROW, 5);
97ff49b3 230
603f702b 231 wxStaticText* itemStaticText28 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Bg colour:"), wxDefaultPosition, wxDefaultSize, 0 );
50283a51
JS
232 itemBoxSizer27->Add(itemStaticText28, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
233
603f702b 234 m_bgColourCtrl = new wxRichTextColourSwatchCtrl( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_BGCOLOURCTRL, wxDefaultPosition, wxSize(40, 20), 0 );
50283a51
JS
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);
42688aea 242
603f702b 243 m_strikethroughCtrl = new wxCheckBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL, _("&Strikethrough"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE );
42688aea
JS
244 m_strikethroughCtrl->SetValue(false);
245 m_strikethroughCtrl->SetHelpText(_("Check to show a line through the text."));
2fce6547 246 if (wxRichTextFontPage::ShowToolTips())
42688aea 247 m_strikethroughCtrl->SetToolTip(_("Check to show a line through the text."));
50283a51 248 itemBoxSizer30->Add(m_strikethroughCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
42688aea 249
603f702b 250 m_capitalsCtrl = new wxCheckBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_CAPSCTRL, _("Ca&pitals"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE );
42688aea
JS
251 m_capitalsCtrl->SetValue(false);
252 m_capitalsCtrl->SetHelpText(_("Check to show the text in capitals."));
2fce6547 253 if (wxRichTextFontPage::ShowToolTips())
42688aea 254 m_capitalsCtrl->SetToolTip(_("Check to show the text in capitals."));
50283a51 255 itemBoxSizer30->Add(m_capitalsCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
42688aea 256
603f702b 257 m_superscriptCtrl = new wxCheckBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_SUPERSCRIPT, _("Supe&rscript"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE );
30bf7630
JS
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."));
50283a51 262 itemBoxSizer30->Add(m_superscriptCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
30bf7630 263
603f702b 264 m_subscriptCtrl = new wxCheckBox( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_SUBSCRIPT, _("Subscrip&t"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE );
30bf7630
JS
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."));
50283a51 269 itemBoxSizer30->Add(m_subscriptCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
30bf7630 270
2fce6547 271 itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL, 5);
97ff49b3 272
603f702b 273 m_previewCtrl = new wxRichTextFontPreviewCtrl( itemRichTextDialogPage1, ID_RICHTEXTFONTPAGE_PREVIEWCTRL, wxDefaultPosition, wxSize(100, 60), 0 );
97ff49b3 274 m_previewCtrl->SetHelpText(_("Shows a preview of the font settings."));
2fce6547 275 if (wxRichTextFontPage::ShowToolTips())
97ff49b3
JS
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
304bool wxRichTextFontPage::TransferDataFromWindow()
305{
306 wxPanel::TransferDataFromWindow();
307
24777478 308 wxRichTextAttr* attr = GetAttributes();
97ff49b3 309
603f702b 310 if (!m_faceTextCtrl->GetValue().IsEmpty())
97ff49b3 311 {
603f702b
JS
312 wxString faceName = m_faceTextCtrl->GetValue();
313 attr->SetFontFaceName(faceName);
97ff49b3
JS
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 {
44cc96a8 324 attr->SetFontSize(sz);
97ff49b3
JS
325 }
326 }
327 else
328 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_SIZE));
329
330 if (m_styleCtrl->GetSelection() != wxNOT_FOUND)
331 {
7d76fbd5 332 wxFontStyle style;
97ff49b3 333 if (m_styleCtrl->GetStringSelection() == _("Italic"))
7d76fbd5 334 style = wxFONTSTYLE_ITALIC;
97ff49b3 335 else
7d76fbd5 336 style = wxFONTSTYLE_NORMAL;
97ff49b3 337
44cc96a8 338 attr->SetFontStyle(style);
97ff49b3
JS
339 }
340 else
341 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_ITALIC));
342
343 if (m_weightCtrl->GetSelection() != wxNOT_FOUND)
344 {
7d76fbd5 345 wxFontWeight weight;
97ff49b3 346 if (m_weightCtrl->GetStringSelection() == _("Bold"))
7d76fbd5 347 weight = wxFONTWEIGHT_BOLD;
97ff49b3 348 else
7d76fbd5 349 weight = wxFONTWEIGHT_NORMAL;
97ff49b3 350
44cc96a8 351 attr->SetFontWeight(weight);
97ff49b3
JS
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
44cc96a8 364 attr->SetFontUnderlined(underlined);
97ff49b3
JS
365 }
366 else
367 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_UNDERLINE));
368
369 if (m_colourPresent)
370 {
50283a51 371 attr->SetTextColour(m_colourCtrl->GetColour());
97ff49b3
JS
372 }
373 else
374 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_TEXT_COLOUR));
44cc96a8 375
50283a51
JS
376 if (m_bgColourPresent)
377 {
378 attr->SetBackgroundColour(m_bgColourCtrl->GetColour());
379 }
380 else
381 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_BACKGROUND_COLOUR));
382
42688aea
JS
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);
44cc96a8 396
42688aea
JS
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 }
97ff49b3 402
30bf7630
JS
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 {
d1e5be0e
JS
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) );
30bf7630
JS
420 }
421
97ff49b3
JS
422 return true;
423}
424
425bool wxRichTextFontPage::TransferDataToWindow()
426{
427 wxPanel::TransferDataToWindow();
428
429 m_dontUpdate = true;
24777478 430 wxRichTextAttr* attr = GetAttributes();
97ff49b3 431
44cc96a8 432 if (attr->HasFontFaceName())
97ff49b3 433 {
44cc96a8 434 m_faceTextCtrl->SetValue(attr->GetFontFaceName());
97ff49b3
JS
435 m_faceListBox->SetFaceNameSelection(attr->GetFont().GetFaceName());
436 }
437 else
438 {
439 m_faceTextCtrl->SetValue(wxEmptyString);
440 m_faceListBox->SetFaceNameSelection(wxEmptyString);
441 }
442
44cc96a8 443 if (attr->HasFontSize())
97ff49b3 444 {
44cc96a8 445 wxString strSize = wxString::Format(wxT("%d"), attr->GetFontSize());
97ff49b3
JS
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
44cc96a8 456 if (attr->HasFontWeight())
97ff49b3 457 {
44cc96a8 458 if (attr->GetFontWeight() == wxBOLD)
97ff49b3
JS
459 m_weightCtrl->SetSelection(1);
460 else
461 m_weightCtrl->SetSelection(0);
462 }
463 else
464 {
465 m_weightCtrl->SetSelection(wxNOT_FOUND);
466 }
467
44cc96a8 468 if (attr->HasFontItalic())
97ff49b3 469 {
44cc96a8 470 if (attr->GetFontStyle() == wxITALIC)
97ff49b3
JS
471 m_styleCtrl->SetSelection(1);
472 else
473 m_styleCtrl->SetSelection(0);
474 }
475 else
476 {
477 m_styleCtrl->SetSelection(wxNOT_FOUND);
478 }
479
44cc96a8 480 if (attr->HasFontUnderlined())
97ff49b3 481 {
44cc96a8 482 if (attr->GetFontUnderlined())
97ff49b3
JS
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 {
3638bb5c 494 m_colourCtrl->SetColour(attr->GetTextColour());
97ff49b3
JS
495 m_colourPresent = true;
496 }
497
50283a51
JS
498 if (attr->HasBackgroundColour())
499 {
500 m_bgColourCtrl->SetColour(attr->GetBackgroundColour());
501 m_bgColourPresent = true;
502 }
503
42688aea
JS
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);
30bf7630
JS
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 {
d1e5be0e
JS
546 m_superscriptCtrl->Set3StateValue(wxCHK_UNDETERMINED);
547 m_subscriptCtrl->Set3StateValue(wxCHK_UNDETERMINED);
30bf7630 548 }
42688aea
JS
549 }
550 else
551 {
552 m_strikethroughCtrl->Set3StateValue(wxCHK_UNDETERMINED);
553 m_capitalsCtrl->Set3StateValue(wxCHK_UNDETERMINED);
d1e5be0e
JS
554 m_superscriptCtrl->Set3StateValue(wxCHK_UNDETERMINED);
555 m_subscriptCtrl->Set3StateValue(wxCHK_UNDETERMINED);
42688aea
JS
556 }
557
97ff49b3
JS
558 UpdatePreview();
559
560 m_dontUpdate = false;
561
562 return true;
563}
564
24777478 565wxRichTextAttr* wxRichTextFontPage::GetAttributes()
97ff49b3
JS
566{
567 return wxRichTextFormattingDialog::GetDialogAttributes(this);
568}
569
570/// Updates the font preview
571void wxRichTextFontPage::UpdatePreview()
572{
24777478 573 wxRichTextAttr attr;
97ff49b3
JS
574
575 if (m_colourPresent)
576 m_previewCtrl->SetForegroundColour(m_colourCtrl->GetBackgroundColour());
577
50283a51
JS
578 if (m_bgColourPresent)
579 m_previewCtrl->SetBackgroundColour(m_bgColourCtrl->GetBackgroundColour());
580
97ff49b3
JS
581 if (m_faceListBox->GetSelection() != wxNOT_FOUND)
582 {
583 wxString faceName = m_faceListBox->GetFaceName(m_faceListBox->GetSelection());
713129f9 584 attr.SetFontFaceName(faceName);
97ff49b3
JS
585 }
586
587 wxString strSize = m_sizeTextCtrl->GetValue();
588 if (!strSize.IsEmpty())
589 {
590 int sz = wxAtoi(strSize);
591 if (sz > 0)
713129f9 592 attr.SetFontSize(sz);
97ff49b3
JS
593 }
594
595 if (m_styleCtrl->GetSelection() != wxNOT_FOUND)
596 {
713129f9 597 wxFontStyle style;
97ff49b3 598 if (m_styleCtrl->GetStringSelection() == _("Italic"))
713129f9 599 style = wxFONTSTYLE_ITALIC;
97ff49b3 600 else
713129f9 601 style = wxFONTSTYLE_NORMAL;
97ff49b3 602
713129f9 603 attr.SetFontStyle(style);
97ff49b3
JS
604 }
605
606 if (m_weightCtrl->GetSelection() != wxNOT_FOUND)
607 {
713129f9 608 wxFontWeight weight;
97ff49b3 609 if (m_weightCtrl->GetStringSelection() == _("Bold"))
713129f9 610 weight = wxFONTWEIGHT_BOLD;
97ff49b3 611 else
713129f9 612 weight = wxFONTWEIGHT_NORMAL;
97ff49b3 613
713129f9 614 attr.SetFontWeight(weight);
97ff49b3
JS
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
713129f9 625 attr.SetFontUnderlined(underlined);
97ff49b3 626 }
44cc96a8 627
42688aea
JS
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 }
97ff49b3 639
30bf7630
JS
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
713129f9 645 wxFont font = attr.GetFont();
97ff49b3 646 m_previewCtrl->SetFont(font);
42688aea 647 m_previewCtrl->SetTextEffects(textEffects);
97ff49b3
JS
648 m_previewCtrl->Refresh();
649}
650
651/*!
652 * Should we show tooltips?
653 */
654
655bool wxRichTextFontPage::ShowToolTips()
656{
dadd4f55 657 return wxRichTextFormattingDialog::ShowToolTips();
97ff49b3
JS
658}
659
660/*!
661 * Get bitmap resources
662 */
663
664wxBitmap 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
677wxIcon 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
690void 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 {
f18eaf26 712 m_faceListBox->ScrollToRow(i);
97ff49b3
JS
713 break;
714 }
715 }
716 }
717 }
718}
719
720
721/*!
722 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_SIZETEXTCTRL
723 */
724
725void 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
741void 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
756void 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
771void 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
781void 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
791void wxRichTextFontPage::OnWeightCtrlSelected( wxCommandEvent& WXUNUSED(event) )
792{
793 UpdatePreview();
794}
795
50283a51 796void wxRichTextFontPage::OnColourClicked( wxCommandEvent& event )
97ff49b3 797{
50283a51
JS
798 if (event.GetId() == m_colourCtrl->GetId())
799 m_colourPresent = true;
800 else if (event.GetId() == m_bgColourCtrl->GetId())
801 m_bgColourPresent = true;
97ff49b3
JS
802
803 UpdatePreview();
804}
42688aea
JS
805/*!
806 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL
807 */
808
809void wxRichTextFontPage::OnStrikethroughctrlClick( wxCommandEvent& WXUNUSED(event) )
810{
811 UpdatePreview();
812}
813
814/*!
815 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_CAPSCTRL
816 */
817
818void wxRichTextFontPage::OnCapsctrlClick( wxCommandEvent& WXUNUSED(event) )
819{
820 UpdatePreview();
821}
822
30bf7630
JS
823/*!
824 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUPERSCRIPT
825 */
826
827void wxRichTextFontPage::OnRichtextfontpageSuperscriptClick( wxCommandEvent& WXUNUSED(event) )
828{
d1e5be0e 829 if ( m_superscriptCtrl->Get3StateValue() == wxCHK_CHECKED)
30bf7630 830 m_subscriptCtrl->Set3StateValue( wxCHK_UNCHECKED );
d1e5be0e 831
30bf7630
JS
832 UpdatePreview();
833}
834
835/*!
836 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUBSCRIPT
837 */
42688aea 838
30bf7630
JS
839void wxRichTextFontPage::OnRichtextfontpageSubscriptClick( wxCommandEvent& WXUNUSED(event) )
840{
d1e5be0e 841 if ( m_subscriptCtrl->Get3StateValue() == wxCHK_CHECKED)
30bf7630 842 m_superscriptCtrl->Set3StateValue( wxCHK_UNCHECKED );
d1e5be0e 843
30bf7630
JS
844 UpdatePreview();
845}