1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextfontpage.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_IDLE( wxRichTextFontPage::OnIdle
)
32 EVT_TEXT( ID_RICHTEXTFONTPAGE_FACETEXTCTRL
, wxRichTextFontPage::OnFaceTextCtrlUpdated
)
34 EVT_TEXT( ID_RICHTEXTFONTPAGE_SIZETEXTCTRL
, wxRichTextFontPage::OnSizeTextCtrlUpdated
)
36 EVT_SPIN_UP( ID_RICHTEXTFONTPAGE_SPINBUTTONS
, wxRichTextFontPage::OnRichtextfontpageSpinbuttonsUp
)
37 EVT_SPIN_DOWN( ID_RICHTEXTFONTPAGE_SPINBUTTONS
, wxRichTextFontPage::OnRichtextfontpageSpinbuttonsDown
)
39 EVT_CHOICE( ID_RICHTEXTFONTPAGE_SIZE_UNITS
, wxRichTextFontPage::OnRichtextfontpageSizeUnitsSelected
)
41 EVT_LISTBOX( ID_RICHTEXTFONTPAGE_SIZELISTBOX
, wxRichTextFontPage::OnSizeListBoxSelected
)
43 EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_STYLECTRL
, wxRichTextFontPage::OnStyleCtrlSelected
)
45 EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_WEIGHTCTRL
, wxRichTextFontPage::OnWeightCtrlSelected
)
47 EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL
, wxRichTextFontPage::OnUnderliningCtrlSelected
)
49 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_COLOURCTRL_LABEL
, wxRichTextFontPage::OnUnderliningCtrlSelected
)
51 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_BGCOLOURCTRL_LABEL
, wxRichTextFontPage::OnUnderliningCtrlSelected
)
53 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL
, wxRichTextFontPage::OnStrikethroughctrlClick
)
55 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_CAPSCTRL
, wxRichTextFontPage::OnCapsctrlClick
)
57 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_SUPERSCRIPT
, wxRichTextFontPage::OnRichtextfontpageSuperscriptClick
)
59 EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_SUBSCRIPT
, wxRichTextFontPage::OnRichtextfontpageSubscriptClick
)
61 ////@end wxRichTextFontPage event table entries
65 IMPLEMENT_HELP_PROVISION(wxRichTextFontPage
)
67 * wxRichTextFontPage constructors
70 wxRichTextFontPage::wxRichTextFontPage( )
75 wxRichTextFontPage::wxRichTextFontPage( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
78 Create(parent
, id
, pos
, size
, style
);
85 void wxRichTextFontPage::Init()
88 m_colourPresent
= false;
89 m_bgColourPresent
= false;
91 ////@begin wxRichTextFontPage member initialisation
92 m_faceTextCtrl
= NULL
;
93 m_sizeTextCtrl
= NULL
;
94 m_fontSizeSpinButtons
= NULL
;
95 m_sizeUnitsCtrl
= NULL
;
96 m_fontListBoxParent
= NULL
;
101 m_underliningCtrl
= NULL
;
102 m_textColourLabel
= NULL
;
104 m_bgColourLabel
= NULL
;
105 m_bgColourCtrl
= NULL
;
106 m_strikethroughCtrl
= NULL
;
107 m_capitalsCtrl
= NULL
;
108 m_superscriptCtrl
= NULL
;
109 m_subscriptCtrl
= NULL
;
110 m_previewCtrl
= NULL
;
111 ////@end wxRichTextFontPage member initialisation
115 * wxRichTextFontPage creator
118 bool wxRichTextFontPage::Create( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
120 ////@begin wxRichTextFontPage creation
121 wxRichTextDialogPage::Create( parent
, id
, pos
, size
, style
);
126 GetSizer()->SetSizeHints(this);
129 ////@end wxRichTextFontPage creation
134 * Control creation for wxRichTextFontPage
137 void wxRichTextFontPage::CreateControls()
139 ////@begin wxRichTextFontPage content construction
140 wxRichTextFontPage
* itemRichTextDialogPage1
= this;
142 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
143 itemRichTextDialogPage1
->SetSizer(itemBoxSizer2
);
145 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
146 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
148 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
149 itemBoxSizer3
->Add(itemBoxSizer4
, 1, wxGROW
, 5);
151 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
152 itemBoxSizer4
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
154 wxStaticText
* itemStaticText6
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
155 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
157 m_faceTextCtrl
= new wxTextCtrl( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_FACETEXTCTRL
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, 0 );
158 m_faceTextCtrl
->SetHelpText(_("Type a font name."));
159 if (wxRichTextFontPage::ShowToolTips())
160 m_faceTextCtrl
->SetToolTip(_("Type a font name."));
161 itemBoxSizer5
->Add(m_faceTextCtrl
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
163 wxBoxSizer
* itemBoxSizer8
= new wxBoxSizer(wxVERTICAL
);
164 itemBoxSizer4
->Add(itemBoxSizer8
, 0, wxGROW
, 5);
166 wxStaticText
* itemStaticText9
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Size:"), wxDefaultPosition
, wxDefaultSize
, 0 );
167 itemBoxSizer8
->Add(itemStaticText9
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
169 wxBoxSizer
* itemBoxSizer10
= new wxBoxSizer(wxHORIZONTAL
);
170 itemBoxSizer8
->Add(itemBoxSizer10
, 0, wxGROW
, 5);
172 m_sizeTextCtrl
= new wxTextCtrl( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_SIZETEXTCTRL
, wxEmptyString
, wxDefaultPosition
, wxSize(50, -1), 0 );
173 m_sizeTextCtrl
->SetHelpText(_("Type a size in points."));
174 if (wxRichTextFontPage::ShowToolTips())
175 m_sizeTextCtrl
->SetToolTip(_("Type a size in points."));
176 itemBoxSizer10
->Add(m_sizeTextCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxTOP
, 5);
178 m_fontSizeSpinButtons
= new wxSpinButton( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_SPINBUTTONS
, wxDefaultPosition
, wxSize(-1, 20), wxSP_VERTICAL
);
179 m_fontSizeSpinButtons
->SetRange(0, 100);
180 m_fontSizeSpinButtons
->SetValue(0);
181 itemBoxSizer10
->Add(m_fontSizeSpinButtons
, 0, wxALIGN_CENTER_VERTICAL
|wxRIGHT
|wxTOP
, 5);
183 wxArrayString m_sizeUnitsCtrlStrings
;
184 m_sizeUnitsCtrlStrings
.Add(_("pt"));
185 m_sizeUnitsCtrlStrings
.Add(_("px"));
186 m_sizeUnitsCtrl
= new wxChoice( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_SIZE_UNITS
, wxDefaultPosition
, wxDefaultSize
, m_sizeUnitsCtrlStrings
, 0 );
187 m_sizeUnitsCtrl
->SetStringSelection(_("pt"));
188 m_sizeUnitsCtrl
->SetHelpText(_("The font size units, points or pixels."));
189 if (wxRichTextFontPage::ShowToolTips())
190 m_sizeUnitsCtrl
->SetToolTip(_("The font size units, points or pixels."));
191 itemBoxSizer10
->Add(m_sizeUnitsCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxRIGHT
|wxTOP
, 5);
193 m_fontListBoxParent
= new wxBoxSizer(wxHORIZONTAL
);
194 itemBoxSizer3
->Add(m_fontListBoxParent
, 0, wxGROW
, 5);
196 m_faceListBox
= new wxRichTextFontListBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_FACELISTBOX
, wxDefaultPosition
, wxSize(200, 100), 0 );
197 m_faceListBox
->SetHelpText(_("Lists the available fonts."));
198 if (wxRichTextFontPage::ShowToolTips())
199 m_faceListBox
->SetToolTip(_("Lists the available fonts."));
200 m_fontListBoxParent
->Add(m_faceListBox
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
|wxFIXED_MINSIZE
, 5);
202 wxArrayString m_sizeListBoxStrings
;
203 m_sizeListBox
= new wxListBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_SIZELISTBOX
, wxDefaultPosition
, wxSize(50, -1), m_sizeListBoxStrings
, wxLB_SINGLE
);
204 m_sizeListBox
->SetHelpText(_("Lists font sizes in points."));
205 if (wxRichTextFontPage::ShowToolTips())
206 m_sizeListBox
->SetToolTip(_("Lists font sizes in points."));
207 m_fontListBoxParent
->Add(m_sizeListBox
, 0, wxGROW
|wxALL
|wxFIXED_MINSIZE
, 5);
209 wxBoxSizer
* itemBoxSizer17
= new wxBoxSizer(wxHORIZONTAL
);
210 itemBoxSizer3
->Add(itemBoxSizer17
, 0, wxGROW
, 5);
212 wxBoxSizer
* itemBoxSizer18
= new wxBoxSizer(wxVERTICAL
);
213 itemBoxSizer17
->Add(itemBoxSizer18
, 0, wxGROW
, 5);
215 wxStaticText
* itemStaticText19
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("Font st&yle:"), wxDefaultPosition
, wxDefaultSize
, 0 );
216 itemBoxSizer18
->Add(itemStaticText19
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
218 wxArrayString m_styleCtrlStrings
;
219 m_styleCtrl
= new wxComboBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_STYLECTRL
, wxEmptyString
, wxDefaultPosition
, wxSize(110, -1), m_styleCtrlStrings
, wxCB_READONLY
);
220 m_styleCtrl
->SetHelpText(_("Select regular or italic style."));
221 if (wxRichTextFontPage::ShowToolTips())
222 m_styleCtrl
->SetToolTip(_("Select regular or italic style."));
223 itemBoxSizer18
->Add(m_styleCtrl
, 0, wxGROW
|wxALL
, 5);
225 wxBoxSizer
* itemBoxSizer21
= new wxBoxSizer(wxVERTICAL
);
226 itemBoxSizer17
->Add(itemBoxSizer21
, 0, wxGROW
, 5);
228 wxStaticText
* itemStaticText22
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("Font &weight:"), wxDefaultPosition
, wxDefaultSize
, 0 );
229 itemBoxSizer21
->Add(itemStaticText22
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
231 wxArrayString m_weightCtrlStrings
;
232 m_weightCtrl
= new wxComboBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_WEIGHTCTRL
, wxEmptyString
, wxDefaultPosition
, wxSize(110, -1), m_weightCtrlStrings
, wxCB_READONLY
);
233 m_weightCtrl
->SetHelpText(_("Select regular or bold."));
234 if (wxRichTextFontPage::ShowToolTips())
235 m_weightCtrl
->SetToolTip(_("Select regular or bold."));
236 itemBoxSizer21
->Add(m_weightCtrl
, 0, wxGROW
|wxALL
, 5);
238 wxBoxSizer
* itemBoxSizer24
= new wxBoxSizer(wxVERTICAL
);
239 itemBoxSizer17
->Add(itemBoxSizer24
, 0, wxGROW
, 5);
241 wxStaticText
* itemStaticText25
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Underlining:"), wxDefaultPosition
, wxDefaultSize
, 0 );
242 itemBoxSizer24
->Add(itemStaticText25
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
244 wxArrayString m_underliningCtrlStrings
;
245 m_underliningCtrl
= new wxComboBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL
, wxEmptyString
, wxDefaultPosition
, wxSize(110, -1), m_underliningCtrlStrings
, wxCB_READONLY
);
246 m_underliningCtrl
->SetHelpText(_("Select underlining or no underlining."));
247 if (wxRichTextFontPage::ShowToolTips())
248 m_underliningCtrl
->SetToolTip(_("Select underlining or no underlining."));
249 itemBoxSizer24
->Add(m_underliningCtrl
, 0, wxGROW
|wxALL
, 5);
251 itemBoxSizer17
->Add(0, 0, 1, wxALIGN_CENTER_VERTICAL
|wxBOTTOM
, 5);
253 wxBoxSizer
* itemBoxSizer28
= new wxBoxSizer(wxVERTICAL
);
254 itemBoxSizer17
->Add(itemBoxSizer28
, 0, wxGROW
, 5);
256 m_textColourLabel
= new wxCheckBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_COLOURCTRL_LABEL
, _("&Colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
257 m_textColourLabel
->SetValue(false);
258 itemBoxSizer28
->Add(m_textColourLabel
, 0, wxALIGN_CENTER_HORIZONTAL
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
260 m_colourCtrl
= new wxRichTextColourSwatchCtrl( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_COLOURCTRL
, wxDefaultPosition
, wxSize(40, 20), 0 );
261 m_colourCtrl
->SetHelpText(_("Click to change the text colour."));
262 if (wxRichTextFontPage::ShowToolTips())
263 m_colourCtrl
->SetToolTip(_("Click to change the text colour."));
264 itemBoxSizer28
->Add(m_colourCtrl
, 0, wxGROW
|wxALL
, 5);
266 wxBoxSizer
* itemBoxSizer31
= new wxBoxSizer(wxVERTICAL
);
267 itemBoxSizer17
->Add(itemBoxSizer31
, 0, wxGROW
, 5);
269 m_bgColourLabel
= new wxCheckBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_BGCOLOURCTRL_LABEL
, _("&Bg colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
270 m_bgColourLabel
->SetValue(false);
271 itemBoxSizer31
->Add(m_bgColourLabel
, 0, wxALIGN_CENTER_HORIZONTAL
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
273 m_bgColourCtrl
= new wxRichTextColourSwatchCtrl( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_BGCOLOURCTRL
, wxDefaultPosition
, wxSize(40, 20), 0 );
274 m_bgColourCtrl
->SetHelpText(_("Click to change the text background colour."));
275 if (wxRichTextFontPage::ShowToolTips())
276 m_bgColourCtrl
->SetToolTip(_("Click to change the text background colour."));
277 itemBoxSizer31
->Add(m_bgColourCtrl
, 0, wxGROW
|wxALL
, 5);
279 wxBoxSizer
* itemBoxSizer34
= new wxBoxSizer(wxHORIZONTAL
);
280 itemBoxSizer3
->Add(itemBoxSizer34
, 0, wxGROW
, 5);
282 m_strikethroughCtrl
= new wxCheckBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL
, _("&Strikethrough"), wxDefaultPosition
, wxDefaultSize
, wxCHK_3STATE
|wxCHK_ALLOW_3RD_STATE_FOR_USER
);
283 m_strikethroughCtrl
->SetValue(false);
284 m_strikethroughCtrl
->SetHelpText(_("Check to show a line through the text."));
285 if (wxRichTextFontPage::ShowToolTips())
286 m_strikethroughCtrl
->SetToolTip(_("Check to show a line through the text."));
287 itemBoxSizer34
->Add(m_strikethroughCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
289 m_capitalsCtrl
= new wxCheckBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_CAPSCTRL
, _("Ca&pitals"), wxDefaultPosition
, wxDefaultSize
, wxCHK_3STATE
|wxCHK_ALLOW_3RD_STATE_FOR_USER
);
290 m_capitalsCtrl
->SetValue(false);
291 m_capitalsCtrl
->SetHelpText(_("Check to show the text in capitals."));
292 if (wxRichTextFontPage::ShowToolTips())
293 m_capitalsCtrl
->SetToolTip(_("Check to show the text in capitals."));
294 itemBoxSizer34
->Add(m_capitalsCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
296 m_superscriptCtrl
= new wxCheckBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_SUPERSCRIPT
, _("Supe&rscript"), wxDefaultPosition
, wxDefaultSize
, wxCHK_3STATE
|wxCHK_ALLOW_3RD_STATE_FOR_USER
);
297 m_superscriptCtrl
->SetValue(false);
298 m_superscriptCtrl
->SetHelpText(_("Check to show the text in superscript."));
299 if (wxRichTextFontPage::ShowToolTips())
300 m_superscriptCtrl
->SetToolTip(_("Check to show the text in superscript."));
301 itemBoxSizer34
->Add(m_superscriptCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
303 m_subscriptCtrl
= new wxCheckBox( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_SUBSCRIPT
, _("Subscrip&t"), wxDefaultPosition
, wxDefaultSize
, wxCHK_3STATE
|wxCHK_ALLOW_3RD_STATE_FOR_USER
);
304 m_subscriptCtrl
->SetValue(false);
305 m_subscriptCtrl
->SetHelpText(_("Check to show the text in subscript."));
306 if (wxRichTextFontPage::ShowToolTips())
307 m_subscriptCtrl
->SetToolTip(_("Check to show the text in subscript."));
308 itemBoxSizer34
->Add(m_subscriptCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
310 itemBoxSizer3
->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL
, 5);
312 m_previewCtrl
= new wxRichTextFontPreviewCtrl( itemRichTextDialogPage1
, ID_RICHTEXTFONTPAGE_PREVIEWCTRL
, wxDefaultPosition
, wxSize(100, 60), 0 );
313 m_previewCtrl
->SetHelpText(_("Shows a preview of the font settings."));
314 if (wxRichTextFontPage::ShowToolTips())
315 m_previewCtrl
->SetToolTip(_("Shows a preview of the font settings."));
316 itemBoxSizer3
->Add(m_previewCtrl
, 0, wxGROW
|wxALL
, 5);
318 ////@end wxRichTextFontPage content construction
320 m_faceListBox
->UpdateFonts();
322 m_styleCtrl
->Append(_("(none)"));
323 m_styleCtrl
->Append(_("Regular"));
324 m_styleCtrl
->Append(_("Italic"));
326 m_weightCtrl
->Append(_("(none)"));
327 m_weightCtrl
->Append(_("Regular"));
328 m_weightCtrl
->Append(_("Bold"));
330 m_underliningCtrl
->Append(_("(none)"));
331 m_underliningCtrl
->Append(_("Not underlined"));
332 m_underliningCtrl
->Append(_("Underlined"));
336 for (i
= 8; i
< 40; i
++)
338 nStr
.Printf(wxT("%d"), i
);
339 m_sizeListBox
->Append(nStr
);
341 m_sizeListBox
->Append(wxT("48"));
342 m_sizeListBox
->Append(wxT("72"));
345 /// Transfer data from/to window
346 bool wxRichTextFontPage::TransferDataFromWindow()
348 wxPanel::TransferDataFromWindow();
350 wxRichTextAttr
* attr
= GetAttributes();
352 if (!m_faceTextCtrl
->GetValue().IsEmpty())
354 wxString faceName
= m_faceTextCtrl
->GetValue();
355 attr
->SetFontFaceName(faceName
);
358 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_FACE
));
360 wxString strSize
= m_sizeTextCtrl
->GetValue();
361 if (!strSize
.IsEmpty())
363 int sz
= wxAtoi(strSize
);
366 if (m_sizeUnitsCtrl
->GetSelection() == 0)
367 attr
->SetFontPointSize(sz
);
369 attr
->SetFontPixelSize(sz
);
373 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_SIZE
));
375 if (m_styleCtrl
->GetSelection() != wxNOT_FOUND
&& m_styleCtrl
->GetSelection() != 0)
378 if (m_styleCtrl
->GetSelection() == 2)
379 style
= wxFONTSTYLE_ITALIC
;
381 style
= wxFONTSTYLE_NORMAL
;
383 attr
->SetFontStyle(style
);
386 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_ITALIC
));
388 if (m_weightCtrl
->GetSelection() != wxNOT_FOUND
&& m_weightCtrl
->GetSelection() != 0)
391 if (m_weightCtrl
->GetSelection() == 2)
392 weight
= wxFONTWEIGHT_BOLD
;
394 weight
= wxFONTWEIGHT_NORMAL
;
396 attr
->SetFontWeight(weight
);
399 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_WEIGHT
));
401 if (m_underliningCtrl
->GetSelection() != wxNOT_FOUND
&& m_underliningCtrl
->GetSelection() != 0)
404 if (m_underliningCtrl
->GetSelection() == 2)
409 attr
->SetFontUnderlined(underlined
);
412 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_FONT_UNDERLINE
));
414 if (m_textColourLabel
->GetValue())
416 attr
->SetTextColour(m_colourCtrl
->GetColour());
419 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_TEXT_COLOUR
));
421 if (m_bgColourLabel
->GetValue())
423 attr
->SetBackgroundColour(m_bgColourCtrl
->GetColour());
426 attr
->SetFlags(attr
->GetFlags() & (~ wxTEXT_ATTR_BACKGROUND_COLOUR
));
428 if (m_strikethroughCtrl
->Get3StateValue() != wxCHK_UNDETERMINED
)
430 attr
->SetTextEffectFlags(attr
->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_STRIKETHROUGH
);
432 if (m_strikethroughCtrl
->Get3StateValue() == wxCHK_CHECKED
)
433 attr
->SetTextEffects(attr
->GetTextEffects() | wxTEXT_ATTR_EFFECT_STRIKETHROUGH
);
435 attr
->SetTextEffects(attr
->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_STRIKETHROUGH
);
439 attr
->SetTextEffectFlags(attr
->GetTextEffectFlags() & ~wxTEXT_ATTR_EFFECT_STRIKETHROUGH
);
440 attr
->SetTextEffects(attr
->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_STRIKETHROUGH
);
443 if (m_capitalsCtrl
->Get3StateValue() != wxCHK_UNDETERMINED
)
445 attr
->SetTextEffectFlags(attr
->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_CAPITALS
);
447 if (m_capitalsCtrl
->Get3StateValue() == wxCHK_CHECKED
)
448 attr
->SetTextEffects(attr
->GetTextEffects() | wxTEXT_ATTR_EFFECT_CAPITALS
);
450 attr
->SetTextEffects(attr
->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_CAPITALS
);
454 attr
->SetTextEffectFlags(attr
->GetTextEffectFlags() & ~wxTEXT_ATTR_EFFECT_CAPITALS
);
455 attr
->SetTextEffects(attr
->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_CAPITALS
);
458 if (m_superscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
460 attr
->SetTextEffectFlags(attr
->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_SUPERSCRIPT
);
461 attr
->SetTextEffects(attr
->GetTextEffects() | wxTEXT_ATTR_EFFECT_SUPERSCRIPT
);
462 attr
->SetTextEffects(attr
->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_SUBSCRIPT
);
464 else if (m_subscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
466 attr
->SetTextEffectFlags(attr
->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_SUBSCRIPT
);
467 attr
->SetTextEffects(attr
->GetTextEffects() | wxTEXT_ATTR_EFFECT_SUBSCRIPT
);
468 attr
->SetTextEffects(attr
->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_SUPERSCRIPT
);
472 // If they are undetermined, we don't want to include these flags in the text effects - the objects
473 // should retain their original style.
474 attr
->SetTextEffectFlags(attr
->GetTextEffectFlags() & ~(wxTEXT_ATTR_EFFECT_SUBSCRIPT
|wxTEXT_ATTR_EFFECT_SUPERSCRIPT
) );
475 attr
->SetTextEffects(attr
->GetTextEffects() & ~(wxTEXT_ATTR_EFFECT_SUBSCRIPT
|wxTEXT_ATTR_EFFECT_SUPERSCRIPT
) );
481 bool wxRichTextFontPage::TransferDataToWindow()
483 wxPanel::TransferDataToWindow();
486 wxRichTextAttr
* attr
= GetAttributes();
488 if (attr
->HasFontFaceName())
490 m_faceTextCtrl
->SetValue(attr
->GetFontFaceName());
491 m_faceListBox
->SetFaceNameSelection(attr
->GetFont().GetFaceName());
495 m_faceTextCtrl
->SetValue(wxEmptyString
);
496 m_faceListBox
->SetFaceNameSelection(wxEmptyString
);
499 if (attr
->HasFontPointSize())
501 wxString strSize
= wxString::Format(wxT("%d"), attr
->GetFontSize());
502 m_sizeTextCtrl
->SetValue(strSize
);
503 m_sizeUnitsCtrl
->SetSelection(0);
504 if (m_sizeListBox
->FindString(strSize
) != wxNOT_FOUND
)
505 m_sizeListBox
->SetStringSelection(strSize
);
507 else if (attr
->HasFontPixelSize())
509 wxString strSize
= wxString::Format(wxT("%d"), attr
->GetFontSize());
510 m_sizeTextCtrl
->SetValue(strSize
);
511 m_sizeUnitsCtrl
->SetSelection(1);
512 m_sizeListBox
->SetSelection(wxNOT_FOUND
);
516 m_sizeTextCtrl
->SetValue(wxEmptyString
);
517 m_sizeListBox
->SetSelection(wxNOT_FOUND
);
520 if (attr
->HasFontWeight())
522 if (attr
->GetFontWeight() == wxBOLD
)
523 m_weightCtrl
->SetSelection(2);
525 m_weightCtrl
->SetSelection(1);
529 m_weightCtrl
->SetSelection(0);
532 if (attr
->HasFontItalic())
534 if (attr
->GetFontStyle() == wxITALIC
)
535 m_styleCtrl
->SetSelection(2);
537 m_styleCtrl
->SetSelection(1);
541 m_styleCtrl
->SetSelection(0);
544 if (attr
->HasFontUnderlined())
546 if (attr
->GetFontUnderlined())
547 m_underliningCtrl
->SetSelection(2);
549 m_underliningCtrl
->SetSelection(1);
553 m_underliningCtrl
->SetSelection(0);
556 if (attr
->HasTextColour())
558 m_colourCtrl
->SetColour(attr
->GetTextColour());
559 m_textColourLabel
->SetValue(true);
560 m_colourPresent
= true;
564 m_colourCtrl
->SetColour(*wxBLACK
);
565 m_textColourLabel
->SetValue(false);
568 if (attr
->HasBackgroundColour())
570 m_bgColourCtrl
->SetColour(attr
->GetBackgroundColour());
571 m_bgColourLabel
->SetValue(true);
572 m_bgColourPresent
= true;
576 m_bgColourCtrl
->SetColour(*wxWHITE
);
577 m_bgColourLabel
->SetValue(false);
580 if (attr
->HasTextEffects())
582 if (attr
->GetTextEffectFlags() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
584 if (attr
->GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
585 m_strikethroughCtrl
->Set3StateValue(wxCHK_CHECKED
);
587 m_strikethroughCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
590 m_strikethroughCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
592 if (attr
->GetTextEffectFlags() & wxTEXT_ATTR_EFFECT_CAPITALS
)
594 if (attr
->GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS
)
595 m_capitalsCtrl
->Set3StateValue(wxCHK_CHECKED
);
597 m_capitalsCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
600 m_capitalsCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
602 if ( attr
->GetTextEffectFlags() & (wxTEXT_ATTR_EFFECT_SUPERSCRIPT
| wxTEXT_ATTR_EFFECT_SUBSCRIPT
) )
604 if (attr
->GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
)
606 m_superscriptCtrl
->Set3StateValue(wxCHK_CHECKED
);
607 m_subscriptCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
609 else if (attr
->GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
)
611 m_superscriptCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
612 m_subscriptCtrl
->Set3StateValue(wxCHK_CHECKED
);
616 m_superscriptCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
617 m_subscriptCtrl
->Set3StateValue(wxCHK_UNCHECKED
);
622 m_superscriptCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
623 m_subscriptCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
628 m_strikethroughCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
629 m_capitalsCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
630 m_superscriptCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
631 m_subscriptCtrl
->Set3StateValue(wxCHK_UNDETERMINED
);
636 m_dontUpdate
= false;
641 wxRichTextAttr
* wxRichTextFontPage::GetAttributes()
643 return wxRichTextFormattingDialog::GetDialogAttributes(this);
646 /// Updates the font preview
647 void wxRichTextFontPage::UpdatePreview()
651 if (m_textColourLabel
->GetValue())
652 m_previewCtrl
->SetForegroundColour(m_colourCtrl
->GetColour());
655 m_previewCtrl
->SetForegroundColour(*wxBLACK
);
656 if (!(m_colourCtrl
->GetColour() == *wxBLACK
))
658 m_colourCtrl
->SetColour(*wxBLACK
);
659 m_colourCtrl
->Refresh();
663 if (m_bgColourLabel
->GetValue())
664 m_previewCtrl
->SetBackgroundColour(m_bgColourCtrl
->GetColour());
667 m_previewCtrl
->SetBackgroundColour(*wxWHITE
);
669 if (!(m_bgColourCtrl
->GetColour() == *wxWHITE
))
671 m_bgColourCtrl
->SetColour(*wxWHITE
);
672 m_bgColourCtrl
->Refresh();
676 if (m_faceListBox
->GetSelection() != wxNOT_FOUND
)
678 wxString faceName
= m_faceListBox
->GetFaceName(m_faceListBox
->GetSelection());
679 attr
.SetFontFaceName(faceName
);
682 wxString strSize
= m_sizeTextCtrl
->GetValue();
683 if (!strSize
.IsEmpty())
685 int sz
= wxAtoi(strSize
);
688 if (m_sizeUnitsCtrl
->GetSelection() == 1)
689 attr
.SetFontPixelSize(sz
);
691 attr
.SetFontPointSize(sz
);
695 if (m_styleCtrl
->GetSelection() != wxNOT_FOUND
&& m_styleCtrl
->GetSelection() != 0)
698 if (m_styleCtrl
->GetSelection() == 2)
699 style
= wxFONTSTYLE_ITALIC
;
701 style
= wxFONTSTYLE_NORMAL
;
703 attr
.SetFontStyle(style
);
706 if (m_weightCtrl
->GetSelection() != wxNOT_FOUND
&& m_weightCtrl
->GetSelection() != 0)
709 if (m_weightCtrl
->GetSelection() == 2)
710 weight
= wxFONTWEIGHT_BOLD
;
712 weight
= wxFONTWEIGHT_NORMAL
;
714 attr
.SetFontWeight(weight
);
717 if (m_underliningCtrl
->GetSelection() != wxNOT_FOUND
&& m_underliningCtrl
->GetSelection() != 0)
720 if (m_underliningCtrl
->GetSelection() == 2)
725 attr
.SetFontUnderlined(underlined
);
730 if (m_strikethroughCtrl
->Get3StateValue() == wxCHK_CHECKED
)
732 textEffects
|= wxTEXT_ATTR_EFFECT_STRIKETHROUGH
;
735 if (m_capitalsCtrl
->Get3StateValue() == wxCHK_CHECKED
)
737 textEffects
|= wxTEXT_ATTR_EFFECT_CAPITALS
;
740 if ( m_superscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
741 textEffects
|= wxTEXT_ATTR_EFFECT_SUPERSCRIPT
;
742 else if ( m_subscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
743 textEffects
|= wxTEXT_ATTR_EFFECT_SUBSCRIPT
;
745 wxFont font
= attr
.GetFont();
746 m_previewCtrl
->SetFont(font
);
747 m_previewCtrl
->SetTextEffects(textEffects
);
748 m_previewCtrl
->Refresh();
752 * Should we show tooltips?
755 bool wxRichTextFontPage::ShowToolTips()
757 return wxRichTextFormattingDialog::ShowToolTips();
761 * Get bitmap resources
764 wxBitmap
wxRichTextFontPage::GetBitmapResource( const wxString
& name
)
767 ////@begin wxRichTextFontPage bitmap retrieval
770 ////@end wxRichTextFontPage bitmap retrieval
777 wxIcon
wxRichTextFontPage::GetIconResource( const wxString
& name
)
780 ////@begin wxRichTextFontPage icon retrieval
783 ////@end wxRichTextFontPage icon retrieval
787 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_FACETEXTCTRL
790 void wxRichTextFontPage::OnFaceTextCtrlUpdated( wxCommandEvent
& WXUNUSED(event
) )
795 wxString facename
= m_faceTextCtrl
->GetValue();
796 if (!facename
.IsEmpty())
798 if (m_faceListBox
->HasFaceName(facename
))
800 m_faceListBox
->SetFaceNameSelection(facename
);
805 // Try to find a partial match
806 const wxArrayString
& arr
= m_faceListBox
->GetFaceNames();
808 for (i
= 0; i
< arr
.GetCount(); i
++)
810 if (arr
[i
].Mid(0, facename
.Length()).Lower() == facename
.Lower())
812 m_faceListBox
->ScrollToRow(i
);
822 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_SIZETEXTCTRL
825 void wxRichTextFontPage::OnSizeTextCtrlUpdated( wxCommandEvent
& WXUNUSED(event
) )
830 wxString strSize
= m_sizeTextCtrl
->GetValue();
831 if (!strSize
.IsEmpty() && m_sizeListBox
->FindString(strSize
) != wxNOT_FOUND
)
832 m_sizeListBox
->SetStringSelection(strSize
);
838 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_SIZELISTBOX
841 void wxRichTextFontPage::OnSizeListBoxSelected( wxCommandEvent
& event
)
843 bool oldDontUpdate
= m_dontUpdate
;
846 m_sizeTextCtrl
->SetValue(event
.GetString());
848 m_dontUpdate
= oldDontUpdate
;
857 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_FACELISTBOX
860 void wxRichTextFontPage::OnFaceListBoxSelected( wxCommandEvent
& WXUNUSED(event
) )
862 bool oldDontUpdate
= m_dontUpdate
;
865 m_faceTextCtrl
->SetValue(m_faceListBox
->GetFaceName(m_faceListBox
->GetSelection()));
867 m_dontUpdate
= oldDontUpdate
;
876 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_STYLECTRL
879 void wxRichTextFontPage::OnStyleCtrlSelected( wxCommandEvent
& WXUNUSED(event
) )
889 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL
892 void wxRichTextFontPage::OnUnderliningCtrlSelected( wxCommandEvent
& WXUNUSED(event
) )
902 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_WEIGHTCTRL
905 void wxRichTextFontPage::OnWeightCtrlSelected( wxCommandEvent
& WXUNUSED(event
) )
913 void wxRichTextFontPage::OnColourClicked( wxCommandEvent
& event
)
915 if (event
.GetId() == m_colourCtrl
->GetId())
916 m_colourPresent
= true;
917 else if (event
.GetId() == m_bgColourCtrl
->GetId())
918 m_bgColourPresent
= true;
922 if (event
.GetId() == m_colourCtrl
->GetId())
924 m_textColourLabel
->SetValue(true);
926 else if (event
.GetId() == m_bgColourCtrl
->GetId())
928 m_bgColourLabel
->SetValue(true);
931 m_dontUpdate
= false;
936 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL
939 void wxRichTextFontPage::OnStrikethroughctrlClick( wxCommandEvent
& WXUNUSED(event
) )
948 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_CAPSCTRL
951 void wxRichTextFontPage::OnCapsctrlClick( wxCommandEvent
& WXUNUSED(event
) )
960 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUPERSCRIPT
963 void wxRichTextFontPage::OnRichtextfontpageSuperscriptClick( wxCommandEvent
& WXUNUSED(event
) )
968 if ( m_superscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
969 m_subscriptCtrl
->Set3StateValue( wxCHK_UNCHECKED
);
975 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUBSCRIPT
978 void wxRichTextFontPage::OnRichtextfontpageSubscriptClick( wxCommandEvent
& WXUNUSED(event
) )
983 if ( m_subscriptCtrl
->Get3StateValue() == wxCHK_CHECKED
)
984 m_superscriptCtrl
->Set3StateValue( wxCHK_UNCHECKED
);
990 * wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_RICHTEXTFONTPAGE_SIZE_UNITS
993 void wxRichTextFontPage::OnRichtextfontpageSizeUnitsSelected( wxCommandEvent
& WXUNUSED(event
) )
1002 * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for ID_RICHTEXTFONTPAGE_SPINBUTTONS
1005 void wxRichTextFontPage::OnRichtextfontpageSpinbuttonsUp( wxSpinEvent
& WXUNUSED(event
) )
1007 wxString text
= m_sizeTextCtrl
->GetValue();
1008 if (!text
.IsEmpty())
1010 int size
= wxAtoi(text
);
1014 m_sizeTextCtrl
->SetValue(wxString::Format(wxT("%d"), size
));
1021 * wxEVT_SCROLL_LINEDOWN event handler for ID_RICHTEXTFONTPAGE_SPINBUTTONS
1024 void wxRichTextFontPage::OnRichtextfontpageSpinbuttonsDown( wxSpinEvent
& WXUNUSED(event
) )
1026 wxString text
= m_sizeTextCtrl
->GetValue();
1027 if (!text
.IsEmpty())
1029 int size
= wxAtoi(text
);
1033 m_sizeTextCtrl
->SetValue(wxString::Format(wxT("%d"), size
));
1040 * wxEVT_IDLE event handler for ID_RICHTEXTFONTPAGE
1043 void wxRichTextFontPage::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
1045 if (!m_sizeUnitsCtrl
)
1048 if (m_sizeUnitsCtrl
->GetSelection() == 1 && m_sizeListBox
->IsShown())
1050 m_fontListBoxParent
->Show(m_sizeListBox
, false);
1053 else if (m_sizeUnitsCtrl
->GetSelection() == 0 && !m_sizeListBox
->IsShown())
1055 m_fontListBoxParent
->Show(m_sizeListBox
, true);
1058 if (!wxRichTextFormattingDialog::GetDialog(this)->HasOption(wxRichTextFormattingDialog::Option_AllowPixelFontSize
) &&
1059 m_sizeUnitsCtrl
->IsEnabled())
1061 m_sizeUnitsCtrl
->Disable();