]> git.saurik.com Git - wxWidgets.git/blob - src/richtext/richtextfontpage.cpp
Fix wxSTC compilation without wxUSE_DRAG_AND_DROP after r65827.
[wxWidgets.git] / src / richtext / richtextfontpage.cpp
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
12 #include "wx/richtext/richtextfontpage.h"
13
14 /*!
15 * wxRichTextFontPage type definition
16 */
17
18 IMPLEMENT_DYNAMIC_CLASS( wxRichTextFontPage, wxPanel )
19
20 /*!
21 * wxRichTextFontPage event table definition
22 */
23
24 BEGIN_EVENT_TABLE( wxRichTextFontPage, wxPanel )
25 EVT_LISTBOX( ID_RICHTEXTFONTPAGE_FACELISTBOX, wxRichTextFontPage::OnFaceListBoxSelected )
26 EVT_BUTTON( ID_RICHTEXTFONTPAGE_COLOURCTRL, wxRichTextFontPage::OnColourClicked )
27 EVT_BUTTON( ID_RICHTEXTFONTPAGE_BGCOLOURCTRL, wxRichTextFontPage::OnColourClicked )
28
29 ////@begin wxRichTextFontPage event table entries
30 EVT_TEXT( ID_RICHTEXTFONTPAGE_FACETEXTCTRL, wxRichTextFontPage::OnFaceTextCtrlUpdated )
31
32 EVT_TEXT( ID_RICHTEXTFONTPAGE_SIZETEXTCTRL, wxRichTextFontPage::OnSizeTextCtrlUpdated )
33
34 EVT_LISTBOX( ID_RICHTEXTFONTPAGE_SIZELISTBOX, wxRichTextFontPage::OnSizeListBoxSelected )
35
36 EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_STYLECTRL, wxRichTextFontPage::OnStyleCtrlSelected )
37
38 EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_WEIGHTCTRL, wxRichTextFontPage::OnWeightCtrlSelected )
39
40 EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL, wxRichTextFontPage::OnUnderliningCtrlSelected )
41
42 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL, wxRichTextFontPage::OnStrikethroughctrlClick )
43
44 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_CAPSCTRL, wxRichTextFontPage::OnCapsctrlClick )
45
46 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_SUPERSCRIPT, wxRichTextFontPage::OnRichtextfontpageSuperscriptClick )
47
48 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_SUBSCRIPT, wxRichTextFontPage::OnRichtextfontpageSubscriptClick )
49
50 ////@end wxRichTextFontPage event table entries
51
52 END_EVENT_TABLE()
53
54 /*!
55 * wxRichTextFontPage constructors
56 */
57
58 wxRichTextFontPage::wxRichTextFontPage( )
59 {
60 Init();
61 }
62
63 wxRichTextFontPage::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 */
72
73 void wxRichTextFontPage::Init()
74 {
75 m_dontUpdate = false;
76 m_colourPresent = false;
77 m_bgColourPresent = false;
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;
88 m_bgColourCtrl = NULL;
89 m_strikethroughCtrl = NULL;
90 m_capitalsCtrl = NULL;
91 m_superscriptCtrl = NULL;
92 m_subscriptCtrl = NULL;
93 m_previewCtrl = NULL;
94 ////@end wxRichTextFontPage member initialisation
95 }
96
97 /*!
98 * wxRichTextFontPage creator
99 */
100
101 bool 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
120 void 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 );
138 itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
139
140 m_faceTextCtrl = new wxTextCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_FACETEXTCTRL, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
141 m_faceTextCtrl->SetHelpText(_("Type a font name."));
142 if (wxRichTextFontPage::ShowToolTips())
143 m_faceTextCtrl->SetToolTip(_("Type a font name."));
144 itemBoxSizer5->Add(m_faceTextCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
145
146 m_faceListBox = new wxRichTextFontListBox( itemPanel1, ID_RICHTEXTFONTPAGE_FACELISTBOX, wxDefaultPosition, wxSize(200, 100), 0 );
147 m_faceListBox->SetHelpText(_("Lists the available fonts."));
148 if (wxRichTextFontPage::ShowToolTips())
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 );
156 itemBoxSizer9->Add(itemStaticText10, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
157
158 m_sizeTextCtrl = new wxTextCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_SIZETEXTCTRL, wxT(""), wxDefaultPosition, wxSize(50, -1), 0 );
159 m_sizeTextCtrl->SetHelpText(_("Type a size in points."));
160 if (wxRichTextFontPage::ShowToolTips())
161 m_sizeTextCtrl->SetToolTip(_("Type a size in points."));
162 itemBoxSizer9->Add(m_sizeTextCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
163
164 wxArrayString m_sizeListBoxStrings;
165 m_sizeListBox = new wxListBox( itemPanel1, ID_RICHTEXTFONTPAGE_SIZELISTBOX, wxDefaultPosition, wxSize(50, -1), m_sizeListBoxStrings, wxLB_SINGLE );
166 m_sizeListBox->SetHelpText(_("Lists font sizes in points."));
167 if (wxRichTextFontPage::ShowToolTips())
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);
175 itemBoxSizer13->Add(itemBoxSizer14, 0, wxGROW, 5);
176
177 wxStaticText* itemStaticText15 = new wxStaticText( itemPanel1, wxID_STATIC, _("Font st&yle:"), wxDefaultPosition, wxDefaultSize, 0 );
178 itemBoxSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
179
180 wxArrayString m_styleCtrlStrings;
181 m_styleCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_STYLECTRL, wxT(""), wxDefaultPosition, wxSize(110, -1), m_styleCtrlStrings, wxCB_READONLY );
182 m_styleCtrl->SetHelpText(_("Select regular or italic style."));
183 if (wxRichTextFontPage::ShowToolTips())
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);
188 itemBoxSizer13->Add(itemBoxSizer17, 0, wxGROW, 5);
189
190 wxStaticText* itemStaticText18 = new wxStaticText( itemPanel1, wxID_STATIC, _("Font &weight:"), wxDefaultPosition, wxDefaultSize, 0 );
191 itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
192
193 wxArrayString m_weightCtrlStrings;
194 m_weightCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_WEIGHTCTRL, wxT(""), wxDefaultPosition, wxSize(110, -1), m_weightCtrlStrings, wxCB_READONLY );
195 m_weightCtrl->SetHelpText(_("Select regular or bold."));
196 if (wxRichTextFontPage::ShowToolTips())
197 m_weightCtrl->SetToolTip(_("Select regular or bold."));
198 itemBoxSizer17->Add(m_weightCtrl, 0, wxGROW|wxALL, 5);
199
200 wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL);
201 itemBoxSizer13->Add(itemBoxSizer20, 0, wxGROW, 5);
202
203 wxStaticText* itemStaticText21 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Underlining:"), wxDefaultPosition, wxDefaultSize, 0 );
204 itemBoxSizer20->Add(itemStaticText21, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
205
206 wxArrayString m_underliningCtrlStrings;
207 m_underliningCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL, wxT(""), wxDefaultPosition, wxSize(110, -1), m_underliningCtrlStrings, wxCB_READONLY );
208 m_underliningCtrl->SetHelpText(_("Select underlining or no underlining."));
209 if (wxRichTextFontPage::ShowToolTips())
210 m_underliningCtrl->SetToolTip(_("Select underlining or no underlining."));
211 itemBoxSizer20->Add(m_underliningCtrl, 0, wxGROW|wxALL, 5);
212
213 itemBoxSizer13->Add(0, 0, 1, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5);
214
215 wxBoxSizer* itemBoxSizer24 = new wxBoxSizer(wxVERTICAL);
216 itemBoxSizer13->Add(itemBoxSizer24, 0, wxGROW, 5);
217
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 );
222 m_colourCtrl->SetHelpText(_("Click to change the text colour."));
223 if (wxRichTextFontPage::ShowToolTips())
224 m_colourCtrl->SetToolTip(_("Click to change the text colour."));
225 itemBoxSizer24->Add(m_colourCtrl, 0, wxGROW|wxALL, 5);
226
227 wxBoxSizer* itemBoxSizer27 = new wxBoxSizer(wxVERTICAL);
228 itemBoxSizer13->Add(itemBoxSizer27, 0, wxGROW, 5);
229
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);
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."));
245 if (wxRichTextFontPage::ShowToolTips())
246 m_strikethroughCtrl->SetToolTip(_("Check to show a line through the text."));
247 itemBoxSizer30->Add(m_strikethroughCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
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."));
252 if (wxRichTextFontPage::ShowToolTips())
253 m_capitalsCtrl->SetToolTip(_("Check to show the text in capitals."));
254 itemBoxSizer30->Add(m_capitalsCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
255
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."));
261 itemBoxSizer30->Add(m_superscriptCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
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."));
268 itemBoxSizer30->Add(m_subscriptCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
269
270 itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL, 5);
271
272 m_previewCtrl = new wxRichTextFontPreviewCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_PREVIEWCTRL, wxDefaultPosition, wxSize(100, 60), 0 );
273 m_previewCtrl->SetHelpText(_("Shows a preview of the font settings."));
274 if (wxRichTextFontPage::ShowToolTips())
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
303 bool wxRichTextFontPage::TransferDataFromWindow()
304 {
305 wxPanel::TransferDataFromWindow();
306
307 wxRichTextAttr* attr = GetAttributes();
308
309 if (m_faceListBox->GetSelection() != wxNOT_FOUND)
310 {
311 wxString faceName = m_faceListBox->GetFaceName(m_faceListBox->GetSelection());
312 if (!faceName.IsEmpty())
313 {
314 attr->SetFontFaceName(faceName);
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 {
326 attr->SetFontSize(sz);
327 }
328 }
329 else
330 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_SIZE));
331
332 if (m_styleCtrl->GetSelection() != wxNOT_FOUND)
333 {
334 wxFontStyle style;
335 if (m_styleCtrl->GetStringSelection() == _("Italic"))
336 style = wxFONTSTYLE_ITALIC;
337 else
338 style = wxFONTSTYLE_NORMAL;
339
340 attr->SetFontStyle(style);
341 }
342 else
343 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_ITALIC));
344
345 if (m_weightCtrl->GetSelection() != wxNOT_FOUND)
346 {
347 wxFontWeight weight;
348 if (m_weightCtrl->GetStringSelection() == _("Bold"))
349 weight = wxFONTWEIGHT_BOLD;
350 else
351 weight = wxFONTWEIGHT_NORMAL;
352
353 attr->SetFontWeight(weight);
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
366 attr->SetFontUnderlined(underlined);
367 }
368 else
369 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_UNDERLINE));
370
371 if (m_colourPresent)
372 {
373 attr->SetTextColour(m_colourCtrl->GetColour());
374 }
375 else
376 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_TEXT_COLOUR));
377
378 if (m_bgColourPresent)
379 {
380 attr->SetBackgroundColour(m_bgColourCtrl->GetColour());
381 }
382 else
383 attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_BACKGROUND_COLOUR));
384
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);
398
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 }
404
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 {
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) );
422 }
423
424 return true;
425 }
426
427 bool wxRichTextFontPage::TransferDataToWindow()
428 {
429 wxPanel::TransferDataToWindow();
430
431 m_dontUpdate = true;
432 wxRichTextAttr* attr = GetAttributes();
433
434 if (attr->HasFontFaceName())
435 {
436 m_faceTextCtrl->SetValue(attr->GetFontFaceName());
437 m_faceListBox->SetFaceNameSelection(attr->GetFont().GetFaceName());
438 }
439 else
440 {
441 m_faceTextCtrl->SetValue(wxEmptyString);
442 m_faceListBox->SetFaceNameSelection(wxEmptyString);
443 }
444
445 if (attr->HasFontSize())
446 {
447 wxString strSize = wxString::Format(wxT("%d"), attr->GetFontSize());
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
458 if (attr->HasFontWeight())
459 {
460 if (attr->GetFontWeight() == wxBOLD)
461 m_weightCtrl->SetSelection(1);
462 else
463 m_weightCtrl->SetSelection(0);
464 }
465 else
466 {
467 m_weightCtrl->SetSelection(wxNOT_FOUND);
468 }
469
470 if (attr->HasFontItalic())
471 {
472 if (attr->GetFontStyle() == wxITALIC)
473 m_styleCtrl->SetSelection(1);
474 else
475 m_styleCtrl->SetSelection(0);
476 }
477 else
478 {
479 m_styleCtrl->SetSelection(wxNOT_FOUND);
480 }
481
482 if (attr->HasFontUnderlined())
483 {
484 if (attr->GetFontUnderlined())
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 {
496 m_colourCtrl->SetColour(attr->GetTextColour());
497 m_colourPresent = true;
498 }
499
500 if (attr->HasBackgroundColour())
501 {
502 m_bgColourCtrl->SetColour(attr->GetBackgroundColour());
503 m_bgColourPresent = true;
504 }
505
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);
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 {
548 m_superscriptCtrl->Set3StateValue(wxCHK_UNDETERMINED);
549 m_subscriptCtrl->Set3StateValue(wxCHK_UNDETERMINED);
550 }
551 }
552 else
553 {
554 m_strikethroughCtrl->Set3StateValue(wxCHK_UNDETERMINED);
555 m_capitalsCtrl->Set3StateValue(wxCHK_UNDETERMINED);
556 m_superscriptCtrl->Set3StateValue(wxCHK_UNDETERMINED);
557 m_subscriptCtrl->Set3StateValue(wxCHK_UNDETERMINED);
558 }
559
560 UpdatePreview();
561
562 m_dontUpdate = false;
563
564 return true;
565 }
566
567 wxRichTextAttr* wxRichTextFontPage::GetAttributes()
568 {
569 return wxRichTextFormattingDialog::GetDialogAttributes(this);
570 }
571
572 /// Updates the font preview
573 void wxRichTextFontPage::UpdatePreview()
574 {
575 wxRichTextAttr attr;
576
577 if (m_colourPresent)
578 m_previewCtrl->SetForegroundColour(m_colourCtrl->GetBackgroundColour());
579
580 if (m_bgColourPresent)
581 m_previewCtrl->SetBackgroundColour(m_bgColourCtrl->GetBackgroundColour());
582
583 if (m_faceListBox->GetSelection() != wxNOT_FOUND)
584 {
585 wxString faceName = m_faceListBox->GetFaceName(m_faceListBox->GetSelection());
586 attr.SetFontFaceName(faceName);
587 }
588
589 wxString strSize = m_sizeTextCtrl->GetValue();
590 if (!strSize.IsEmpty())
591 {
592 int sz = wxAtoi(strSize);
593 if (sz > 0)
594 attr.SetFontSize(sz);
595 }
596
597 if (m_styleCtrl->GetSelection() != wxNOT_FOUND)
598 {
599 wxFontStyle style;
600 if (m_styleCtrl->GetStringSelection() == _("Italic"))
601 style = wxFONTSTYLE_ITALIC;
602 else
603 style = wxFONTSTYLE_NORMAL;
604
605 attr.SetFontStyle(style);
606 }
607
608 if (m_weightCtrl->GetSelection() != wxNOT_FOUND)
609 {
610 wxFontWeight weight;
611 if (m_weightCtrl->GetStringSelection() == _("Bold"))
612 weight = wxFONTWEIGHT_BOLD;
613 else
614 weight = wxFONTWEIGHT_NORMAL;
615
616 attr.SetFontWeight(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 attr.SetFontUnderlined(underlined);
628 }
629
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 }
641
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
647 wxFont font = attr.GetFont();
648 m_previewCtrl->SetFont(font);
649 m_previewCtrl->SetTextEffects(textEffects);
650 m_previewCtrl->Refresh();
651 }
652
653 /*!
654 * Should we show tooltips?
655 */
656
657 bool wxRichTextFontPage::ShowToolTips()
658 {
659 return wxRichTextFormattingDialog::ShowToolTips();
660 }
661
662 /*!
663 * Get bitmap resources
664 */
665
666 wxBitmap 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
679 wxIcon 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
692 void 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 {
714 m_faceListBox->ScrollToRow(i);
715 break;
716 }
717 }
718 }
719 }
720 }
721
722
723 /*!
724 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_SIZETEXTCTRL
725 */
726
727 void 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
743 void 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
758 void 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
773 void 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
783 void 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
793 void wxRichTextFontPage::OnWeightCtrlSelected( wxCommandEvent& WXUNUSED(event) )
794 {
795 UpdatePreview();
796 }
797
798 void wxRichTextFontPage::OnColourClicked( wxCommandEvent& event )
799 {
800 if (event.GetId() == m_colourCtrl->GetId())
801 m_colourPresent = true;
802 else if (event.GetId() == m_bgColourCtrl->GetId())
803 m_bgColourPresent = true;
804
805 UpdatePreview();
806 }
807 /*!
808 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL
809 */
810
811 void wxRichTextFontPage::OnStrikethroughctrlClick( wxCommandEvent& WXUNUSED(event) )
812 {
813 UpdatePreview();
814 }
815
816 /*!
817 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_CAPSCTRL
818 */
819
820 void wxRichTextFontPage::OnCapsctrlClick( wxCommandEvent& WXUNUSED(event) )
821 {
822 UpdatePreview();
823 }
824
825 /*!
826 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUPERSCRIPT
827 */
828
829 void wxRichTextFontPage::OnRichtextfontpageSuperscriptClick( wxCommandEvent& WXUNUSED(event) )
830 {
831 if ( m_superscriptCtrl->Get3StateValue() == wxCHK_CHECKED)
832 m_subscriptCtrl->Set3StateValue( wxCHK_UNCHECKED );
833
834 UpdatePreview();
835 }
836
837 /*!
838 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUBSCRIPT
839 */
840
841 void wxRichTextFontPage::OnRichtextfontpageSubscriptClick( wxCommandEvent& WXUNUSED(event) )
842 {
843 if ( m_subscriptCtrl->Get3StateValue() == wxCHK_CHECKED)
844 m_superscriptCtrl->Set3StateValue( wxCHK_UNCHECKED );
845
846 UpdatePreview();
847 }