]>
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 | ||
12 | ////@begin includes | |
13 | ////@end includes | |
14 | ||
15 | #include "../../include/wx/richtext/richtextfontpage.h" | |
16 | ||
17 | ////@begin XPM images | |
18 | ////@end XPM images | |
19 | ||
20 | /*! | |
21 | * wxRichTextFontPage type definition | |
22 | */ | |
23 | ||
24 | IMPLEMENT_DYNAMIC_CLASS( wxRichTextFontPage, wxPanel ) | |
25 | ||
26 | /*! | |
27 | * wxRichTextFontPage event table definition | |
28 | */ | |
29 | ||
30 | BEGIN_EVENT_TABLE( wxRichTextFontPage, wxPanel ) | |
31 | EVT_LISTBOX( ID_RICHTEXTFONTPAGE_FACELISTBOX, wxRichTextFontPage::OnFaceListBoxSelected ) | |
32 | EVT_BUTTON( ID_RICHTEXTFONTPAGE_COLOURCTRL, wxRichTextFontPage::OnColourClicked ) | |
33 | ||
34 | ////@begin wxRichTextFontPage event table entries | |
35 | EVT_TEXT( ID_RICHTEXTFONTPAGE_FACETEXTCTRL, wxRichTextFontPage::OnFaceTextCtrlUpdated ) | |
36 | ||
37 | EVT_TEXT( ID_RICHTEXTFONTPAGE_SIZETEXTCTRL, wxRichTextFontPage::OnSizeTextCtrlUpdated ) | |
38 | ||
39 | EVT_LISTBOX( ID_RICHTEXTFONTPAGE_SIZELISTBOX, wxRichTextFontPage::OnSizeListBoxSelected ) | |
40 | ||
41 | EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_STYLECTRL, wxRichTextFontPage::OnStyleCtrlSelected ) | |
42 | ||
43 | EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_WEIGHTCTRL, wxRichTextFontPage::OnWeightCtrlSelected ) | |
44 | ||
45 | EVT_COMBOBOX( ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL, wxRichTextFontPage::OnUnderliningCtrlSelected ) | |
46 | ||
47 | ////@end wxRichTextFontPage event table entries | |
48 | ||
49 | END_EVENT_TABLE() | |
50 | ||
51 | /*! | |
52 | * wxRichTextFontPage constructors | |
53 | */ | |
54 | ||
55 | wxRichTextFontPage::wxRichTextFontPage( ) | |
56 | { | |
57 | Init(); | |
58 | } | |
59 | ||
60 | wxRichTextFontPage::wxRichTextFontPage( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) | |
61 | { | |
62 | Init(); | |
63 | Create(parent, id, pos, size, style); | |
64 | } | |
65 | ||
66 | /*! | |
67 | * Initialise members | |
68 | */ | |
69 | ||
70 | void wxRichTextFontPage::Init() | |
71 | { | |
72 | m_dontUpdate = false; | |
73 | m_colourPresent = false; | |
74 | ||
75 | ////@begin wxRichTextFontPage member initialisation | |
76 | m_faceTextCtrl = NULL; | |
77 | m_faceListBox = NULL; | |
78 | m_sizeTextCtrl = NULL; | |
79 | m_sizeListBox = NULL; | |
80 | m_styleCtrl = NULL; | |
81 | m_weightCtrl = NULL; | |
82 | m_underliningCtrl = NULL; | |
83 | m_colourCtrl = NULL; | |
84 | m_previewCtrl = NULL; | |
85 | ////@end wxRichTextFontPage member initialisation | |
86 | } | |
87 | ||
88 | /*! | |
89 | * wxRichTextFontPage creator | |
90 | */ | |
91 | ||
92 | bool wxRichTextFontPage::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) | |
93 | { | |
94 | ////@begin wxRichTextFontPage creation | |
95 | wxPanel::Create( parent, id, pos, size, style ); | |
96 | ||
97 | CreateControls(); | |
98 | if (GetSizer()) | |
99 | { | |
100 | GetSizer()->SetSizeHints(this); | |
101 | } | |
102 | Centre(); | |
103 | ////@end wxRichTextFontPage creation | |
104 | return true; | |
105 | } | |
106 | ||
107 | /*! | |
108 | * Control creation for wxRichTextFontPage | |
109 | */ | |
110 | ||
111 | void wxRichTextFontPage::CreateControls() | |
112 | { | |
113 | ////@begin wxRichTextFontPage content construction | |
114 | wxRichTextFontPage* itemPanel1 = this; | |
115 | ||
116 | wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); | |
117 | itemPanel1->SetSizer(itemBoxSizer2); | |
118 | ||
119 | wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL); | |
120 | itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5); | |
121 | ||
122 | wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL); | |
123 | itemBoxSizer3->Add(itemBoxSizer4, 1, wxGROW, 5); | |
124 | ||
125 | wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL); | |
126 | itemBoxSizer4->Add(itemBoxSizer5, 1, wxGROW, 5); | |
127 | ||
128 | wxStaticText* itemStaticText6 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Font:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
129 | itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); | |
130 | ||
131 | m_faceTextCtrl = new wxTextCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_FACETEXTCTRL, _T(""), wxDefaultPosition, wxDefaultSize, 0 ); | |
132 | m_faceTextCtrl->SetHelpText(_("Type a font name.")); | |
133 | if (ShowToolTips()) | |
134 | m_faceTextCtrl->SetToolTip(_("Type a font name.")); | |
135 | itemBoxSizer5->Add(m_faceTextCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5); | |
136 | ||
137 | m_faceListBox = new wxRichTextFontListBox( itemPanel1, ID_RICHTEXTFONTPAGE_FACELISTBOX, wxDefaultPosition, wxSize(200, 140), wxSIMPLE_BORDER ); | |
138 | m_faceListBox->SetHelpText(_("Lists the available fonts.")); | |
139 | if (ShowToolTips()) | |
140 | m_faceListBox->SetToolTip(_("Lists the available fonts.")); | |
141 | itemBoxSizer5->Add(m_faceListBox, 1, wxGROW|wxALL|wxFIXED_MINSIZE, 5); | |
142 | ||
143 | wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxVERTICAL); | |
144 | itemBoxSizer4->Add(itemBoxSizer9, 0, wxGROW, 5); | |
145 | ||
146 | wxStaticText* itemStaticText10 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Size:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
147 | itemBoxSizer9->Add(itemStaticText10, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); | |
148 | ||
149 | m_sizeTextCtrl = new wxTextCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_SIZETEXTCTRL, _T(""), wxDefaultPosition, wxSize(50, -1), 0 ); | |
150 | m_sizeTextCtrl->SetHelpText(_("Type a size in points.")); | |
151 | if (ShowToolTips()) | |
152 | m_sizeTextCtrl->SetToolTip(_("Type a size in points.")); | |
153 | itemBoxSizer9->Add(m_sizeTextCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5); | |
154 | ||
155 | wxString* m_sizeListBoxStrings = NULL; | |
156 | m_sizeListBox = new wxListBox( itemPanel1, ID_RICHTEXTFONTPAGE_SIZELISTBOX, wxDefaultPosition, wxSize(50, -1), 0, m_sizeListBoxStrings, wxLB_SINGLE ); | |
157 | m_sizeListBox->SetHelpText(_("Lists font sizes in points.")); | |
158 | if (ShowToolTips()) | |
159 | m_sizeListBox->SetToolTip(_("Lists font sizes in points.")); | |
160 | itemBoxSizer9->Add(m_sizeListBox, 1, wxALIGN_CENTER_HORIZONTAL|wxALL|wxFIXED_MINSIZE, 5); | |
161 | ||
162 | wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL); | |
163 | itemBoxSizer3->Add(itemBoxSizer13, 0, wxGROW, 5); | |
164 | ||
165 | wxBoxSizer* itemBoxSizer14 = new wxBoxSizer(wxVERTICAL); | |
166 | itemBoxSizer13->Add(itemBoxSizer14, 1, wxGROW, 5); | |
167 | ||
168 | wxStaticText* itemStaticText15 = new wxStaticText( itemPanel1, wxID_STATIC, _("Font st&yle:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
169 | itemBoxSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); | |
170 | ||
171 | wxString* m_styleCtrlStrings = NULL; | |
172 | m_styleCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_STYLECTRL, _T(""), wxDefaultPosition, wxDefaultSize, 0, m_styleCtrlStrings, wxCB_READONLY ); | |
173 | m_styleCtrl->SetHelpText(_("Select regular or italic style.")); | |
174 | if (ShowToolTips()) | |
175 | m_styleCtrl->SetToolTip(_("Select regular or italic style.")); | |
176 | itemBoxSizer14->Add(m_styleCtrl, 0, wxGROW|wxALL, 5); | |
177 | ||
178 | wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxVERTICAL); | |
179 | itemBoxSizer13->Add(itemBoxSizer17, 1, wxGROW, 5); | |
180 | ||
181 | wxStaticText* itemStaticText18 = new wxStaticText( itemPanel1, wxID_STATIC, _("Font &weight:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
182 | itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); | |
183 | ||
184 | wxString* m_weightCtrlStrings = NULL; | |
185 | m_weightCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_WEIGHTCTRL, _T(""), wxDefaultPosition, wxDefaultSize, 0, m_weightCtrlStrings, wxCB_READONLY ); | |
186 | m_weightCtrl->SetHelpText(_("Select regular or bold.")); | |
187 | if (ShowToolTips()) | |
188 | m_weightCtrl->SetToolTip(_("Select regular or bold.")); | |
189 | itemBoxSizer17->Add(m_weightCtrl, 0, wxGROW|wxALL, 5); | |
190 | ||
191 | wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL); | |
192 | itemBoxSizer13->Add(itemBoxSizer20, 1, wxGROW, 5); | |
193 | ||
194 | wxStaticText* itemStaticText21 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Underlining:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
195 | itemBoxSizer20->Add(itemStaticText21, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); | |
196 | ||
197 | wxString* m_underliningCtrlStrings = NULL; | |
198 | m_underliningCtrl = new wxComboBox( itemPanel1, ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL, _T(""), wxDefaultPosition, wxDefaultSize, 0, m_underliningCtrlStrings, wxCB_READONLY ); | |
199 | m_underliningCtrl->SetHelpText(_("Select underlining or no underlining.")); | |
200 | if (ShowToolTips()) | |
201 | m_underliningCtrl->SetToolTip(_("Select underlining or no underlining.")); | |
202 | itemBoxSizer20->Add(m_underliningCtrl, 0, wxGROW|wxALL, 5); | |
203 | ||
204 | wxBoxSizer* itemBoxSizer23 = new wxBoxSizer(wxVERTICAL); | |
205 | itemBoxSizer13->Add(itemBoxSizer23, 0, wxGROW, 5); | |
206 | ||
207 | wxStaticText* itemStaticText24 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Colour:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
208 | itemBoxSizer23->Add(itemStaticText24, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); | |
209 | ||
210 | m_colourCtrl = new wxRichTextColourSwatchCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_COLOURCTRL, wxDefaultPosition, wxSize(40, 20), wxSIMPLE_BORDER ); | |
211 | m_colourCtrl->SetHelpText(_("Click to change the text colour.")); | |
212 | if (ShowToolTips()) | |
213 | m_colourCtrl->SetToolTip(_("Click to change the text colour.")); | |
214 | itemBoxSizer23->Add(m_colourCtrl, 0, wxALIGN_LEFT|wxALL, 5); | |
215 | ||
216 | itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); | |
217 | ||
218 | m_previewCtrl = new wxRichTextFontPreviewCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_PREVIEWCTRL, wxDefaultPosition, wxSize(100, 80), wxSIMPLE_BORDER ); | |
219 | m_previewCtrl->SetHelpText(_("Shows a preview of the font settings.")); | |
220 | if (ShowToolTips()) | |
221 | m_previewCtrl->SetToolTip(_("Shows a preview of the font settings.")); | |
222 | itemBoxSizer3->Add(m_previewCtrl, 0, wxGROW|wxALL, 5); | |
223 | ||
224 | ////@end wxRichTextFontPage content construction | |
225 | ||
226 | m_faceListBox->UpdateFonts(); | |
227 | ||
228 | m_styleCtrl->Append(_("Regular")); | |
229 | m_styleCtrl->Append(_("Italic")); | |
230 | ||
231 | m_weightCtrl->Append(_("Regular")); | |
232 | m_weightCtrl->Append(_("Bold")); | |
233 | ||
234 | m_underliningCtrl->Append(_("Not underlined")); | |
235 | m_underliningCtrl->Append(_("Underlined")); | |
236 | ||
237 | wxString nStr; | |
238 | int i; | |
239 | for (i = 8; i < 40; i++) | |
240 | { | |
241 | nStr.Printf(wxT("%d"), i); | |
242 | m_sizeListBox->Append(nStr); | |
243 | } | |
244 | m_sizeListBox->Append(wxT("48")); | |
245 | m_sizeListBox->Append(wxT("72")); | |
246 | } | |
247 | ||
248 | /// Transfer data from/to window | |
249 | bool wxRichTextFontPage::TransferDataFromWindow() | |
250 | { | |
251 | wxPanel::TransferDataFromWindow(); | |
252 | ||
253 | wxTextAttrEx* attr = GetAttributes(); | |
254 | ||
255 | if (m_faceListBox->GetSelection() != wxNOT_FOUND) | |
256 | { | |
257 | wxString faceName = m_faceListBox->GetFaceName(m_faceListBox->GetSelection()); | |
258 | if (!faceName.IsEmpty()) | |
259 | { | |
260 | wxFont font(attr->GetFont().Ok() ? attr->GetFont() : *wxNORMAL_FONT); | |
261 | font.SetFaceName(faceName); | |
262 | wxSetFontPreservingStyles(*attr, font); | |
263 | attr->SetFlags(attr->GetFlags() | wxTEXT_ATTR_FONT_FACE); | |
264 | } | |
265 | } | |
266 | else | |
267 | attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_FACE)); | |
268 | ||
269 | wxString strSize = m_sizeTextCtrl->GetValue(); | |
270 | if (!strSize.IsEmpty()) | |
271 | { | |
272 | int sz = wxAtoi(strSize); | |
273 | if (sz > 0) | |
274 | { | |
275 | wxFont font(attr->GetFont().Ok() ? attr->GetFont() : *wxNORMAL_FONT); | |
276 | font.SetPointSize(sz); | |
277 | wxSetFontPreservingStyles(*attr, font); | |
278 | attr->SetFlags(attr->GetFlags() | wxTEXT_ATTR_FONT_SIZE); | |
279 | } | |
280 | } | |
281 | else | |
282 | attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_SIZE)); | |
283 | ||
284 | if (m_styleCtrl->GetSelection() != wxNOT_FOUND) | |
285 | { | |
286 | int style; | |
287 | if (m_styleCtrl->GetStringSelection() == _("Italic")) | |
288 | style = wxITALIC; | |
289 | else | |
290 | style = wxNORMAL; | |
291 | ||
292 | wxFont font(attr->GetFont().Ok() ? attr->GetFont() : *wxNORMAL_FONT); | |
293 | font.SetStyle(style); | |
294 | wxSetFontPreservingStyles(*attr, font); | |
295 | attr->SetFlags(attr->GetFlags() | wxTEXT_ATTR_FONT_ITALIC); | |
296 | } | |
297 | else | |
298 | attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_ITALIC)); | |
299 | ||
300 | if (m_weightCtrl->GetSelection() != wxNOT_FOUND) | |
301 | { | |
302 | int weight; | |
303 | if (m_weightCtrl->GetStringSelection() == _("Bold")) | |
304 | weight = wxBOLD; | |
305 | else | |
306 | weight = wxNORMAL; | |
307 | ||
308 | wxFont font(attr->GetFont().Ok() ? attr->GetFont() : *wxNORMAL_FONT); | |
309 | font.SetWeight(weight); | |
310 | wxSetFontPreservingStyles(*attr, font); | |
311 | attr->SetFlags(attr->GetFlags() | wxTEXT_ATTR_FONT_WEIGHT); | |
312 | } | |
313 | else | |
314 | attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_WEIGHT)); | |
315 | ||
316 | if (m_underliningCtrl->GetSelection() != wxNOT_FOUND) | |
317 | { | |
318 | bool underlined; | |
319 | if (m_underliningCtrl->GetStringSelection() == _("Underlined")) | |
320 | underlined = true; | |
321 | else | |
322 | underlined = false; | |
323 | ||
324 | wxFont font(attr->GetFont().Ok() ? attr->GetFont() : *wxNORMAL_FONT); | |
325 | font.SetUnderlined(underlined); | |
326 | wxSetFontPreservingStyles(*attr, font); | |
327 | attr->SetFlags(attr->GetFlags() | wxTEXT_ATTR_FONT_UNDERLINE); | |
328 | } | |
329 | else | |
330 | attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_FONT_UNDERLINE)); | |
331 | ||
332 | if (m_colourPresent) | |
333 | { | |
334 | attr->SetTextColour(m_colourCtrl->GetBackgroundColour()); | |
335 | } | |
336 | else | |
337 | attr->SetFlags(attr->GetFlags() & (~ wxTEXT_ATTR_TEXT_COLOUR)); | |
338 | ||
339 | return true; | |
340 | } | |
341 | ||
342 | bool wxRichTextFontPage::TransferDataToWindow() | |
343 | { | |
344 | wxPanel::TransferDataToWindow(); | |
345 | ||
346 | m_dontUpdate = true; | |
347 | wxTextAttrEx* attr = GetAttributes(); | |
348 | ||
349 | if (attr->HasFont() && attr->HasFaceName()) | |
350 | { | |
351 | m_faceTextCtrl->SetValue(attr->GetFont().GetFaceName()); | |
352 | m_faceListBox->SetFaceNameSelection(attr->GetFont().GetFaceName()); | |
353 | } | |
354 | else | |
355 | { | |
356 | m_faceTextCtrl->SetValue(wxEmptyString); | |
357 | m_faceListBox->SetFaceNameSelection(wxEmptyString); | |
358 | } | |
359 | ||
360 | if (attr->HasFont() && attr->HasSize()) | |
361 | { | |
362 | wxString strSize = wxString::Format(wxT("%d"), attr->GetFont().GetPointSize()); | |
363 | m_sizeTextCtrl->SetValue(strSize); | |
364 | if (m_sizeListBox->FindString(strSize) != wxNOT_FOUND) | |
365 | m_sizeListBox->SetStringSelection(strSize); | |
366 | } | |
367 | else | |
368 | { | |
369 | m_sizeTextCtrl->SetValue(wxEmptyString); | |
370 | m_sizeListBox->SetSelection(wxNOT_FOUND); | |
371 | } | |
372 | ||
373 | if (attr->HasFont() && attr->HasWeight()) | |
374 | { | |
375 | if (attr->GetFont().GetWeight() == wxBOLD) | |
376 | m_weightCtrl->SetSelection(1); | |
377 | else | |
378 | m_weightCtrl->SetSelection(0); | |
379 | } | |
380 | else | |
381 | { | |
382 | m_weightCtrl->SetSelection(wxNOT_FOUND); | |
383 | } | |
384 | ||
385 | if (attr->HasFont() && attr->HasItalic()) | |
386 | { | |
387 | if (attr->GetFont().GetStyle() == wxITALIC) | |
388 | m_styleCtrl->SetSelection(1); | |
389 | else | |
390 | m_styleCtrl->SetSelection(0); | |
391 | } | |
392 | else | |
393 | { | |
394 | m_styleCtrl->SetSelection(wxNOT_FOUND); | |
395 | } | |
396 | ||
397 | if (attr->HasFont() && attr->HasUnderlined()) | |
398 | { | |
399 | if (attr->GetFont().GetUnderlined()) | |
400 | m_underliningCtrl->SetSelection(1); | |
401 | else | |
402 | m_underliningCtrl->SetSelection(0); | |
403 | } | |
404 | else | |
405 | { | |
406 | m_underliningCtrl->SetSelection(wxNOT_FOUND); | |
407 | } | |
408 | ||
409 | if (attr->HasTextColour()) | |
410 | { | |
411 | m_colourCtrl->SetBackgroundColour(attr->GetTextColour()); | |
412 | m_colourPresent = true; | |
413 | } | |
414 | ||
415 | UpdatePreview(); | |
416 | ||
417 | m_dontUpdate = false; | |
418 | ||
419 | return true; | |
420 | } | |
421 | ||
422 | wxTextAttrEx* wxRichTextFontPage::GetAttributes() | |
423 | { | |
424 | return wxRichTextFormattingDialog::GetDialogAttributes(this); | |
425 | } | |
426 | ||
427 | /// Updates the font preview | |
428 | void wxRichTextFontPage::UpdatePreview() | |
429 | { | |
430 | wxFont font(*wxNORMAL_FONT); | |
431 | ||
432 | if (m_colourPresent) | |
433 | m_previewCtrl->SetForegroundColour(m_colourCtrl->GetBackgroundColour()); | |
434 | ||
435 | if (m_faceListBox->GetSelection() != wxNOT_FOUND) | |
436 | { | |
437 | wxString faceName = m_faceListBox->GetFaceName(m_faceListBox->GetSelection()); | |
438 | font.SetFaceName(faceName); | |
439 | } | |
440 | ||
441 | wxString strSize = m_sizeTextCtrl->GetValue(); | |
442 | if (!strSize.IsEmpty()) | |
443 | { | |
444 | int sz = wxAtoi(strSize); | |
445 | if (sz > 0) | |
446 | font.SetPointSize(sz); | |
447 | } | |
448 | ||
449 | if (m_styleCtrl->GetSelection() != wxNOT_FOUND) | |
450 | { | |
451 | int style; | |
452 | if (m_styleCtrl->GetStringSelection() == _("Italic")) | |
453 | style = wxITALIC; | |
454 | else | |
455 | style = wxNORMAL; | |
456 | ||
457 | font.SetStyle(style); | |
458 | } | |
459 | ||
460 | if (m_weightCtrl->GetSelection() != wxNOT_FOUND) | |
461 | { | |
462 | int weight; | |
463 | if (m_weightCtrl->GetStringSelection() == _("Bold")) | |
464 | weight = wxBOLD; | |
465 | else | |
466 | weight = wxNORMAL; | |
467 | ||
468 | font.SetWeight(weight); | |
469 | } | |
470 | ||
471 | if (m_underliningCtrl->GetSelection() != wxNOT_FOUND) | |
472 | { | |
473 | bool underlined; | |
474 | if (m_underliningCtrl->GetStringSelection() == _("Underlined")) | |
475 | underlined = true; | |
476 | else | |
477 | underlined = false; | |
478 | ||
479 | font.SetUnderlined(underlined); | |
480 | } | |
481 | ||
482 | m_previewCtrl->SetFont(font); | |
483 | m_previewCtrl->Refresh(); | |
484 | } | |
485 | ||
486 | /*! | |
487 | * Should we show tooltips? | |
488 | */ | |
489 | ||
490 | bool wxRichTextFontPage::ShowToolTips() | |
491 | { | |
492 | return true; | |
493 | } | |
494 | ||
495 | /*! | |
496 | * Get bitmap resources | |
497 | */ | |
498 | ||
499 | wxBitmap wxRichTextFontPage::GetBitmapResource( const wxString& name ) | |
500 | { | |
501 | // Bitmap retrieval | |
502 | ////@begin wxRichTextFontPage bitmap retrieval | |
503 | wxUnusedVar(name); | |
504 | return wxNullBitmap; | |
505 | ////@end wxRichTextFontPage bitmap retrieval | |
506 | } | |
507 | ||
508 | /*! | |
509 | * Get icon resources | |
510 | */ | |
511 | ||
512 | wxIcon wxRichTextFontPage::GetIconResource( const wxString& name ) | |
513 | { | |
514 | // Icon retrieval | |
515 | ////@begin wxRichTextFontPage icon retrieval | |
516 | wxUnusedVar(name); | |
517 | return wxNullIcon; | |
518 | ////@end wxRichTextFontPage icon retrieval | |
519 | } | |
520 | ||
521 | /*! | |
522 | * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_FACETEXTCTRL | |
523 | */ | |
524 | ||
525 | void wxRichTextFontPage::OnFaceTextCtrlUpdated( wxCommandEvent& WXUNUSED(event) ) | |
526 | { | |
527 | if (m_dontUpdate) | |
528 | return; | |
529 | ||
530 | wxString facename = m_faceTextCtrl->GetValue(); | |
531 | if (!facename.IsEmpty()) | |
532 | { | |
533 | if (m_faceListBox->HasFaceName(facename)) | |
534 | { | |
535 | m_faceListBox->SetFaceNameSelection(facename); | |
536 | UpdatePreview(); | |
537 | } | |
538 | else | |
539 | { | |
540 | // Try to find a partial match | |
541 | const wxArrayString& arr = m_faceListBox->GetFaceNames(); | |
542 | size_t i; | |
543 | for (i = 0; i < arr.GetCount(); i++) | |
544 | { | |
545 | if (arr[i].Mid(0, facename.Length()).Lower() == facename.Lower()) | |
546 | { | |
547 | m_faceListBox->ScrollToLine(i); | |
548 | break; | |
549 | } | |
550 | } | |
551 | } | |
552 | } | |
553 | } | |
554 | ||
555 | ||
556 | /*! | |
557 | * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_RICHTEXTFONTPAGE_SIZETEXTCTRL | |
558 | */ | |
559 | ||
560 | void wxRichTextFontPage::OnSizeTextCtrlUpdated( wxCommandEvent& WXUNUSED(event) ) | |
561 | { | |
562 | if (m_dontUpdate) | |
563 | return; | |
564 | ||
565 | wxString strSize = m_sizeTextCtrl->GetValue(); | |
566 | if (!strSize.IsEmpty() && m_sizeListBox->FindString(strSize) != wxNOT_FOUND) | |
567 | m_sizeListBox->SetStringSelection(strSize); | |
568 | UpdatePreview(); | |
569 | } | |
570 | ||
571 | ||
572 | /*! | |
573 | * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_SIZELISTBOX | |
574 | */ | |
575 | ||
576 | void wxRichTextFontPage::OnSizeListBoxSelected( wxCommandEvent& event ) | |
577 | { | |
578 | m_dontUpdate = true; | |
579 | ||
580 | m_sizeTextCtrl->SetValue(event.GetString()); | |
581 | ||
582 | m_dontUpdate = false; | |
583 | ||
584 | UpdatePreview(); | |
585 | } | |
586 | ||
587 | /*! | |
588 | * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_FACELISTBOX | |
589 | */ | |
590 | ||
591 | void wxRichTextFontPage::OnFaceListBoxSelected( wxCommandEvent& WXUNUSED(event) ) | |
592 | { | |
593 | m_dontUpdate = true; | |
594 | ||
595 | m_faceTextCtrl->SetValue(m_faceListBox->GetFaceName(m_faceListBox->GetSelection())); | |
596 | ||
597 | m_dontUpdate = false; | |
598 | ||
599 | UpdatePreview(); | |
600 | } | |
601 | ||
602 | /*! | |
603 | * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_STYLECTRL | |
604 | */ | |
605 | ||
606 | void wxRichTextFontPage::OnStyleCtrlSelected( wxCommandEvent& WXUNUSED(event) ) | |
607 | { | |
608 | UpdatePreview(); | |
609 | } | |
610 | ||
611 | ||
612 | /*! | |
613 | * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_UNDERLINING_CTRL | |
614 | */ | |
615 | ||
616 | void wxRichTextFontPage::OnUnderliningCtrlSelected( wxCommandEvent& WXUNUSED(event) ) | |
617 | { | |
618 | UpdatePreview(); | |
619 | } | |
620 | ||
621 | ||
622 | /*! | |
623 | * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_RICHTEXTFONTPAGE_WEIGHTCTRL | |
624 | */ | |
625 | ||
626 | void wxRichTextFontPage::OnWeightCtrlSelected( wxCommandEvent& WXUNUSED(event) ) | |
627 | { | |
628 | UpdatePreview(); | |
629 | } | |
630 | ||
631 | void wxRichTextFontPage::OnColourClicked( wxCommandEvent& WXUNUSED(event) ) | |
632 | { | |
633 | m_colourPresent = true; | |
634 | ||
635 | UpdatePreview(); | |
636 | } |