1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richeditfontpage.cpp
3 // Purpose: Font page for wxRichTextFormattingDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/richtext/richtextfontpage.h"
15 * wxRichTextFontPage type definition
18 IMPLEMENT_DYNAMIC_CLASS( wxRichTextFontPage
, wxPanel
)
21 * wxRichTextFontPage event table definition
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
)
29 ////@begin wxRichTextFontPage event table entries
30 EVT_TEXT( ID_RICHTEXTFONTPAGE_FACETEXTCTRL
, wxRichTextFontPage::OnFaceTextCtrlUpdated
)
32 EVT_TEXT( ID_RICHTEXTFONTPAGE_SIZETEXTCTRL
, wxRichTextFontPage::OnSizeTextCtrlUpdated
)
34 EVT_LISTBOX( ID_RICHTEXTFONTPAGE_SIZELISTBOX
, wxRichTextFontPage::OnSizeListBoxSelected
)
36 EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_STYLECTRL
, wxRichTextFontPage::OnStyleCtrlSelected
)
38 EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_WEIGHTCTRL
, wxRichTextFontPage::OnWeightCtrlSelected
)
40 EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL
, wxRichTextFontPage::OnUnderliningCtrlSelected
)
42 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL
, wxRichTextFontPage::OnStrikethroughctrlClick
)
44 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_CAPSCTRL
, wxRichTextFontPage::OnCapsctrlClick
)
46 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_SUPERSCRIPT
, wxRichTextFontPage::OnRichtextfontpageSuperscriptClick
)
48 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_SUBSCRIPT
, wxRichTextFontPage::OnRichtextfontpageSubscriptClick
)
50 ////@end wxRichTextFontPage event table entries
55 * wxRichTextFontPage constructors
58 wxRichTextFontPage::wxRichTextFontPage( )
63 wxRichTextFontPage::wxRichTextFontPage( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
66 Create(parent
, id
, pos
, size
, style
);
73 void wxRichTextFontPage::Init()
76 m_colourPresent
= false;
77 m_bgColourPresent
= false;
79 ////@begin wxRichTextFontPage member initialisation
80 m_faceTextCtrl
= NULL
;
82 m_sizeTextCtrl
= NULL
;
86 m_underliningCtrl
= NULL
;
88 m_bgColourCtrl
= NULL
;
89 m_strikethroughCtrl
= NULL
;
90 m_capitalsCtrl
= NULL
;
91 m_superscriptCtrl
= NULL
;
92 m_subscriptCtrl
= NULL
;
94 ////@end wxRichTextFontPage member initialisation
98 * wxRichTextFontPage creator
101 bool wxRichTextFontPage::Create( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
103 ////@begin wxRichTextFontPage creation
104 wxPanel::Create( parent
, id
, pos
, size
, style
);
109 GetSizer()->SetSizeHints(this);
112 ////@end wxRichTextFontPage creation
117 * Control creation for wxRichTextFontPage
120 void wxRichTextFontPage::CreateControls()
122 ////@begin wxRichTextFontPage content construction
123 wxRichTextFontPage
* itemPanel1
= this;
125 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
126 itemPanel1
->SetSizer(itemBoxSizer2
);
128 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
129 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
131 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
132 itemBoxSizer3
->Add(itemBoxSizer4
, 1, wxGROW
, 5);
134 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
135 itemBoxSizer4
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
137 wxStaticText
* itemStaticText6
= new wxStaticText( itemPanel1
, wxID_STATIC
, _("&Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
138 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
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);
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);
152 wxBoxSizer
* itemBoxSizer9
= new wxBoxSizer(wxVERTICAL
);
153 itemBoxSizer4
->Add(itemBoxSizer9
, 0, wxGROW
, 5);
155 wxStaticText
* itemStaticText10
= new wxStaticText( itemPanel1
, wxID_STATIC
, _("&Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
156 itemBoxSizer9
->Add(itemStaticText10
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
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);
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);
171 wxBoxSizer
* itemBoxSizer13
= new wxBoxSizer(wxHORIZONTAL
);
172 itemBoxSizer3
->Add(itemBoxSizer13
, 0, wxGROW
, 5);
174 wxBoxSizer
* itemBoxSizer14
= new wxBoxSizer(wxVERTICAL
);
175 itemBoxSizer13
->Add(itemBoxSizer14
, 0, wxGROW
, 5);
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);
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);
187 wxBoxSizer
* itemBoxSizer17
= new wxBoxSizer(wxVERTICAL
);
188 itemBoxSizer13
->Add(itemBoxSizer17
, 0, wxGROW
, 5);
190 wxStaticText
* itemStaticText18
= new wxStaticText( itemPanel1
, wxID_STATIC
, _("Font &weight:"), wxDefaultPosition
, wxDefaultSize
, 0 );
191 itemBoxSizer17
->Add(itemStaticText18
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
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);
200 wxBoxSizer
* itemBoxSizer20
= new wxBoxSizer(wxVERTICAL
);
201 itemBoxSizer13
->Add(itemBoxSizer20
, 0, wxGROW
, 5);
203 wxStaticText
* itemStaticText21
= new wxStaticText( itemPanel1
, wxID_STATIC
, _("&Underlining:"), wxDefaultPosition
, wxDefaultSize
, 0 );
204 itemBoxSizer20
->Add(itemStaticText21
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
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);
213 itemBoxSizer13
->Add(0, 0, 1, wxALIGN_CENTER_VERTICAL
|wxBOTTOM
, 5);
215 wxBoxSizer
* itemBoxSizer24
= new wxBoxSizer(wxVERTICAL
);
216 itemBoxSizer13
->Add(itemBoxSizer24
, 0, wxGROW
, 5);
218 wxStaticText
* itemStaticText25
= new wxStaticText( itemPanel1
, wxID_STATIC
, _("&Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
219 itemBoxSizer24
->Add(itemStaticText25
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
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);
227 wxBoxSizer
* itemBoxSizer27
= new wxBoxSizer(wxVERTICAL
);
228 itemBoxSizer13
->Add(itemBoxSizer27
, 0, wxGROW
, 5);
230 wxStaticText
* itemStaticText28
= new wxStaticText( itemPanel1
, wxID_STATIC
, _("&Bg colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
231 itemBoxSizer27
->Add(itemStaticText28
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
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);
239 wxBoxSizer
* itemBoxSizer30
= new wxBoxSizer(wxHORIZONTAL
);
240 itemBoxSizer3
->Add(itemBoxSizer30
, 0, wxGROW
, 5);
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);
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);
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);
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);
270 itemBoxSizer3
->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL
, 5);
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);
278 ////@end wxRichTextFontPage content construction
280 m_faceListBox
->UpdateFonts();
282 m_styleCtrl
->Append(_("Regular"));
283 m_styleCtrl
->Append(_("Italic"));
285 m_weightCtrl
->Append(_("Regular"));
286 m_weightCtrl
->Append(_("Bold"));
288 m_underliningCtrl
->Append(_("Not underlined"));
289 m_underliningCtrl
->Append(_("Underlined"));
293 for (i
= 8; i
< 40; i
++)
295 nStr
.Printf(wxT("%d"), i
);
296 m_sizeListBox
->Append(nStr
);
298 m_sizeListBox
->Append(wxT("48"));
299 m_sizeListBox
->Append(wxT("72"));
302 /// Transfer data from/to window
303 bool wxRichTextFontPage::TransferDataFromWindow()
305 wxPanel::TransferDataFromWindow();
307 wxRichTextAttr
* attr
= GetAttributes();
309 if (m_faceListBox
->GetSelection() != wxNOT_FOUND
)
311 wxString faceName
= m_faceListBox
->GetFaceName(m_faceListBox
->GetSelection());
312 if (!faceName
.IsEmpty())
314 attr
->SetFontFaceName(faceName
);
318 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_FACE
));
320 wxString strSize
= m_sizeTextCtrl
->GetValue();
321 if (!strSize
.IsEmpty())
323 int sz
= wxAtoi(strSize
);
326 attr
->SetFontSize(sz
);
330 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_SIZE
));
332 if (m_styleCtrl
->GetSelection() != wxNOT_FOUND
)
335 if (m_styleCtrl
->GetStringSelection() == _("Italic"))
336 style
= wxFONTSTYLE_ITALIC
;
338 style
= wxFONTSTYLE_NORMAL
;
340 attr
->SetFontStyle(style
);
343 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_ITALIC
));
345 if (m_weightCtrl
->GetSelection() != wxNOT_FOUND
)
348 if (m_weightCtrl
->GetStringSelection() == _("Bold"))
349 weight
= wxFONTWEIGHT_BOLD
;
351 weight
= wxFONTWEIGHT_NORMAL
;
353 attr
->SetFontWeight(weight
);
356 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_WEIGHT
));
358 if (m_underliningCtrl
->GetSelection() != wxNOT_FOUND
)
361 if (m_underliningCtrl
->GetStringSelection() == _("Underlined"))
366 attr
->SetFontUnderlined(underlined
);
369 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_UNDERLINE
));
373 attr
->SetTextColour(m_colourCtrl
->GetColour());
376 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_TEXT_COLOUR
));
378 if (m_bgColourPresent
)
380 attr
->SetBackgroundColour(m_bgColourCtrl
->GetColour());
383 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_BACKGROUND_COLOUR
));
385 if (m_strikethroughCtrl
->Get3StateValue() != wxCHK_UNDETERMINED
)
387 attr
->SetTextEffectFlags(attr
->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_STRIKETHROUGH
);
389 if (m_strikethroughCtrl
->Get3StateValue() == wxCHK_CHECKED
)
390 attr
->SetTextEffects(attr
->GetTextEffects() | wxTEXT_ATTR_EFFECT_STRIKETHROUGH
);
392 attr
->SetTextEffects(attr
->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_STRIKETHROUGH
);
395 if (m_capitalsCtrl
->Get3StateValue() != wxCHK_UNDETERMINED
)
397 attr
->SetTextEffectFlags(attr
->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_CAPITALS
);
399 if (m_capitalsCtrl
->Get3StateValue() == wxCHK_CHECKED
)
400 attr
->SetTextEffects(attr
->GetTextEffects() | wxTEXT_ATTR_EFFECT_CAPITALS
);
402 attr
->SetTextEffects(attr
->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_CAPITALS
);
405 if (m_superscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
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
);
411 else if (m_subscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
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
);
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
) );
427 bool wxRichTextFontPage::TransferDataToWindow()
429 wxPanel::TransferDataToWindow();
432 wxRichTextAttr
* attr
= GetAttributes();
434 if (attr
->HasFontFaceName())
436 m_faceTextCtrl
->SetValue(attr
->GetFontFaceName());
437 m_faceListBox
->SetFaceNameSelection(attr
->GetFont().GetFaceName());
441 m_faceTextCtrl
->SetValue(wxEmptyString
);
442 m_faceListBox
->SetFaceNameSelection(wxEmptyString
);
445 if (attr
->HasFontSize())
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
);
454 m_sizeTextCtrl
->SetValue(wxEmptyString
);
455 m_sizeListBox
->SetSelection(wxNOT_FOUND
);
458 if (attr
->HasFontWeight())
460 if (attr
->GetFontWeight() == wxBOLD
)
461 m_weightCtrl
->SetSelection(1);
463 m_weightCtrl
->SetSelection(0);
467 m_weightCtrl
->SetSelection(wxNOT_FOUND
);
470 if (attr
->HasFontItalic())
472 if (attr
->GetFontStyle() == wxITALIC
)
473 m_styleCtrl
->SetSelection(1);
475 m_styleCtrl
->SetSelection(0);
479 m_styleCtrl
->SetSelection(wxNOT_FOUND
);
482 if (attr
->HasFontUnderlined())
484 if (attr
->GetFontUnderlined())
485 m_underliningCtrl
->SetSelection(1);
487 m_underliningCtrl
->SetSelection(0);
491 m_underliningCtrl
->SetSelection(wxNOT_FOUND
);
494 if (attr
->HasTextColour())
496 m_colourCtrl
->SetColour(attr
->GetTextColour());
497 m_colourPresent
= true;
500 if (attr
->HasBackgroundColour())
502 m_bgColourCtrl
->SetColour(attr
->GetBackgroundColour());
503 m_bgColourPresent
= true;
506 if (attr
->HasTextEffects())
508 if (attr
->GetTextEffectFlags() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
510 if (attr
->GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
511 m_strikethroughCtrl
->Set3StateValue(wxCHK_CHECKED
);
513 m_strikethroughCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
516 m_strikethroughCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
518 if (attr
->GetTextEffectFlags() & wxTEXT_ATTR_EFFECT_CAPITALS
)
520 if (attr
->GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS
)
521 m_capitalsCtrl
->Set3StateValue(wxCHK_CHECKED
);
523 m_capitalsCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
526 m_capitalsCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
528 if ( attr
->GetTextEffectFlags() & (wxTEXT_ATTR_EFFECT_SUPERSCRIPT
| wxTEXT_ATTR_EFFECT_SUBSCRIPT
) )
530 if (attr
->GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
)
532 m_superscriptCtrl
->Set3StateValue(wxCHK_CHECKED
);
533 m_subscriptCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
535 else if (attr
->GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
)
537 m_superscriptCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
538 m_subscriptCtrl
->Set3StateValue(wxCHK_CHECKED
);
542 m_superscriptCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
543 m_subscriptCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
548 m_superscriptCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
549 m_subscriptCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
554 m_strikethroughCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
555 m_capitalsCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
556 m_superscriptCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
557 m_subscriptCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
562 m_dontUpdate
= false;
567 wxRichTextAttr
* wxRichTextFontPage::GetAttributes()
569 return wxRichTextFormattingDialog::GetDialogAttributes(this);
572 /// Updates the font preview
573 void wxRichTextFontPage::UpdatePreview()
578 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetBackgroundColour());
580 if (m_bgColourPresent
)
581 m_previewCtrl
->SetBackgroundColour(m_bgColourCtrl
->GetBackgroundColour());
583 if (m_faceListBox
->GetSelection() != wxNOT_FOUND
)
585 wxString faceName
= m_faceListBox
->GetFaceName(m_faceListBox
->GetSelection());
586 attr
.SetFontFaceName(faceName
);
589 wxString strSize
= m_sizeTextCtrl
->GetValue();
590 if (!strSize
.IsEmpty())
592 int sz
= wxAtoi(strSize
);
594 attr
.SetFontSize(sz
);
597 if (m_styleCtrl
->GetSelection() != wxNOT_FOUND
)
600 if (m_styleCtrl
->GetStringSelection() == _("Italic"))
601 style
= wxFONTSTYLE_ITALIC
;
603 style
= wxFONTSTYLE_NORMAL
;
605 attr
.SetFontStyle(style
);
608 if (m_weightCtrl
->GetSelection() != wxNOT_FOUND
)
611 if (m_weightCtrl
->GetStringSelection() == _("Bold"))
612 weight
= wxFONTWEIGHT_BOLD
;
614 weight
= wxFONTWEIGHT_NORMAL
;
616 attr
.SetFontWeight(weight
);
619 if (m_underliningCtrl
->GetSelection() != wxNOT_FOUND
)
622 if (m_underliningCtrl
->GetStringSelection() == _("Underlined"))
627 attr
.SetFontUnderlined(underlined
);
632 if (m_strikethroughCtrl
->Get3StateValue() == wxCHK_CHECKED
)
634 textEffects
|= wxTEXT_ATTR_EFFECT_STRIKETHROUGH
;
637 if (m_capitalsCtrl
->Get3StateValue() == wxCHK_CHECKED
)
639 textEffects
|= wxTEXT_ATTR_EFFECT_CAPITALS
;
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
;
647 wxFont font
= attr
.GetFont();
648 m_previewCtrl
->SetFont(font
);
649 m_previewCtrl
->SetTextEffects(textEffects
);
650 m_previewCtrl
->Refresh();
654 * Should we show tooltips?
657 bool wxRichTextFontPage::ShowToolTips()
659 return wxRichTextFormattingDialog::ShowToolTips();
663 * Get bitmap resources
666 wxBitmap
wxRichTextFontPage::GetBitmapResource( const wxString
& name
)
669 ////@begin wxRichTextFontPage bitmap retrieval
672 ////@end wxRichTextFontPage bitmap retrieval
679 wxIcon
wxRichTextFontPage::GetIconResource( const wxString
& name
)
682 ////@begin wxRichTextFontPage icon retrieval
685 ////@end wxRichTextFontPage icon retrieval
689 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_FACETEXTCTRL
692 void wxRichTextFontPage::OnFaceTextCtrlUpdated( wxCommandEvent
& WXUNUSED(event
) )
697 wxString facename
= m_faceTextCtrl
->GetValue();
698 if (!facename
.IsEmpty())
700 if (m_faceListBox
->HasFaceName(facename
))
702 m_faceListBox
->SetFaceNameSelection(facename
);
707 // Try to find a partial match
708 const wxArrayString
& arr
= m_faceListBox
->GetFaceNames();
710 for (i
= 0; i
< arr
.GetCount(); i
++)
712 if (arr
[i
].Mid(0, facename
.Length()).Lower() == facename
.Lower())
714 m_faceListBox
->ScrollToRow(i
);
724 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_SIZETEXTCTRL
727 void wxRichTextFontPage::OnSizeTextCtrlUpdated( wxCommandEvent
& WXUNUSED(event
) )
732 wxString strSize
= m_sizeTextCtrl
->GetValue();
733 if (!strSize
.IsEmpty() && m_sizeListBox
->FindString(strSize
) != wxNOT_FOUND
)
734 m_sizeListBox
->SetStringSelection(strSize
);
740 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_SIZELISTBOX
743 void wxRichTextFontPage::OnSizeListBoxSelected( wxCommandEvent
& event
)
747 m_sizeTextCtrl
->SetValue(event
.GetString());
749 m_dontUpdate
= false;
755 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_FACELISTBOX
758 void wxRichTextFontPage::OnFaceListBoxSelected( wxCommandEvent
& WXUNUSED(event
) )
762 m_faceTextCtrl
->SetValue(m_faceListBox
->GetFaceName(m_faceListBox
->GetSelection()));
764 m_dontUpdate
= false;
770 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_STYLECTRL
773 void wxRichTextFontPage::OnStyleCtrlSelected( wxCommandEvent
& WXUNUSED(event
) )
780 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL
783 void wxRichTextFontPage::OnUnderliningCtrlSelected( wxCommandEvent
& WXUNUSED(event
) )
790 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_WEIGHTCTRL
793 void wxRichTextFontPage::OnWeightCtrlSelected( wxCommandEvent
& WXUNUSED(event
) )
798 void wxRichTextFontPage::OnColourClicked( wxCommandEvent
& event
)
800 if (event
.GetId() == m_colourCtrl
->GetId())
801 m_colourPresent
= true;
802 else if (event
.GetId() == m_bgColourCtrl
->GetId())
803 m_bgColourPresent
= true;
808 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL
811 void wxRichTextFontPage::OnStrikethroughctrlClick( wxCommandEvent
& WXUNUSED(event
) )
817 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_CAPSCTRL
820 void wxRichTextFontPage::OnCapsctrlClick( wxCommandEvent
& WXUNUSED(event
) )
826 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUPERSCRIPT
829 void wxRichTextFontPage::OnRichtextfontpageSuperscriptClick( wxCommandEvent
& WXUNUSED(event
) )
831 if ( m_superscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
832 m_subscriptCtrl
->Set3StateValue( wxCHK_UNCHECKED
);
838 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUBSCRIPT
841 void wxRichTextFontPage::OnRichtextfontpageSubscriptClick( wxCommandEvent
& WXUNUSED(event
) )
843 if ( m_subscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
844 m_superscriptCtrl
->Set3StateValue( wxCHK_UNCHECKED
);