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
, wxRichTextDialogPage
)
21 * wxRichTextFontPage event table definition
24 BEGIN_EVENT_TABLE( wxRichTextFontPage
, wxRichTextDialogPage
)
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
54 IMPLEMENT_HELP_PROVISION(wxRichTextFontPage
)
56 * wxRichTextFontPage constructors
59 wxRichTextFontPage::wxRichTextFontPage( )
64 wxRichTextFontPage::wxRichTextFontPage( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
67 Create(parent
, id
, pos
, size
, style
);
74 void wxRichTextFontPage::Init()
77 m_colourPresent
= false;
78 m_bgColourPresent
= false;
80 ////@begin wxRichTextFontPage member initialisation
81 m_faceTextCtrl
= NULL
;
83 m_sizeTextCtrl
= NULL
;
87 m_underliningCtrl
= NULL
;
89 m_bgColourCtrl
= NULL
;
90 m_strikethroughCtrl
= NULL
;
91 m_capitalsCtrl
= NULL
;
92 m_superscriptCtrl
= NULL
;
93 m_subscriptCtrl
= NULL
;
95 ////@end wxRichTextFontPage member initialisation
99 * wxRichTextFontPage creator
102 bool wxRichTextFontPage::Create( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
104 ////@begin wxRichTextFontPage creation
105 wxRichTextDialogPage::Create( parent
, id
, pos
, size
, style
);
110 GetSizer()->SetSizeHints(this);
113 ////@end wxRichTextFontPage creation
118 * Control creation for wxRichTextFontPage
121 void wxRichTextFontPage::CreateControls()
123 ////@begin wxRichTextFontPage content construction
124 wxRichTextFontPage
* itemRichTextDialogPage1
= this;
126 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
127 itemRichTextDialogPage1
->SetSizer(itemBoxSizer2
);
129 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
130 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
132 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
133 itemBoxSizer3
->Add(itemBoxSizer4
, 1, wxGROW
, 5);
135 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
136 itemBoxSizer4
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
138 wxStaticText
* itemStaticText6
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
139 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
141 m_faceTextCtrl
= new wxTextCtrl( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_FACETEXTCTRL
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, 0 );
142 m_faceTextCtrl
->SetHelpText(_("Type a font name."));
143 if (wxRichTextFontPage::ShowToolTips())
144 m_faceTextCtrl
->SetToolTip(_("Type a font name."));
145 itemBoxSizer5
->Add(m_faceTextCtrl
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
147 m_faceListBox
= new wxRichTextFontListBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_FACELISTBOX
, wxDefaultPosition
, wxSize(200, 100), 0 );
148 m_faceListBox
->SetHelpText(_("Lists the available fonts."));
149 if (wxRichTextFontPage::ShowToolTips())
150 m_faceListBox
->SetToolTip(_("Lists the available fonts."));
151 itemBoxSizer5
->Add(m_faceListBox
, 1, wxGROW
|wxALL
|wxFIXED_MINSIZE
, 5);
153 wxBoxSizer
* itemBoxSizer9
= new wxBoxSizer(wxVERTICAL
);
154 itemBoxSizer4
->Add(itemBoxSizer9
, 0, wxGROW
, 5);
156 wxStaticText
* itemStaticText10
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
157 itemBoxSizer9
->Add(itemStaticText10
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
159 m_sizeTextCtrl
= new wxTextCtrl( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_SIZETEXTCTRL
, wxEmptyString
, wxDefaultPosition
, wxSize(50, -1), 0 );
160 m_sizeTextCtrl
->SetHelpText(_("Type a size in points."));
161 if (wxRichTextFontPage::ShowToolTips())
162 m_sizeTextCtrl
->SetToolTip(_("Type a size in points."));
163 itemBoxSizer9
->Add(m_sizeTextCtrl
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
165 wxArrayString m_sizeListBoxStrings
;
166 m_sizeListBox
= new wxListBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_SIZELISTBOX
, wxDefaultPosition
, wxSize(50, -1), m_sizeListBoxStrings
, wxLB_SINGLE
);
167 m_sizeListBox
->SetHelpText(_("Lists font sizes in points."));
168 if (wxRichTextFontPage::ShowToolTips())
169 m_sizeListBox
->SetToolTip(_("Lists font sizes in points."));
170 itemBoxSizer9
->Add(m_sizeListBox
, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
|wxFIXED_MINSIZE
, 5);
172 wxBoxSizer
* itemBoxSizer13
= new wxBoxSizer(wxHORIZONTAL
);
173 itemBoxSizer3
->Add(itemBoxSizer13
, 0, wxGROW
, 5);
175 wxBoxSizer
* itemBoxSizer14
= new wxBoxSizer(wxVERTICAL
);
176 itemBoxSizer13
->Add(itemBoxSizer14
, 0, wxGROW
, 5);
178 wxStaticText
* itemStaticText15
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("Font st&yle:"), wxDefaultPosition
, wxDefaultSize
, 0 );
179 itemBoxSizer14
->Add(itemStaticText15
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
181 wxArrayString m_styleCtrlStrings
;
182 m_styleCtrl
= new wxComboBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_STYLECTRL
, wxEmptyString
, wxDefaultPosition
, wxSize(110, -1), m_styleCtrlStrings
, wxCB_READONLY
);
183 m_styleCtrl
->SetHelpText(_("Select regular or italic style."));
184 if (wxRichTextFontPage::ShowToolTips())
185 m_styleCtrl
->SetToolTip(_("Select regular or italic style."));
186 itemBoxSizer14
->Add(m_styleCtrl
, 0, wxGROW
|wxALL
, 5);
188 wxBoxSizer
* itemBoxSizer17
= new wxBoxSizer(wxVERTICAL
);
189 itemBoxSizer13
->Add(itemBoxSizer17
, 0, wxGROW
, 5);
191 wxStaticText
* itemStaticText18
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("Font &weight:"), wxDefaultPosition
, wxDefaultSize
, 0 );
192 itemBoxSizer17
->Add(itemStaticText18
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
194 wxArrayString m_weightCtrlStrings
;
195 m_weightCtrl
= new wxComboBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_WEIGHTCTRL
, wxEmptyString
, wxDefaultPosition
, wxSize(110, -1), m_weightCtrlStrings
, wxCB_READONLY
);
196 m_weightCtrl
->SetHelpText(_("Select regular or bold."));
197 if (wxRichTextFontPage::ShowToolTips())
198 m_weightCtrl
->SetToolTip(_("Select regular or bold."));
199 itemBoxSizer17
->Add(m_weightCtrl
, 0, wxGROW
|wxALL
, 5);
201 wxBoxSizer
* itemBoxSizer20
= new wxBoxSizer(wxVERTICAL
);
202 itemBoxSizer13
->Add(itemBoxSizer20
, 0, wxGROW
, 5);
204 wxStaticText
* itemStaticText21
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Underlining:"), wxDefaultPosition
, wxDefaultSize
, 0 );
205 itemBoxSizer20
->Add(itemStaticText21
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
207 wxArrayString m_underliningCtrlStrings
;
208 m_underliningCtrl
= new wxComboBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL
, wxEmptyString
, wxDefaultPosition
, wxSize(110, -1), m_underliningCtrlStrings
, wxCB_READONLY
);
209 m_underliningCtrl
->SetHelpText(_("Select underlining or no underlining."));
210 if (wxRichTextFontPage::ShowToolTips())
211 m_underliningCtrl
->SetToolTip(_("Select underlining or no underlining."));
212 itemBoxSizer20
->Add(m_underliningCtrl
, 0, wxGROW
|wxALL
, 5);
214 itemBoxSizer13
->Add(0, 0, 1, wxALIGN_CENTER_VERTICAL
|wxBOTTOM
, 5);
216 wxBoxSizer
* itemBoxSizer24
= new wxBoxSizer(wxVERTICAL
);
217 itemBoxSizer13
->Add(itemBoxSizer24
, 0, wxGROW
, 5);
219 wxStaticText
* itemStaticText25
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
220 itemBoxSizer24
->Add(itemStaticText25
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
222 m_colourCtrl
= new wxRichTextColourSwatchCtrl( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_COLOURCTRL
, wxDefaultPosition
, wxSize(40, 20), 0 );
223 m_colourCtrl
->SetHelpText(_("Click to change the text colour."));
224 if (wxRichTextFontPage::ShowToolTips())
225 m_colourCtrl
->SetToolTip(_("Click to change the text colour."));
226 itemBoxSizer24
->Add(m_colourCtrl
, 0, wxGROW
|wxALL
, 5);
228 wxBoxSizer
* itemBoxSizer27
= new wxBoxSizer(wxVERTICAL
);
229 itemBoxSizer13
->Add(itemBoxSizer27
, 0, wxGROW
, 5);
231 wxStaticText
* itemStaticText28
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Bg colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
232 itemBoxSizer27
->Add(itemStaticText28
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
234 m_bgColourCtrl
= new wxRichTextColourSwatchCtrl( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_BGCOLOURCTRL
, wxDefaultPosition
, wxSize(40, 20), 0 );
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);
240 wxBoxSizer
* itemBoxSizer30
= new wxBoxSizer(wxHORIZONTAL
);
241 itemBoxSizer3
->Add(itemBoxSizer30
, 0, wxGROW
, 5);
243 m_strikethroughCtrl
= new wxCheckBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL
, _("&Strikethrough"), wxDefaultPosition
, wxDefaultSize
, wxCHK_3STATE
);
244 m_strikethroughCtrl
->SetValue(false);
245 m_strikethroughCtrl
->SetHelpText(_("Check to show a line through the text."));
246 if (wxRichTextFontPage::ShowToolTips())
247 m_strikethroughCtrl
->SetToolTip(_("Check to show a line through the text."));
248 itemBoxSizer30
->Add(m_strikethroughCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
250 m_capitalsCtrl
= new wxCheckBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_CAPSCTRL
, _("Ca&pitals"), wxDefaultPosition
, wxDefaultSize
, wxCHK_3STATE
);
251 m_capitalsCtrl
->SetValue(false);
252 m_capitalsCtrl
->SetHelpText(_("Check to show the text in capitals."));
253 if (wxRichTextFontPage::ShowToolTips())
254 m_capitalsCtrl
->SetToolTip(_("Check to show the text in capitals."));
255 itemBoxSizer30
->Add(m_capitalsCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
257 m_superscriptCtrl
= new wxCheckBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_SUPERSCRIPT
, _("Supe&rscript"), wxDefaultPosition
, wxDefaultSize
, wxCHK_3STATE
);
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."));
262 itemBoxSizer30
->Add(m_superscriptCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
264 m_subscriptCtrl
= new wxCheckBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_SUBSCRIPT
, _("Subscrip&t"), wxDefaultPosition
, wxDefaultSize
, wxCHK_3STATE
);
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."));
269 itemBoxSizer30
->Add(m_subscriptCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
271 itemBoxSizer3
->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL
, 5);
273 m_previewCtrl
= new wxRichTextFontPreviewCtrl( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_PREVIEWCTRL
, wxDefaultPosition
, wxSize(100, 60), 0 );
274 m_previewCtrl
->SetHelpText(_("Shows a preview of the font settings."));
275 if (wxRichTextFontPage::ShowToolTips())
276 m_previewCtrl
->SetToolTip(_("Shows a preview of the font settings."));
277 itemBoxSizer3
->Add(m_previewCtrl
, 0, wxGROW
|wxALL
, 5);
279 ////@end wxRichTextFontPage content construction
281 m_faceListBox
->UpdateFonts();
283 m_styleCtrl
->Append(_("Regular"));
284 m_styleCtrl
->Append(_("Italic"));
286 m_weightCtrl
->Append(_("Regular"));
287 m_weightCtrl
->Append(_("Bold"));
289 m_underliningCtrl
->Append(_("Not underlined"));
290 m_underliningCtrl
->Append(_("Underlined"));
294 for (i
= 8; i
< 40; i
++)
296 nStr
.Printf(wxT("%d"), i
);
297 m_sizeListBox
->Append(nStr
);
299 m_sizeListBox
->Append(wxT("48"));
300 m_sizeListBox
->Append(wxT("72"));
303 /// Transfer data from/to window
304 bool wxRichTextFontPage::TransferDataFromWindow()
306 wxPanel::TransferDataFromWindow();
308 wxRichTextAttr
* attr
= GetAttributes();
310 if (!m_faceTextCtrl
->GetValue().IsEmpty())
312 wxString faceName
= m_faceTextCtrl
->GetValue();
313 attr
->SetFontFaceName(faceName
);
316 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_FACE
));
318 wxString strSize
= m_sizeTextCtrl
->GetValue();
319 if (!strSize
.IsEmpty())
321 int sz
= wxAtoi(strSize
);
324 attr
->SetFontSize(sz
);
328 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_SIZE
));
330 if (m_styleCtrl
->GetSelection() != wxNOT_FOUND
)
333 if (m_styleCtrl
->GetStringSelection() == _("Italic"))
334 style
= wxFONTSTYLE_ITALIC
;
336 style
= wxFONTSTYLE_NORMAL
;
338 attr
->SetFontStyle(style
);
341 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_ITALIC
));
343 if (m_weightCtrl
->GetSelection() != wxNOT_FOUND
)
346 if (m_weightCtrl
->GetStringSelection() == _("Bold"))
347 weight
= wxFONTWEIGHT_BOLD
;
349 weight
= wxFONTWEIGHT_NORMAL
;
351 attr
->SetFontWeight(weight
);
354 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_WEIGHT
));
356 if (m_underliningCtrl
->GetSelection() != wxNOT_FOUND
)
359 if (m_underliningCtrl
->GetStringSelection() == _("Underlined"))
364 attr
->SetFontUnderlined(underlined
);
367 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_UNDERLINE
));
371 attr
->SetTextColour(m_colourCtrl
->GetColour());
374 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_TEXT_COLOUR
));
376 if (m_bgColourPresent
)
378 attr
->SetBackgroundColour(m_bgColourCtrl
->GetColour());
381 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_BACKGROUND_COLOUR
));
383 if (m_strikethroughCtrl
->Get3StateValue() != wxCHK_UNDETERMINED
)
385 attr
->SetTextEffectFlags(attr
->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_STRIKETHROUGH
);
387 if (m_strikethroughCtrl
->Get3StateValue() == wxCHK_CHECKED
)
388 attr
->SetTextEffects(attr
->GetTextEffects() | wxTEXT_ATTR_EFFECT_STRIKETHROUGH
);
390 attr
->SetTextEffects(attr
->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_STRIKETHROUGH
);
393 if (m_capitalsCtrl
->Get3StateValue() != wxCHK_UNDETERMINED
)
395 attr
->SetTextEffectFlags(attr
->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_CAPITALS
);
397 if (m_capitalsCtrl
->Get3StateValue() == wxCHK_CHECKED
)
398 attr
->SetTextEffects(attr
->GetTextEffects() | wxTEXT_ATTR_EFFECT_CAPITALS
);
400 attr
->SetTextEffects(attr
->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_CAPITALS
);
403 if (m_superscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
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
);
409 else if (m_subscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
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
);
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
) );
425 bool wxRichTextFontPage::TransferDataToWindow()
427 wxPanel::TransferDataToWindow();
430 wxRichTextAttr
* attr
= GetAttributes();
432 if (attr
->HasFontFaceName())
434 m_faceTextCtrl
->SetValue(attr
->GetFontFaceName());
435 m_faceListBox
->SetFaceNameSelection(attr
->GetFont().GetFaceName());
439 m_faceTextCtrl
->SetValue(wxEmptyString
);
440 m_faceListBox
->SetFaceNameSelection(wxEmptyString
);
443 if (attr
->HasFontSize())
445 wxString strSize
= wxString::Format(wxT("%d"), attr
->GetFontSize());
446 m_sizeTextCtrl
->SetValue(strSize
);
447 if (m_sizeListBox
->FindString(strSize
) != wxNOT_FOUND
)
448 m_sizeListBox
->SetStringSelection(strSize
);
452 m_sizeTextCtrl
->SetValue(wxEmptyString
);
453 m_sizeListBox
->SetSelection(wxNOT_FOUND
);
456 if (attr
->HasFontWeight())
458 if (attr
->GetFontWeight() == wxBOLD
)
459 m_weightCtrl
->SetSelection(1);
461 m_weightCtrl
->SetSelection(0);
465 m_weightCtrl
->SetSelection(wxNOT_FOUND
);
468 if (attr
->HasFontItalic())
470 if (attr
->GetFontStyle() == wxITALIC
)
471 m_styleCtrl
->SetSelection(1);
473 m_styleCtrl
->SetSelection(0);
477 m_styleCtrl
->SetSelection(wxNOT_FOUND
);
480 if (attr
->HasFontUnderlined())
482 if (attr
->GetFontUnderlined())
483 m_underliningCtrl
->SetSelection(1);
485 m_underliningCtrl
->SetSelection(0);
489 m_underliningCtrl
->SetSelection(wxNOT_FOUND
);
492 if (attr
->HasTextColour())
494 m_colourCtrl
->SetColour(attr
->GetTextColour());
495 m_colourPresent
= true;
498 if (attr
->HasBackgroundColour())
500 m_bgColourCtrl
->SetColour(attr
->GetBackgroundColour());
501 m_bgColourPresent
= true;
504 if (attr
->HasTextEffects())
506 if (attr
->GetTextEffectFlags() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
508 if (attr
->GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
509 m_strikethroughCtrl
->Set3StateValue(wxCHK_CHECKED
);
511 m_strikethroughCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
514 m_strikethroughCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
516 if (attr
->GetTextEffectFlags() & wxTEXT_ATTR_EFFECT_CAPITALS
)
518 if (attr
->GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS
)
519 m_capitalsCtrl
->Set3StateValue(wxCHK_CHECKED
);
521 m_capitalsCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
524 m_capitalsCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
526 if ( attr
->GetTextEffectFlags() & (wxTEXT_ATTR_EFFECT_SUPERSCRIPT
| wxTEXT_ATTR_EFFECT_SUBSCRIPT
) )
528 if (attr
->GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
)
530 m_superscriptCtrl
->Set3StateValue(wxCHK_CHECKED
);
531 m_subscriptCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
533 else if (attr
->GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
)
535 m_superscriptCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
536 m_subscriptCtrl
->Set3StateValue(wxCHK_CHECKED
);
540 m_superscriptCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
541 m_subscriptCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
546 m_superscriptCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
547 m_subscriptCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
552 m_strikethroughCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
553 m_capitalsCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
554 m_superscriptCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
555 m_subscriptCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
560 m_dontUpdate
= false;
565 wxRichTextAttr
* wxRichTextFontPage::GetAttributes()
567 return wxRichTextFormattingDialog::GetDialogAttributes(this);
570 /// Updates the font preview
571 void wxRichTextFontPage::UpdatePreview()
576 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetBackgroundColour());
578 if (m_bgColourPresent
)
579 m_previewCtrl
->SetBackgroundColour(m_bgColourCtrl
->GetBackgroundColour());
581 if (m_faceListBox
->GetSelection() != wxNOT_FOUND
)
583 wxString faceName
= m_faceListBox
->GetFaceName(m_faceListBox
->GetSelection());
584 attr
.SetFontFaceName(faceName
);
587 wxString strSize
= m_sizeTextCtrl
->GetValue();
588 if (!strSize
.IsEmpty())
590 int sz
= wxAtoi(strSize
);
592 attr
.SetFontSize(sz
);
595 if (m_styleCtrl
->GetSelection() != wxNOT_FOUND
)
598 if (m_styleCtrl
->GetStringSelection() == _("Italic"))
599 style
= wxFONTSTYLE_ITALIC
;
601 style
= wxFONTSTYLE_NORMAL
;
603 attr
.SetFontStyle(style
);
606 if (m_weightCtrl
->GetSelection() != wxNOT_FOUND
)
609 if (m_weightCtrl
->GetStringSelection() == _("Bold"))
610 weight
= wxFONTWEIGHT_BOLD
;
612 weight
= wxFONTWEIGHT_NORMAL
;
614 attr
.SetFontWeight(weight
);
617 if (m_underliningCtrl
->GetSelection() != wxNOT_FOUND
)
620 if (m_underliningCtrl
->GetStringSelection() == _("Underlined"))
625 attr
.SetFontUnderlined(underlined
);
630 if (m_strikethroughCtrl
->Get3StateValue() == wxCHK_CHECKED
)
632 textEffects
|= wxTEXT_ATTR_EFFECT_STRIKETHROUGH
;
635 if (m_capitalsCtrl
->Get3StateValue() == wxCHK_CHECKED
)
637 textEffects
|= wxTEXT_ATTR_EFFECT_CAPITALS
;
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
;
645 wxFont font
= attr
.GetFont();
646 m_previewCtrl
->SetFont(font
);
647 m_previewCtrl
->SetTextEffects(textEffects
);
648 m_previewCtrl
->Refresh();
652 * Should we show tooltips?
655 bool wxRichTextFontPage::ShowToolTips()
657 return wxRichTextFormattingDialog::ShowToolTips();
661 * Get bitmap resources
664 wxBitmap
wxRichTextFontPage::GetBitmapResource( const wxString
& name
)
667 ////@begin wxRichTextFontPage bitmap retrieval
670 ////@end wxRichTextFontPage bitmap retrieval
677 wxIcon
wxRichTextFontPage::GetIconResource( const wxString
& name
)
680 ////@begin wxRichTextFontPage icon retrieval
683 ////@end wxRichTextFontPage icon retrieval
687 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_FACETEXTCTRL
690 void wxRichTextFontPage::OnFaceTextCtrlUpdated( wxCommandEvent
& WXUNUSED(event
) )
695 wxString facename
= m_faceTextCtrl
->GetValue();
696 if (!facename
.IsEmpty())
698 if (m_faceListBox
->HasFaceName(facename
))
700 m_faceListBox
->SetFaceNameSelection(facename
);
705 // Try to find a partial match
706 const wxArrayString
& arr
= m_faceListBox
->GetFaceNames();
708 for (i
= 0; i
< arr
.GetCount(); i
++)
710 if (arr
[i
].Mid(0, facename
.Length()).Lower() == facename
.Lower())
712 m_faceListBox
->ScrollToRow(i
);
722 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_SIZETEXTCTRL
725 void wxRichTextFontPage::OnSizeTextCtrlUpdated( wxCommandEvent
& WXUNUSED(event
) )
730 wxString strSize
= m_sizeTextCtrl
->GetValue();
731 if (!strSize
.IsEmpty() && m_sizeListBox
->FindString(strSize
) != wxNOT_FOUND
)
732 m_sizeListBox
->SetStringSelection(strSize
);
738 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_SIZELISTBOX
741 void wxRichTextFontPage::OnSizeListBoxSelected( wxCommandEvent
& event
)
745 m_sizeTextCtrl
->SetValue(event
.GetString());
747 m_dontUpdate
= false;
753 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_FACELISTBOX
756 void wxRichTextFontPage::OnFaceListBoxSelected( wxCommandEvent
& WXUNUSED(event
) )
760 m_faceTextCtrl
->SetValue(m_faceListBox
->GetFaceName(m_faceListBox
->GetSelection()));
762 m_dontUpdate
= false;
768 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_STYLECTRL
771 void wxRichTextFontPage::OnStyleCtrlSelected( wxCommandEvent
& WXUNUSED(event
) )
778 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL
781 void wxRichTextFontPage::OnUnderliningCtrlSelected( wxCommandEvent
& WXUNUSED(event
) )
788 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_WEIGHTCTRL
791 void wxRichTextFontPage::OnWeightCtrlSelected( wxCommandEvent
& WXUNUSED(event
) )
796 void wxRichTextFontPage::OnColourClicked( wxCommandEvent
& event
)
798 if (event
.GetId() == m_colourCtrl
->GetId())
799 m_colourPresent
= true;
800 else if (event
.GetId() == m_bgColourCtrl
->GetId())
801 m_bgColourPresent
= true;
806 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL
809 void wxRichTextFontPage::OnStrikethroughctrlClick( wxCommandEvent
& WXUNUSED(event
) )
815 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_CAPSCTRL
818 void wxRichTextFontPage::OnCapsctrlClick( wxCommandEvent
& WXUNUSED(event
) )
824 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUPERSCRIPT
827 void wxRichTextFontPage::OnRichtextfontpageSuperscriptClick( wxCommandEvent
& WXUNUSED(event
) )
829 if ( m_superscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
830 m_subscriptCtrl
->Set3StateValue( wxCHK_UNCHECKED
);
836 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUBSCRIPT
839 void wxRichTextFontPage::OnRichtextfontpageSubscriptClick( wxCommandEvent
& WXUNUSED(event
) )
841 if ( m_subscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
842 m_superscriptCtrl
->Set3StateValue( wxCHK_UNCHECKED
);