]>
Commit | Line | Data |
---|---|---|
97ff49b3 JS |
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 | ||
41a85215 | 12 | #include "wx/richtext/richtextfontpage.h" |
97ff49b3 | 13 | |
97ff49b3 JS |
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 | ||
28 | ////@begin wxRichTextFontPage event table entries | |
29 | EVT_TEXT( ID_RICHTEXTFONTPAGE_FACETEXTCTRL, wxRichTextFontPage::OnFaceTextCtrlUpdated ) | |
30 | ||
31 | EVT_TEXT( ID_RICHTEXTFONTPAGE_SIZETEXTCTRL, wxRichTextFontPage::OnSizeTextCtrlUpdated ) | |
32 | ||
33 | EVT_LISTBOX( ID_RICHTEXTFONTPAGE_SIZELISTBOX, wxRichTextFontPage::OnSizeListBoxSelected ) | |
34 | ||
35 | EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_STYLECTRL, wxRichTextFontPage::OnStyleCtrlSelected ) | |
36 | ||
37 | EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_WEIGHTCTRL, wxRichTextFontPage::OnWeightCtrlSelected ) | |
38 | ||
39 | EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL, wxRichTextFontPage::OnUnderliningCtrlSelected ) | |
40 | ||
42688aea JS |
41 | EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL, wxRichTextFontPage::OnStrikethroughctrlClick ) |
42 | ||
43 | EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_CAPSCTRL, wxRichTextFontPage::OnCapsctrlClick ) | |
44 | ||
30bf7630 JS |
45 | EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_SUPERSCRIPT, wxRichTextFontPage::OnRichtextfontpageSuperscriptClick ) |
46 | ||
47 | EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_SUBSCRIPT, wxRichTextFontPage::OnRichtextfontpageSubscriptClick ) | |
48 | ||
97ff49b3 JS |
49 | ////@end wxRichTextFontPage event table entries |
50 | ||
51 | END_EVENT_TABLE() | |
52 | ||
53 | /*! | |
54 | * wxRichTextFontPage constructors | |
55 | */ | |
56 | ||
57 | wxRichTextFontPage::wxRichTextFontPage( ) | |
58 | { | |
59 | Init(); | |
60 | } | |
61 | ||
62 | wxRichTextFontPage::wxRichTextFontPage( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) | |
63 | { | |
64 | Init(); | |
65 | Create(parent, id, pos, size, style); | |
66 | } | |
67 | ||
68 | /*! | |
69 | * Initialise members | |
70 | */ | |
5778b3c8 | 71 | |
97ff49b3 JS |
72 | void wxRichTextFontPage::Init() |
73 | { | |
74 | m_dontUpdate = false; | |
75 | m_colourPresent = false; | |
76 | ||
77 | ////@begin wxRichTextFontPage member initialisation | |
78 | m_faceTextCtrl = NULL; | |
79 | m_faceListBox = NULL; | |
80 | m_sizeTextCtrl = NULL; | |
81 | m_sizeListBox = NULL; | |
82 | m_styleCtrl = NULL; | |
83 | m_weightCtrl = NULL; | |
84 | m_underliningCtrl = NULL; | |
85 | m_colourCtrl = NULL; | |
42688aea JS |
86 | m_strikethroughCtrl = NULL; |
87 | m_capitalsCtrl = NULL; | |
30bf7630 JS |
88 | m_superscriptCtrl = NULL; |
89 | m_subscriptCtrl = NULL; | |
97ff49b3 JS |
90 | m_previewCtrl = NULL; |
91 | ////@end wxRichTextFontPage member initialisation | |
92 | } | |
93 | ||
94 | /*! | |
95 | * wxRichTextFontPage creator | |
96 | */ | |
97 | ||
98 | bool wxRichTextFontPage::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) | |
99 | { | |
100 | ////@begin wxRichTextFontPage creation | |
101 | wxPanel::Create( parent, id, pos, size, style ); | |
102 | ||
103 | CreateControls(); | |
104 | if (GetSizer()) | |
105 | { | |
106 | GetSizer()->SetSizeHints(this); | |
107 | } | |
108 | Centre(); | |
109 | ////@end wxRichTextFontPage creation | |
110 | return true; | |
111 | } | |
112 | ||
113 | /*! | |
114 | * Control creation for wxRichTextFontPage | |
115 | */ | |
116 | ||
117 | void wxRichTextFontPage::CreateControls() | |
118 | { | |
119 | ////@begin wxRichTextFontPage content construction | |
120 | wxRichTextFontPage* itemPanel1 = this; | |
121 | ||
122 | wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); | |
123 | itemPanel1->SetSizer(itemBoxSizer2); | |
124 | ||
125 | wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL); | |
126 | itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5); | |
127 | ||
128 | wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL); | |
129 | itemBoxSizer3->Add(itemBoxSizer4, 1, wxGROW, 5); | |
130 | ||
131 | wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL); | |
132 | itemBoxSizer4->Add(itemBoxSizer5, 1, wxGROW, 5); | |
133 | ||
134 | wxStaticText* itemStaticText6 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Font:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 135 | itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
97ff49b3 | 136 | |
42688aea | 137 | m_faceTextCtrl = new wxTextCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_FACETEXTCTRL, _T(""), wxDefaultPosition, wxDefaultSize, 0 ); |
97ff49b3 | 138 | m_faceTextCtrl->SetHelpText(_("Type a font name.")); |
2fce6547 | 139 | if (wxRichTextFontPage::ShowToolTips()) |
97ff49b3 JS |
140 | m_faceTextCtrl->SetToolTip(_("Type a font name.")); |
141 | itemBoxSizer5->Add(m_faceTextCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5); | |
142 | ||
2fce6547 | 143 | m_faceListBox = new wxRichTextFontListBox( itemPanel1, ID_RICHTEXTFONTPAGE_FACELISTBOX, wxDefaultPosition, wxSize(200, 100), 0 ); |
97ff49b3 | 144 | m_faceListBox->SetHelpText(_("Lists the available fonts.")); |
2fce6547 | 145 | if (wxRichTextFontPage::ShowToolTips()) |
97ff49b3 JS |
146 | m_faceListBox->SetToolTip(_("Lists the available fonts.")); |
147 | itemBoxSizer5->Add(m_faceListBox, 1, wxGROW|wxALL|wxFIXED_MINSIZE, 5); | |
148 | ||
149 | wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxVERTICAL); | |
150 | itemBoxSizer4->Add(itemBoxSizer9, 0, wxGROW, 5); | |
151 | ||
152 | wxStaticText* itemStaticText10 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Size:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 153 | itemBoxSizer9->Add(itemStaticText10, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
97ff49b3 | 154 | |
42688aea | 155 | m_sizeTextCtrl = new wxTextCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_SIZETEXTCTRL, _T(""), wxDefaultPosition, wxSize(50, -1), 0 ); |
97ff49b3 | 156 | m_sizeTextCtrl->SetHelpText(_("Type a size in points.")); |
2fce6547 | 157 | if (wxRichTextFontPage::ShowToolTips()) |
97ff49b3 JS |
158 | m_sizeTextCtrl->SetToolTip(_("Type a size in points.")); |
159 | itemBoxSizer9->Add(m_sizeTextCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5); | |
160 | ||
2fce6547 JS |
161 | wxArrayString m_sizeListBoxStrings; |
162 | m_sizeListBox = new wxListBox( itemPanel1, ID_RICHTEXTFONTPAGE_SIZELISTBOX, wxDefaultPosition, wxSize(50, -1), m_sizeListBoxStrings, wxLB_SINGLE ); | |
97ff49b3 | 163 | m_sizeListBox->SetHelpText(_("Lists font sizes in points.")); |
2fce6547 | 164 | if (wxRichTextFontPage::ShowToolTips()) |
97ff49b3 JS |
165 | m_sizeListBox->SetToolTip(_("Lists font sizes in points.")); |
166 | itemBoxSizer9->Add(m_sizeListBox, 1, wxALIGN_CENTER_HORIZONTAL|wxALL|wxFIXED_MINSIZE, 5); | |
167 | ||
168 | wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL); | |
169 | itemBoxSizer3->Add(itemBoxSizer13, 0, wxGROW, 5); | |
170 | ||
171 | wxBoxSizer* itemBoxSizer14 = new wxBoxSizer(wxVERTICAL); | |
172 | itemBoxSizer13->Add(itemBoxSizer14, 1, wxGROW, 5); | |
173 | ||
174 | wxStaticText* itemStaticText15 = new wxStaticText( itemPanel1, wxID_STATIC, _("Font st&yle:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 175 | itemBoxSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
97ff49b3 | 176 | |
2fce6547 JS |
177 | wxArrayString m_styleCtrlStrings; |
178 | m_styleCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_STYLECTRL, _T(""), wxDefaultPosition, wxDefaultSize, m_styleCtrlStrings, wxCB_READONLY ); | |
97ff49b3 | 179 | m_styleCtrl->SetHelpText(_("Select regular or italic style.")); |
2fce6547 | 180 | if (wxRichTextFontPage::ShowToolTips()) |
97ff49b3 JS |
181 | m_styleCtrl->SetToolTip(_("Select regular or italic style.")); |
182 | itemBoxSizer14->Add(m_styleCtrl, 0, wxGROW|wxALL, 5); | |
183 | ||
184 | wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxVERTICAL); | |
185 | itemBoxSizer13->Add(itemBoxSizer17, 1, wxGROW, 5); | |
186 | ||
187 | wxStaticText* itemStaticText18 = new wxStaticText( itemPanel1, wxID_STATIC, _("Font &weight:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 188 | itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
97ff49b3 | 189 | |
2fce6547 JS |
190 | wxArrayString m_weightCtrlStrings; |
191 | m_weightCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_WEIGHTCTRL, _T(""), wxDefaultPosition, wxDefaultSize, m_weightCtrlStrings, wxCB_READONLY ); | |
97ff49b3 | 192 | m_weightCtrl->SetHelpText(_("Select regular or bold.")); |
2fce6547 | 193 | if (wxRichTextFontPage::ShowToolTips()) |
97ff49b3 JS |
194 | m_weightCtrl->SetToolTip(_("Select regular or bold.")); |
195 | itemBoxSizer17->Add(m_weightCtrl, 0, wxGROW|wxALL, 5); | |
196 | ||
197 | wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL); | |
198 | itemBoxSizer13->Add(itemBoxSizer20, 1, wxGROW, 5); | |
199 | ||
200 | wxStaticText* itemStaticText21 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Underlining:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 201 | itemBoxSizer20->Add(itemStaticText21, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
97ff49b3 | 202 | |
2fce6547 JS |
203 | wxArrayString m_underliningCtrlStrings; |
204 | m_underliningCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL, _T(""), wxDefaultPosition, wxDefaultSize, m_underliningCtrlStrings, wxCB_READONLY ); | |
97ff49b3 | 205 | m_underliningCtrl->SetHelpText(_("Select underlining or no underlining.")); |
2fce6547 | 206 | if (wxRichTextFontPage::ShowToolTips()) |
97ff49b3 JS |
207 | m_underliningCtrl->SetToolTip(_("Select underlining or no underlining.")); |
208 | itemBoxSizer20->Add(m_underliningCtrl, 0, wxGROW|wxALL, 5); | |
209 | ||
210 | wxBoxSizer* itemBoxSizer23 = new wxBoxSizer(wxVERTICAL); | |
211 | itemBoxSizer13->Add(itemBoxSizer23, 0, wxGROW, 5); | |
212 | ||
213 | wxStaticText* itemStaticText24 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Colour:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 214 | itemBoxSizer23->Add(itemStaticText24, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
97ff49b3 JS |
215 | |
216 | m_colourCtrl = new wxRichTextColourSwatchCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_COLOURCTRL, wxDefaultPosition, wxSize(40, 20), wxSIMPLE_BORDER ); | |
217 | m_colourCtrl->SetHelpText(_("Click to change the text colour.")); | |
2fce6547 | 218 | if (wxRichTextFontPage::ShowToolTips()) |
97ff49b3 JS |
219 | m_colourCtrl->SetToolTip(_("Click to change the text colour.")); |
220 | itemBoxSizer23->Add(m_colourCtrl, 0, wxALIGN_LEFT|wxALL, 5); | |
221 | ||
42688aea JS |
222 | wxBoxSizer* itemBoxSizer26 = new wxBoxSizer(wxHORIZONTAL); |
223 | itemBoxSizer3->Add(itemBoxSizer26, 0, wxGROW, 5); | |
224 | ||
225 | m_strikethroughCtrl = new wxCheckBox( itemPanel1, ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL, _("&Strikethrough"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE ); | |
226 | m_strikethroughCtrl->SetValue(false); | |
227 | m_strikethroughCtrl->SetHelpText(_("Check to show a line through the text.")); | |
2fce6547 | 228 | if (wxRichTextFontPage::ShowToolTips()) |
42688aea JS |
229 | m_strikethroughCtrl->SetToolTip(_("Check to show a line through the text.")); |
230 | itemBoxSizer26->Add(m_strikethroughCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
231 | ||
232 | m_capitalsCtrl = new wxCheckBox( itemPanel1, ID_RICHTEXTFONTPAGE_CAPSCTRL, _("Ca&pitals"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE ); | |
233 | m_capitalsCtrl->SetValue(false); | |
234 | m_capitalsCtrl->SetHelpText(_("Check to show the text in capitals.")); | |
2fce6547 | 235 | if (wxRichTextFontPage::ShowToolTips()) |
42688aea JS |
236 | m_capitalsCtrl->SetToolTip(_("Check to show the text in capitals.")); |
237 | itemBoxSizer26->Add(m_capitalsCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
238 | ||
30bf7630 JS |
239 | m_superscriptCtrl = new wxCheckBox( itemPanel1, ID_RICHTEXTFONTPAGE_SUPERSCRIPT, _("Supe&rscript"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE ); |
240 | m_superscriptCtrl->SetValue(false); | |
241 | m_superscriptCtrl->SetHelpText(_("Check to show the text in superscript.")); | |
242 | if (wxRichTextFontPage::ShowToolTips()) | |
243 | m_superscriptCtrl->SetToolTip(_("Check to show the text in superscript.")); | |
244 | itemBoxSizer26->Add(m_superscriptCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
245 | ||
246 | m_subscriptCtrl = new wxCheckBox( itemPanel1, ID_RICHTEXTFONTPAGE_SUBSCRIPT, _("Subscrip&t"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE ); | |
247 | m_subscriptCtrl->SetValue(false); | |
248 | m_subscriptCtrl->SetHelpText(_("Check to show the text in subscript.")); | |
249 | if (wxRichTextFontPage::ShowToolTips()) | |
250 | m_subscriptCtrl->SetToolTip(_("Check to show the text in subscript.")); | |
251 | itemBoxSizer26->Add(m_subscriptCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
252 | ||
2fce6547 | 253 | itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL, 5); |
97ff49b3 | 254 | |
2fce6547 | 255 | m_previewCtrl = new wxRichTextFontPreviewCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_PREVIEWCTRL, wxDefaultPosition, wxSize(100, 60), 0 ); |
97ff49b3 | 256 | m_previewCtrl->SetHelpText(_("Shows a preview of the font settings.")); |
2fce6547 | 257 | if (wxRichTextFontPage::ShowToolTips()) |
97ff49b3 JS |
258 | m_previewCtrl->SetToolTip(_("Shows a preview of the font settings.")); |
259 | itemBoxSizer3->Add(m_previewCtrl, 0, wxGROW|wxALL, 5); | |
260 | ||
261 | ////@end wxRichTextFontPage content construction | |
262 | ||
263 | m_faceListBox->UpdateFonts(); | |
264 | ||
265 | m_styleCtrl->Append(_("Regular")); | |
266 | m_styleCtrl->Append(_("Italic")); | |
267 | ||
268 | m_weightCtrl->Append(_("Regular")); | |
269 | m_weightCtrl->Append(_("Bold")); | |
270 | ||
271 | m_underliningCtrl->Append(_("Not underlined")); | |
272 | m_underliningCtrl->Append(_("Underlined")); | |
273 | ||
274 | wxString nStr; | |
275 | int i; | |
276 | for (i = 8; i < 40; i++) | |
277 | { | |
278 | nStr.Printf(wxT("%d"), i); | |
279 | m_sizeListBox->Append(nStr); | |
280 | } | |
281 | m_sizeListBox->Append(wxT("48")); | |
282 | m_sizeListBox->Append(wxT("72")); | |
283 | } | |
284 | ||
285 | /// Transfer data from/to window | |
286 | bool wxRichTextFontPage::TransferDataFromWindow() | |
287 | { | |
288 | wxPanel::TransferDataFromWindow(); | |
289 | ||
44cc96a8 | 290 | wxTextAttr* attr = GetAttributes(); |
97ff49b3 JS |
291 | |
292 | if (m_faceListBox->GetSelection() != wxNOT_FOUND) | |
293 | { | |
294 | wxString faceName = m_faceListBox->GetFaceName(m_faceListBox->GetSelection()); | |
295 | if (!faceName.IsEmpty()) | |
296 | { | |
44cc96a8 | 297 | attr->SetFontFaceName(faceName); |
97ff49b3 JS |
298 | } |
299 | } | |
300 | else | |
301 | attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_FACE)); | |
302 | ||
303 | wxString strSize = m_sizeTextCtrl->GetValue(); | |
304 | if (!strSize.IsEmpty()) | |
305 | { | |
306 | int sz = wxAtoi(strSize); | |
307 | if (sz > 0) | |
308 | { | |
44cc96a8 | 309 | attr->SetFontSize(sz); |
97ff49b3 JS |
310 | } |
311 | } | |
312 | else | |
313 | attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_SIZE)); | |
314 | ||
315 | if (m_styleCtrl->GetSelection() != wxNOT_FOUND) | |
316 | { | |
317 | int style; | |
318 | if (m_styleCtrl->GetStringSelection() == _("Italic")) | |
319 | style = wxITALIC; | |
320 | else | |
321 | style = wxNORMAL; | |
322 | ||
44cc96a8 | 323 | attr->SetFontStyle(style); |
97ff49b3 JS |
324 | } |
325 | else | |
326 | attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_ITALIC)); | |
327 | ||
328 | if (m_weightCtrl->GetSelection() != wxNOT_FOUND) | |
329 | { | |
330 | int weight; | |
331 | if (m_weightCtrl->GetStringSelection() == _("Bold")) | |
332 | weight = wxBOLD; | |
333 | else | |
334 | weight = wxNORMAL; | |
335 | ||
44cc96a8 | 336 | attr->SetFontWeight(weight); |
97ff49b3 JS |
337 | } |
338 | else | |
339 | attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_WEIGHT)); | |
340 | ||
341 | if (m_underliningCtrl->GetSelection() != wxNOT_FOUND) | |
342 | { | |
343 | bool underlined; | |
344 | if (m_underliningCtrl->GetStringSelection() == _("Underlined")) | |
345 | underlined = true; | |
346 | else | |
347 | underlined = false; | |
348 | ||
44cc96a8 | 349 | attr->SetFontUnderlined(underlined); |
97ff49b3 JS |
350 | } |
351 | else | |
352 | attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_UNDERLINE)); | |
353 | ||
354 | if (m_colourPresent) | |
355 | { | |
356 | attr->SetTextColour(m_colourCtrl->GetBackgroundColour()); | |
357 | } | |
358 | else | |
359 | attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_TEXT_COLOUR)); | |
44cc96a8 | 360 | |
42688aea JS |
361 | if (m_strikethroughCtrl->Get3StateValue() != wxCHK_UNDETERMINED) |
362 | { | |
363 | attr->SetTextEffectFlags(attr->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_STRIKETHROUGH); | |
364 | ||
365 | if (m_strikethroughCtrl->Get3StateValue() == wxCHK_CHECKED) | |
366 | attr->SetTextEffects(attr->GetTextEffects() | wxTEXT_ATTR_EFFECT_STRIKETHROUGH); | |
367 | else | |
368 | attr->SetTextEffects(attr->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_STRIKETHROUGH); | |
369 | } | |
370 | ||
371 | if (m_capitalsCtrl->Get3StateValue() != wxCHK_UNDETERMINED) | |
372 | { | |
373 | attr->SetTextEffectFlags(attr->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_CAPITALS); | |
44cc96a8 | 374 | |
42688aea JS |
375 | if (m_capitalsCtrl->Get3StateValue() == wxCHK_CHECKED) |
376 | attr->SetTextEffects(attr->GetTextEffects() | wxTEXT_ATTR_EFFECT_CAPITALS); | |
377 | else | |
378 | attr->SetTextEffects(attr->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_CAPITALS); | |
379 | } | |
97ff49b3 | 380 | |
30bf7630 JS |
381 | if (m_superscriptCtrl->Get3StateValue() == wxCHK_CHECKED) |
382 | { | |
383 | attr->SetTextEffectFlags(attr->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_SUPERSCRIPT); | |
384 | attr->SetTextEffects(attr->GetTextEffects() | wxTEXT_ATTR_EFFECT_SUPERSCRIPT); | |
385 | attr->SetTextEffects(attr->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_SUBSCRIPT); | |
386 | } | |
387 | else if (m_subscriptCtrl->Get3StateValue() == wxCHK_CHECKED) | |
388 | { | |
389 | attr->SetTextEffectFlags(attr->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_SUBSCRIPT); | |
390 | attr->SetTextEffects(attr->GetTextEffects() | wxTEXT_ATTR_EFFECT_SUBSCRIPT); | |
391 | attr->SetTextEffects(attr->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_SUPERSCRIPT); | |
392 | } | |
393 | else | |
394 | { | |
395 | attr->SetTextEffectFlags(attr->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_SUBSCRIPT | wxTEXT_ATTR_EFFECT_SUPERSCRIPT ); | |
396 | attr->SetTextEffects(attr->GetTextEffects() & ~( wxTEXT_ATTR_EFFECT_SUPERSCRIPT | wxTEXT_ATTR_EFFECT_SUBSCRIPT)); | |
397 | } | |
398 | ||
97ff49b3 JS |
399 | return true; |
400 | } | |
401 | ||
402 | bool wxRichTextFontPage::TransferDataToWindow() | |
403 | { | |
404 | wxPanel::TransferDataToWindow(); | |
405 | ||
406 | m_dontUpdate = true; | |
44cc96a8 | 407 | wxTextAttr* attr = GetAttributes(); |
97ff49b3 | 408 | |
44cc96a8 | 409 | if (attr->HasFontFaceName()) |
97ff49b3 | 410 | { |
44cc96a8 | 411 | m_faceTextCtrl->SetValue(attr->GetFontFaceName()); |
97ff49b3 JS |
412 | m_faceListBox->SetFaceNameSelection(attr->GetFont().GetFaceName()); |
413 | } | |
414 | else | |
415 | { | |
416 | m_faceTextCtrl->SetValue(wxEmptyString); | |
417 | m_faceListBox->SetFaceNameSelection(wxEmptyString); | |
418 | } | |
419 | ||
44cc96a8 | 420 | if (attr->HasFontSize()) |
97ff49b3 | 421 | { |
44cc96a8 | 422 | wxString strSize = wxString::Format(wxT("%d"), attr->GetFontSize()); |
97ff49b3 JS |
423 | m_sizeTextCtrl->SetValue(strSize); |
424 | if (m_sizeListBox->FindString(strSize) != wxNOT_FOUND) | |
425 | m_sizeListBox->SetStringSelection(strSize); | |
426 | } | |
427 | else | |
428 | { | |
429 | m_sizeTextCtrl->SetValue(wxEmptyString); | |
430 | m_sizeListBox->SetSelection(wxNOT_FOUND); | |
431 | } | |
432 | ||
44cc96a8 | 433 | if (attr->HasFontWeight()) |
97ff49b3 | 434 | { |
44cc96a8 | 435 | if (attr->GetFontWeight() == wxBOLD) |
97ff49b3 JS |
436 | m_weightCtrl->SetSelection(1); |
437 | else | |
438 | m_weightCtrl->SetSelection(0); | |
439 | } | |
440 | else | |
441 | { | |
442 | m_weightCtrl->SetSelection(wxNOT_FOUND); | |
443 | } | |
444 | ||
44cc96a8 | 445 | if (attr->HasFontItalic()) |
97ff49b3 | 446 | { |
44cc96a8 | 447 | if (attr->GetFontStyle() == wxITALIC) |
97ff49b3 JS |
448 | m_styleCtrl->SetSelection(1); |
449 | else | |
450 | m_styleCtrl->SetSelection(0); | |
451 | } | |
452 | else | |
453 | { | |
454 | m_styleCtrl->SetSelection(wxNOT_FOUND); | |
455 | } | |
456 | ||
44cc96a8 | 457 | if (attr->HasFontUnderlined()) |
97ff49b3 | 458 | { |
44cc96a8 | 459 | if (attr->GetFontUnderlined()) |
97ff49b3 JS |
460 | m_underliningCtrl->SetSelection(1); |
461 | else | |
462 | m_underliningCtrl->SetSelection(0); | |
463 | } | |
464 | else | |
465 | { | |
466 | m_underliningCtrl->SetSelection(wxNOT_FOUND); | |
467 | } | |
468 | ||
469 | if (attr->HasTextColour()) | |
470 | { | |
3638bb5c | 471 | m_colourCtrl->SetColour(attr->GetTextColour()); |
97ff49b3 JS |
472 | m_colourPresent = true; |
473 | } | |
474 | ||
42688aea JS |
475 | if (attr->HasTextEffects()) |
476 | { | |
477 | if (attr->GetTextEffectFlags() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH) | |
478 | { | |
479 | if (attr->GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH) | |
480 | m_strikethroughCtrl->Set3StateValue(wxCHK_CHECKED); | |
481 | else | |
482 | m_strikethroughCtrl->Set3StateValue(wxCHK_UNCHECKED); | |
483 | } | |
484 | else | |
485 | m_strikethroughCtrl->Set3StateValue(wxCHK_UNDETERMINED); | |
486 | ||
487 | if (attr->GetTextEffectFlags() & wxTEXT_ATTR_EFFECT_CAPITALS) | |
488 | { | |
489 | if (attr->GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS) | |
490 | m_capitalsCtrl->Set3StateValue(wxCHK_CHECKED); | |
491 | else | |
492 | m_capitalsCtrl->Set3StateValue(wxCHK_UNCHECKED); | |
493 | } | |
494 | else | |
495 | m_capitalsCtrl->Set3StateValue(wxCHK_UNDETERMINED); | |
30bf7630 JS |
496 | |
497 | if ( attr->GetTextEffectFlags() & (wxTEXT_ATTR_EFFECT_SUPERSCRIPT | wxTEXT_ATTR_EFFECT_SUBSCRIPT) ) | |
498 | { | |
499 | if (attr->GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT) | |
500 | { | |
501 | m_superscriptCtrl->Set3StateValue(wxCHK_CHECKED); | |
502 | m_subscriptCtrl->Set3StateValue(wxCHK_UNCHECKED); | |
503 | } | |
504 | else if (attr->GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT) | |
505 | { | |
506 | m_superscriptCtrl->Set3StateValue(wxCHK_UNCHECKED); | |
507 | m_subscriptCtrl->Set3StateValue(wxCHK_CHECKED); | |
508 | } | |
509 | else | |
510 | { | |
511 | m_superscriptCtrl->Set3StateValue(wxCHK_UNCHECKED); | |
512 | m_subscriptCtrl->Set3StateValue(wxCHK_UNCHECKED); | |
513 | } | |
514 | } | |
515 | else | |
516 | { | |
517 | m_superscriptCtrl->Set3StateValue(wxCHK_UNCHECKED); | |
518 | m_subscriptCtrl->Set3StateValue(wxCHK_UNCHECKED); | |
519 | } | |
42688aea JS |
520 | } |
521 | else | |
522 | { | |
523 | m_strikethroughCtrl->Set3StateValue(wxCHK_UNDETERMINED); | |
524 | m_capitalsCtrl->Set3StateValue(wxCHK_UNDETERMINED); | |
30bf7630 JS |
525 | m_superscriptCtrl->Set3StateValue(wxCHK_UNCHECKED); |
526 | m_subscriptCtrl->Set3StateValue(wxCHK_UNCHECKED); | |
42688aea JS |
527 | } |
528 | ||
97ff49b3 JS |
529 | UpdatePreview(); |
530 | ||
531 | m_dontUpdate = false; | |
532 | ||
533 | return true; | |
534 | } | |
535 | ||
44cc96a8 | 536 | wxTextAttr* wxRichTextFontPage::GetAttributes() |
97ff49b3 JS |
537 | { |
538 | return wxRichTextFormattingDialog::GetDialogAttributes(this); | |
539 | } | |
540 | ||
541 | /// Updates the font preview | |
542 | void wxRichTextFontPage::UpdatePreview() | |
543 | { | |
544 | wxFont font(*wxNORMAL_FONT); | |
545 | ||
546 | if (m_colourPresent) | |
547 | m_previewCtrl->SetForegroundColour(m_colourCtrl->GetBackgroundColour()); | |
548 | ||
549 | if (m_faceListBox->GetSelection() != wxNOT_FOUND) | |
550 | { | |
551 | wxString faceName = m_faceListBox->GetFaceName(m_faceListBox->GetSelection()); | |
552 | font.SetFaceName(faceName); | |
553 | } | |
554 | ||
555 | wxString strSize = m_sizeTextCtrl->GetValue(); | |
556 | if (!strSize.IsEmpty()) | |
557 | { | |
558 | int sz = wxAtoi(strSize); | |
559 | if (sz > 0) | |
560 | font.SetPointSize(sz); | |
561 | } | |
562 | ||
563 | if (m_styleCtrl->GetSelection() != wxNOT_FOUND) | |
564 | { | |
565 | int style; | |
566 | if (m_styleCtrl->GetStringSelection() == _("Italic")) | |
567 | style = wxITALIC; | |
568 | else | |
569 | style = wxNORMAL; | |
570 | ||
571 | font.SetStyle(style); | |
572 | } | |
573 | ||
574 | if (m_weightCtrl->GetSelection() != wxNOT_FOUND) | |
575 | { | |
576 | int weight; | |
577 | if (m_weightCtrl->GetStringSelection() == _("Bold")) | |
578 | weight = wxBOLD; | |
579 | else | |
580 | weight = wxNORMAL; | |
581 | ||
582 | font.SetWeight(weight); | |
583 | } | |
584 | ||
585 | if (m_underliningCtrl->GetSelection() != wxNOT_FOUND) | |
586 | { | |
587 | bool underlined; | |
588 | if (m_underliningCtrl->GetStringSelection() == _("Underlined")) | |
589 | underlined = true; | |
590 | else | |
591 | underlined = false; | |
592 | ||
593 | font.SetUnderlined(underlined); | |
594 | } | |
44cc96a8 | 595 | |
42688aea JS |
596 | int textEffects = 0; |
597 | ||
598 | if (m_strikethroughCtrl->Get3StateValue() == wxCHK_CHECKED) | |
599 | { | |
600 | textEffects |= wxTEXT_ATTR_EFFECT_STRIKETHROUGH; | |
601 | } | |
602 | ||
603 | if (m_capitalsCtrl->Get3StateValue() == wxCHK_CHECKED) | |
604 | { | |
605 | textEffects |= wxTEXT_ATTR_EFFECT_CAPITALS; | |
606 | } | |
97ff49b3 | 607 | |
30bf7630 JS |
608 | if ( m_superscriptCtrl->Get3StateValue() == wxCHK_CHECKED ) |
609 | textEffects |= wxTEXT_ATTR_EFFECT_SUPERSCRIPT; | |
610 | else if ( m_subscriptCtrl->Get3StateValue() == wxCHK_CHECKED ) | |
611 | textEffects |= wxTEXT_ATTR_EFFECT_SUBSCRIPT; | |
612 | ||
97ff49b3 | 613 | m_previewCtrl->SetFont(font); |
42688aea | 614 | m_previewCtrl->SetTextEffects(textEffects); |
97ff49b3 JS |
615 | m_previewCtrl->Refresh(); |
616 | } | |
617 | ||
618 | /*! | |
619 | * Should we show tooltips? | |
620 | */ | |
621 | ||
622 | bool wxRichTextFontPage::ShowToolTips() | |
623 | { | |
dadd4f55 | 624 | return wxRichTextFormattingDialog::ShowToolTips(); |
97ff49b3 JS |
625 | } |
626 | ||
627 | /*! | |
628 | * Get bitmap resources | |
629 | */ | |
630 | ||
631 | wxBitmap wxRichTextFontPage::GetBitmapResource( const wxString& name ) | |
632 | { | |
633 | // Bitmap retrieval | |
634 | ////@begin wxRichTextFontPage bitmap retrieval | |
635 | wxUnusedVar(name); | |
636 | return wxNullBitmap; | |
637 | ////@end wxRichTextFontPage bitmap retrieval | |
638 | } | |
639 | ||
640 | /*! | |
641 | * Get icon resources | |
642 | */ | |
643 | ||
644 | wxIcon wxRichTextFontPage::GetIconResource( const wxString& name ) | |
645 | { | |
646 | // Icon retrieval | |
647 | ////@begin wxRichTextFontPage icon retrieval | |
648 | wxUnusedVar(name); | |
649 | return wxNullIcon; | |
650 | ////@end wxRichTextFontPage icon retrieval | |
651 | } | |
652 | ||
653 | /*! | |
654 | * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_FACETEXTCTRL | |
655 | */ | |
656 | ||
657 | void wxRichTextFontPage::OnFaceTextCtrlUpdated( wxCommandEvent& WXUNUSED(event) ) | |
658 | { | |
659 | if (m_dontUpdate) | |
660 | return; | |
661 | ||
662 | wxString facename = m_faceTextCtrl->GetValue(); | |
663 | if (!facename.IsEmpty()) | |
664 | { | |
665 | if (m_faceListBox->HasFaceName(facename)) | |
666 | { | |
667 | m_faceListBox->SetFaceNameSelection(facename); | |
668 | UpdatePreview(); | |
669 | } | |
670 | else | |
671 | { | |
672 | // Try to find a partial match | |
673 | const wxArrayString& arr = m_faceListBox->GetFaceNames(); | |
674 | size_t i; | |
675 | for (i = 0; i < arr.GetCount(); i++) | |
676 | { | |
677 | if (arr[i].Mid(0, facename.Length()).Lower() == facename.Lower()) | |
678 | { | |
f18eaf26 | 679 | m_faceListBox->ScrollToRow(i); |
97ff49b3 JS |
680 | break; |
681 | } | |
682 | } | |
683 | } | |
684 | } | |
685 | } | |
686 | ||
687 | ||
688 | /*! | |
689 | * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_SIZETEXTCTRL | |
690 | */ | |
691 | ||
692 | void wxRichTextFontPage::OnSizeTextCtrlUpdated( wxCommandEvent& WXUNUSED(event) ) | |
693 | { | |
694 | if (m_dontUpdate) | |
695 | return; | |
696 | ||
697 | wxString strSize = m_sizeTextCtrl->GetValue(); | |
698 | if (!strSize.IsEmpty() && m_sizeListBox->FindString(strSize) != wxNOT_FOUND) | |
699 | m_sizeListBox->SetStringSelection(strSize); | |
700 | UpdatePreview(); | |
701 | } | |
702 | ||
703 | ||
704 | /*! | |
705 | * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_SIZELISTBOX | |
706 | */ | |
707 | ||
708 | void wxRichTextFontPage::OnSizeListBoxSelected( wxCommandEvent& event ) | |
709 | { | |
710 | m_dontUpdate = true; | |
711 | ||
712 | m_sizeTextCtrl->SetValue(event.GetString()); | |
713 | ||
714 | m_dontUpdate = false; | |
715 | ||
716 | UpdatePreview(); | |
717 | } | |
718 | ||
719 | /*! | |
720 | * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_FACELISTBOX | |
721 | */ | |
722 | ||
723 | void wxRichTextFontPage::OnFaceListBoxSelected( wxCommandEvent& WXUNUSED(event) ) | |
724 | { | |
725 | m_dontUpdate = true; | |
726 | ||
727 | m_faceTextCtrl->SetValue(m_faceListBox->GetFaceName(m_faceListBox->GetSelection())); | |
728 | ||
729 | m_dontUpdate = false; | |
730 | ||
731 | UpdatePreview(); | |
732 | } | |
733 | ||
734 | /*! | |
735 | * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_STYLECTRL | |
736 | */ | |
737 | ||
738 | void wxRichTextFontPage::OnStyleCtrlSelected( wxCommandEvent& WXUNUSED(event) ) | |
739 | { | |
740 | UpdatePreview(); | |
741 | } | |
742 | ||
743 | ||
744 | /*! | |
745 | * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL | |
746 | */ | |
747 | ||
748 | void wxRichTextFontPage::OnUnderliningCtrlSelected( wxCommandEvent& WXUNUSED(event) ) | |
749 | { | |
750 | UpdatePreview(); | |
751 | } | |
752 | ||
753 | ||
754 | /*! | |
755 | * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_WEIGHTCTRL | |
756 | */ | |
757 | ||
758 | void wxRichTextFontPage::OnWeightCtrlSelected( wxCommandEvent& WXUNUSED(event) ) | |
759 | { | |
760 | UpdatePreview(); | |
761 | } | |
762 | ||
763 | void wxRichTextFontPage::OnColourClicked( wxCommandEvent& WXUNUSED(event) ) | |
764 | { | |
765 | m_colourPresent = true; | |
766 | ||
767 | UpdatePreview(); | |
768 | } | |
42688aea JS |
769 | /*! |
770 | * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL | |
771 | */ | |
772 | ||
773 | void wxRichTextFontPage::OnStrikethroughctrlClick( wxCommandEvent& WXUNUSED(event) ) | |
774 | { | |
775 | UpdatePreview(); | |
776 | } | |
777 | ||
778 | /*! | |
779 | * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_CAPSCTRL | |
780 | */ | |
781 | ||
782 | void wxRichTextFontPage::OnCapsctrlClick( wxCommandEvent& WXUNUSED(event) ) | |
783 | { | |
784 | UpdatePreview(); | |
785 | } | |
786 | ||
30bf7630 JS |
787 | /*! |
788 | * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUPERSCRIPT | |
789 | */ | |
790 | ||
791 | void wxRichTextFontPage::OnRichtextfontpageSuperscriptClick( wxCommandEvent& WXUNUSED(event) ) | |
792 | { | |
793 | if ( m_superscriptCtrl->Get3StateValue() == wxCHK_CHECKED && m_subscriptCtrl->Get3StateValue() == wxCHK_CHECKED ) | |
794 | m_subscriptCtrl->Set3StateValue( wxCHK_UNCHECKED ); | |
795 | UpdatePreview(); | |
796 | } | |
797 | ||
798 | /*! | |
799 | * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUBSCRIPT | |
800 | */ | |
42688aea | 801 | |
30bf7630 JS |
802 | void wxRichTextFontPage::OnRichtextfontpageSubscriptClick( wxCommandEvent& WXUNUSED(event) ) |
803 | { | |
804 | if ( m_superscriptCtrl->Get3StateValue() == wxCHK_CHECKED && m_subscriptCtrl->Get3StateValue() == wxCHK_CHECKED ) | |
805 | m_superscriptCtrl->Set3StateValue( wxCHK_UNCHECKED ); | |
806 | UpdatePreview(); | |
807 | } |