]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
c2c59b22 | 2 | // Name: src/generic/fontdlgg.cpp |
c801d85f KB |
3 | // Purpose: Generic font dialog |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
c801d85f KB |
13 | #pragma implementation "fontdlgg.h" |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
47e118ba | 23 | #if wxUSE_FONTDLG && (!defined(__WXGTK__) || defined(__WXGPE__) || defined(__WXUNIVERSAL__)) |
4234ea8b | 24 | |
c801d85f | 25 | #ifndef WX_PRECOMP |
53cf79fa VS |
26 | #include <stdio.h> |
27 | #include "wx/utils.h" | |
28 | #include "wx/dialog.h" | |
29 | #include "wx/listbox.h" | |
30 | #include "wx/button.h" | |
31 | #include "wx/stattext.h" | |
32 | #include "wx/layout.h" | |
33 | #include "wx/dcclient.h" | |
34 | #include "wx/choice.h" | |
35 | #include "wx/checkbox.h" | |
36 | #include "wx/intl.h" | |
c801d85f KB |
37 | #endif |
38 | ||
39 | #include <string.h> | |
40 | #include <stdlib.h> | |
41 | ||
42 | #include "wx/cmndata.h" | |
53cf79fa | 43 | #include "wx/sizer.h" |
c2c59b22 | 44 | #include "wx/fontdlg.h" |
23c47bc1 | 45 | #include "wx/generic/fontdlgg.h" |
47e118ba | 46 | #include "wx/settings.h" |
c801d85f | 47 | |
53cf79fa VS |
48 | //----------------------------------------------------------------------------- |
49 | // helper class - wxFontPreviewer | |
50 | //----------------------------------------------------------------------------- | |
51 | ||
52 | class WXDLLEXPORT wxFontPreviewer : public wxWindow | |
53 | { | |
54 | public: | |
94f53923 JS |
55 | wxFontPreviewer(wxWindow *parent, const wxSize& sz = wxDefaultSize) : wxWindow(parent, wxID_ANY, wxDefaultPosition, sz) |
56 | { | |
57 | } | |
53cf79fa VS |
58 | |
59 | private: | |
60 | void OnPaint(wxPaintEvent& event); | |
61 | DECLARE_EVENT_TABLE() | |
62 | }; | |
63 | ||
64 | BEGIN_EVENT_TABLE(wxFontPreviewer, wxWindow) | |
65 | EVT_PAINT(wxFontPreviewer::OnPaint) | |
66 | END_EVENT_TABLE() | |
67 | ||
68 | void wxFontPreviewer::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
69 | { | |
70 | wxPaintDC dc(this); | |
71 | ||
72 | wxSize size = GetSize(); | |
73 | wxFont font = GetFont(); | |
74 | ||
75 | dc.SetPen(*wxBLACK_PEN); | |
76 | dc.SetBrush(*wxWHITE_BRUSH); | |
77 | dc.DrawRectangle(0, 0, size.x, size.y); | |
78 | ||
79 | if ( font.Ok() ) | |
80 | { | |
2b5f62a0 | 81 | dc.SetFont(font); |
53cf79fa VS |
82 | // Calculate vertical centre |
83 | long w, h; | |
2b5f62a0 | 84 | dc.GetTextExtent( wxT("X"), &w, &h); |
53cf79fa VS |
85 | dc.SetTextForeground(GetForegroundColour()); |
86 | dc.SetClippingRegion(2, 2, size.x-4, size.y-4); | |
dabbc6a5 | 87 | dc.DrawText(_("ABCDEFGabcdefg12345"), |
2b5f62a0 | 88 | 10, size.y/2 - h/2); |
53cf79fa VS |
89 | dc.DestroyClippingRegion(); |
90 | } | |
91 | } | |
92 | ||
93 | //----------------------------------------------------------------------------- | |
94 | // wxGenericFontDialog | |
95 | //----------------------------------------------------------------------------- | |
96 | ||
c801d85f KB |
97 | IMPLEMENT_DYNAMIC_CLASS(wxGenericFontDialog, wxDialog) |
98 | ||
99 | BEGIN_EVENT_TABLE(wxGenericFontDialog, wxDialog) | |
c35414db VZ |
100 | EVT_CHECKBOX(wxID_FONT_UNDERLINE, wxGenericFontDialog::OnChangeFont) |
101 | EVT_CHOICE(wxID_FONT_STYLE, wxGenericFontDialog::OnChangeFont) | |
102 | EVT_CHOICE(wxID_FONT_WEIGHT, wxGenericFontDialog::OnChangeFont) | |
103 | EVT_CHOICE(wxID_FONT_FAMILY, wxGenericFontDialog::OnChangeFont) | |
104 | EVT_CHOICE(wxID_FONT_COLOUR, wxGenericFontDialog::OnChangeFont) | |
105 | EVT_CHOICE(wxID_FONT_SIZE, wxGenericFontDialog::OnChangeFont) | |
c35414db | 106 | EVT_CLOSE(wxGenericFontDialog::OnCloseWindow) |
c801d85f KB |
107 | END_EVENT_TABLE() |
108 | ||
c801d85f KB |
109 | |
110 | #define NUM_COLS 48 | |
223d09f6 KB |
111 | static wxString wxColourDialogNames[NUM_COLS]={wxT("ORANGE"), |
112 | wxT("GOLDENROD"), | |
113 | wxT("WHEAT"), | |
114 | wxT("SPRING GREEN"), | |
115 | wxT("SKY BLUE"), | |
116 | wxT("SLATE BLUE"), | |
117 | wxT("MEDIUM VIOLET RED"), | |
118 | wxT("PURPLE"), | |
119 | ||
120 | wxT("RED"), | |
121 | wxT("YELLOW"), | |
122 | wxT("MEDIUM SPRING GREEN"), | |
123 | wxT("PALE GREEN"), | |
124 | wxT("CYAN"), | |
125 | wxT("LIGHT STEEL BLUE"), | |
126 | wxT("ORCHID"), | |
127 | wxT("LIGHT MAGENTA"), | |
128 | ||
129 | wxT("BROWN"), | |
130 | wxT("YELLOW"), | |
131 | wxT("GREEN"), | |
132 | wxT("CADET BLUE"), | |
133 | wxT("MEDIUM BLUE"), | |
134 | wxT("MAGENTA"), | |
135 | wxT("MAROON"), | |
136 | wxT("ORANGE RED"), | |
137 | ||
138 | wxT("FIREBRICK"), | |
139 | wxT("CORAL"), | |
140 | wxT("FOREST GREEN"), | |
141 | wxT("AQUARAMINE"), | |
142 | wxT("BLUE"), | |
143 | wxT("NAVY"), | |
144 | wxT("THISTLE"), | |
145 | wxT("MEDIUM VIOLET RED"), | |
146 | ||
147 | wxT("INDIAN RED"), | |
148 | wxT("GOLD"), | |
149 | wxT("MEDIUM SEA GREEN"), | |
150 | wxT("MEDIUM BLUE"), | |
151 | wxT("MIDNIGHT BLUE"), | |
152 | wxT("GREY"), | |
153 | wxT("PURPLE"), | |
154 | wxT("KHAKI"), | |
155 | ||
156 | wxT("BLACK"), | |
157 | wxT("MEDIUM FOREST GREEN"), | |
158 | wxT("KHAKI"), | |
159 | wxT("DARK GREY"), | |
160 | wxT("SEA GREEN"), | |
161 | wxT("LIGHT GREY"), | |
162 | wxT("MEDIUM SLATE BLUE"), | |
163 | wxT("WHITE") | |
c35414db | 164 | }; |
c801d85f KB |
165 | |
166 | /* | |
167 | * Generic wxFontDialog | |
168 | */ | |
169 | ||
c2c59b22 | 170 | void wxGenericFontDialog::Init() |
c801d85f | 171 | { |
dabbc6a5 | 172 | m_useEvents = false; |
53cf79fa | 173 | m_previewer = NULL; |
1bab9242 | 174 | Create( m_parent ) ; |
c801d85f KB |
175 | } |
176 | ||
c2c59b22 | 177 | wxGenericFontDialog::~wxGenericFontDialog() |
c801d85f KB |
178 | { |
179 | } | |
180 | ||
74e3313b | 181 | void wxGenericFontDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
c801d85f | 182 | { |
47e118ba | 183 | EndModal(wxID_CANCEL); |
c801d85f | 184 | } |
c35414db | 185 | |
c2c59b22 | 186 | bool wxGenericFontDialog::DoCreate(wxWindow *parent) |
c801d85f | 187 | { |
dabbc6a5 | 188 | if ( !wxDialog::Create( parent , wxID_ANY , _T("Choose Font") , wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, |
1bab9242 SC |
189 | _T("fontdialog") ) ) |
190 | { | |
191 | wxFAIL_MSG( wxT("wxFontDialog creation failed") ); | |
dabbc6a5 | 192 | return false; |
1bab9242 | 193 | } |
fc8eba27 | 194 | |
47e118ba RR |
195 | InitializeFont(); |
196 | CreateWidgets(); | |
dabbc6a5 | 197 | |
47e118ba RR |
198 | // sets initial font in preview area |
199 | wxCommandEvent dummy; | |
200 | OnChangeFont(dummy); | |
dabbc6a5 DS |
201 | |
202 | return true; | |
c801d85f KB |
203 | } |
204 | ||
c2c59b22 | 205 | int wxGenericFontDialog::ShowModal() |
c801d85f | 206 | { |
1bab9242 | 207 | int ret = wxDialog::ShowModal(); |
c801d85f KB |
208 | |
209 | if (ret != wxID_CANCEL) | |
210 | { | |
ae500232 | 211 | m_fontData.m_chosenFont = dialogFont; |
c801d85f KB |
212 | } |
213 | ||
c35414db | 214 | return ret; |
c801d85f KB |
215 | } |
216 | ||
4566d7db JS |
217 | // This should be application-settable |
218 | static bool ShowToolTips() { return false; } | |
219 | ||
c2c59b22 | 220 | void wxGenericFontDialog::CreateWidgets() |
c801d85f | 221 | { |
47e118ba | 222 | wxString |
36b3b54a | 223 | *families = new wxString[6], |
59043ba2 KB |
224 | *styles = new wxString[3], |
225 | *weights = new wxString[3]; | |
47e118ba RR |
226 | families[0] = _("Roman"); |
227 | families[1] = _("Decorative"); | |
228 | families[2] = _("Modern"); | |
229 | families[3] = _("Script"); | |
230 | families[4] = _("Swiss" ); | |
231 | families[5] = _("Teletype" ); | |
232 | styles[0] = _("Normal"); | |
233 | styles[1] = _("Italic"); | |
234 | styles[2] = _("Slant"); | |
235 | weights[0] = _("Normal"); | |
236 | weights[1] = _("Light"); | |
237 | weights[2] = _("Bold"); | |
238 | ||
47e118ba RR |
239 | wxString *pointSizes = new wxString[40]; |
240 | int i; | |
241 | for ( i = 0; i < 40; i++) | |
242 | { | |
243 | wxChar buf[5]; | |
244 | wxSprintf(buf, wxT("%d"), i + 1); | |
245 | pointSizes[i] = buf; | |
246 | } | |
c801d85f | 247 | |
4566d7db | 248 | // layout |
c801d85f | 249 | |
4566d7db JS |
250 | bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); |
251 | int noCols, noRows; | |
252 | if (is_pda) | |
253 | { | |
254 | noCols = 2; noRows = 3; | |
255 | } | |
256 | else | |
257 | { | |
258 | noCols = 3; noRows = 2; | |
259 | } | |
c801d85f | 260 | |
4566d7db JS |
261 | wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); |
262 | this->SetSizer(itemBoxSizer2); | |
263 | this->SetAutoLayout(TRUE); | |
264 | ||
265 | wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL); | |
266 | itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5); | |
267 | ||
268 | wxFlexGridSizer* itemGridSizer4 = new wxFlexGridSizer(noRows, noCols, 0, 0); | |
269 | itemBoxSizer3->Add(itemGridSizer4, 0, wxGROW, 5); | |
270 | ||
271 | wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL); | |
272 | itemGridSizer4->Add(itemBoxSizer5, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5); | |
273 | wxStaticText* itemStaticText6 = new wxStaticText( this, wxID_STATIC, _("&Font family:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
274 | itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); | |
275 | ||
276 | wxChoice* itemChoice7 = new wxChoice( this, wxID_FONT_FAMILY, wxDefaultPosition, wxDefaultSize, 5, families, 0 ); | |
277 | itemChoice7->SetHelpText(_("The font family.")); | |
278 | if (ShowToolTips()) | |
279 | itemChoice7->SetToolTip(_("The font family.")); | |
280 | itemBoxSizer5->Add(itemChoice7, 0, wxALIGN_LEFT|wxALL, 5); | |
281 | ||
282 | wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxVERTICAL); | |
283 | itemGridSizer4->Add(itemBoxSizer8, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5); | |
284 | wxStaticText* itemStaticText9 = new wxStaticText( this, wxID_STATIC, _("&Style:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
285 | itemBoxSizer8->Add(itemStaticText9, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); | |
286 | ||
287 | wxChoice* itemChoice10 = new wxChoice( this, wxID_FONT_STYLE, wxDefaultPosition, wxDefaultSize, 3, styles, 0 ); | |
288 | itemChoice10->SetHelpText(_("The font style.")); | |
289 | if (ShowToolTips()) | |
290 | itemChoice10->SetToolTip(_("The font style.")); | |
291 | itemBoxSizer8->Add(itemChoice10, 0, wxALIGN_LEFT|wxALL, 5); | |
292 | ||
293 | wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxVERTICAL); | |
294 | itemGridSizer4->Add(itemBoxSizer11, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5); | |
295 | wxStaticText* itemStaticText12 = new wxStaticText( this, wxID_STATIC, _("&Weight:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
296 | itemBoxSizer11->Add(itemStaticText12, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); | |
297 | ||
298 | wxChoice* itemChoice13 = new wxChoice( this, wxID_FONT_WEIGHT, wxDefaultPosition, wxDefaultSize, 3, weights, 0 ); | |
299 | itemChoice13->SetHelpText(_("The font weight.")); | |
300 | if (ShowToolTips()) | |
301 | itemChoice13->SetToolTip(_("The font weight.")); | |
302 | itemBoxSizer11->Add(itemChoice13, 0, wxALIGN_LEFT|wxALL, 5); | |
303 | ||
304 | wxBoxSizer* itemBoxSizer14 = new wxBoxSizer(wxVERTICAL); | |
305 | itemGridSizer4->Add(itemBoxSizer14, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5); | |
8ae6cfb6 KH |
306 | if (m_fontData.GetEnableEffects()) |
307 | { | |
308 | wxStaticText* itemStaticText15 = new wxStaticText( this, wxID_STATIC, _("C&olour:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
309 | itemBoxSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); | |
94f53923 JS |
310 | |
311 | wxSize colourSize = wxDefaultSize; | |
312 | if (is_pda) | |
313 | colourSize.x = 100; | |
8ae6cfb6 KH |
314 | |
315 | wxChoice* itemChoice16 = new wxChoice( this, wxID_FONT_COLOUR, wxDefaultPosition, wxDefaultSize, NUM_COLS, wxColourDialogNames, 0 ); | |
316 | itemChoice16->SetHelpText(_("The font colour.")); | |
317 | if (ShowToolTips()) | |
318 | itemChoice16->SetToolTip(_("The font colour.")); | |
319 | itemBoxSizer14->Add(itemChoice16, 0, wxALIGN_LEFT|wxALL, 5); | |
320 | } | |
4566d7db JS |
321 | |
322 | wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxVERTICAL); | |
323 | itemGridSizer4->Add(itemBoxSizer17, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5); | |
324 | wxStaticText* itemStaticText18 = new wxStaticText( this, wxID_STATIC, _("&Point size:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
325 | itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); | |
326 | ||
327 | wxChoice* itemChoice19 = new wxChoice( this, wxID_FONT_SIZE, wxDefaultPosition, wxDefaultSize, 40, pointSizes, 0 ); | |
328 | itemChoice19->SetHelpText(_("The font point size.")); | |
329 | if (ShowToolTips()) | |
330 | itemChoice19->SetToolTip(_("The font point size.")); | |
331 | itemBoxSizer17->Add(itemChoice19, 0, wxALIGN_LEFT|wxALL, 5); | |
332 | ||
8ae6cfb6 KH |
333 | if (m_fontData.GetEnableEffects()) |
334 | { | |
335 | wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL); | |
336 | itemGridSizer4->Add(itemBoxSizer20, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5); | |
337 | wxCheckBox* itemCheckBox21 = new wxCheckBox( this, wxID_FONT_UNDERLINE, _("&Underline"), wxDefaultPosition, wxDefaultSize, 0 ); | |
338 | itemCheckBox21->SetValue(FALSE); | |
339 | itemCheckBox21->SetHelpText(_("Whether the font is underlined.")); | |
340 | if (ShowToolTips()) | |
341 | itemCheckBox21->SetToolTip(_("Whether the font is underlined.")); | |
342 | itemBoxSizer20->Add(itemCheckBox21, 0, wxALIGN_LEFT|wxALL, 5); | |
343 | } | |
4566d7db | 344 | |
94f53923 JS |
345 | if (!is_pda) |
346 | itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); | |
4566d7db JS |
347 | |
348 | wxStaticText* itemStaticText23 = new wxStaticText( this, wxID_STATIC, _("Preview:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
349 | itemBoxSizer3->Add(itemStaticText23, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); | |
94f53923 | 350 | |
4566d7db JS |
351 | wxFontPreviewer* itemWindow24 = new wxFontPreviewer( this ); |
352 | m_previewer = itemWindow24; | |
353 | itemWindow24->SetHelpText(_("Shows the font preview.")); | |
354 | if (ShowToolTips()) | |
355 | itemWindow24->SetToolTip(_("Shows the font preview.")); | |
356 | itemBoxSizer3->Add(itemWindow24, 0, wxGROW|wxALL, 5); | |
357 | ||
358 | wxBoxSizer* itemBoxSizer25 = new wxBoxSizer(wxHORIZONTAL); | |
359 | itemBoxSizer3->Add(itemBoxSizer25, 0, wxGROW, 5); | |
360 | itemBoxSizer25->Add(5, 5, 1, wxGROW|wxALL, 5); | |
361 | ||
362 | #ifdef __WXMAC__ | |
363 | wxButton* itemButton28 = new wxButton( this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); | |
364 | if (ShowToolTips()) | |
365 | itemButton28->SetToolTip(_("Click to cancel the font selection.")); | |
366 | itemBoxSizer25->Add(itemButton28, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
367 | ||
368 | wxButton* itemButton27 = new wxButton( this, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 ); | |
369 | itemButton27->SetDefault(); | |
370 | itemButton27->SetHelpText(_("Click to confirm the font selection.")); | |
371 | if (ShowToolTips()) | |
372 | itemButton27->SetToolTip(_("Click to confirm the font selection.")); | |
373 | itemBoxSizer25->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
374 | #else | |
375 | wxButton* itemButton27 = new wxButton( this, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 ); | |
376 | itemButton27->SetDefault(); | |
377 | itemButton27->SetHelpText(_("Click to confirm the font selection.")); | |
378 | if (ShowToolTips()) | |
379 | itemButton27->SetToolTip(_("Click to confirm the font selection.")); | |
380 | itemBoxSizer25->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
381 | ||
382 | wxButton* itemButton28 = new wxButton( this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); | |
383 | if (ShowToolTips()) | |
384 | itemButton28->SetToolTip(_("Click to cancel the font selection.")); | |
385 | itemBoxSizer25->Add(itemButton28, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
386 | #endif | |
c801d85f | 387 | |
4566d7db JS |
388 | familyChoice = (wxChoice*) FindWindow(wxID_FONT_FAMILY); |
389 | styleChoice = (wxChoice*) FindWindow(wxID_FONT_STYLE); | |
390 | weightChoice = (wxChoice*) FindWindow(wxID_FONT_WEIGHT); | |
391 | colourChoice = (wxChoice*) FindWindow(wxID_FONT_COLOUR); | |
392 | pointSizeChoice = (wxChoice*) FindWindow(wxID_FONT_SIZE); | |
393 | underLineCheckBox = (wxCheckBox*) FindWindow(wxID_FONT_UNDERLINE); | |
394 | ||
47e118ba RR |
395 | familyChoice->SetStringSelection( wxFontFamilyIntToString(dialogFont.GetFamily()) ); |
396 | styleChoice->SetStringSelection(wxFontStyleIntToString(dialogFont.GetStyle())); | |
397 | weightChoice->SetStringSelection(wxFontWeightIntToString(dialogFont.GetWeight())); | |
8ae6cfb6 KH |
398 | |
399 | if (colourChoice) | |
400 | { | |
401 | wxString name(wxTheColourDatabase->FindName(m_fontData.GetColour())); | |
402 | if (name.length()) | |
403 | colourChoice->SetStringSelection(name); | |
404 | else | |
405 | colourChoice->SetStringSelection(wxT("BLACK")); | |
406 | } | |
448971f3 | 407 | |
8ae6cfb6 KH |
408 | if (underLineCheckBox) |
409 | { | |
410 | underLineCheckBox->SetValue(dialogFont.GetUnderlined()); | |
411 | } | |
412 | ||
47e118ba | 413 | pointSizeChoice->SetSelection(dialogFont.GetPointSize()-1); |
c801d85f | 414 | |
94f53923 | 415 | GetSizer()->SetItemMinSize(m_previewer, is_pda ? 100 : 430, is_pda ? 40 : 100); |
4566d7db JS |
416 | GetSizer()->SetSizeHints(this); |
417 | GetSizer()->Fit(this); | |
47e118ba RR |
418 | |
419 | Centre(wxBOTH); | |
420 | ||
421 | delete[] families; | |
422 | delete[] styles; | |
423 | delete[] weights; | |
424 | delete[] pointSizes; | |
dabbc6a5 | 425 | |
47e118ba | 426 | // Don't block events any more |
dabbc6a5 | 427 | m_useEvents = true; |
4566d7db | 428 | |
c801d85f KB |
429 | } |
430 | ||
c2c59b22 | 431 | void wxGenericFontDialog::InitializeFont() |
c801d85f | 432 | { |
47e118ba RR |
433 | int fontFamily = wxSWISS; |
434 | int fontWeight = wxNORMAL; | |
435 | int fontStyle = wxNORMAL; | |
436 | int fontSize = 12; | |
dabbc6a5 | 437 | bool fontUnderline = false; |
53cf79fa | 438 | |
47e118ba RR |
439 | if (m_fontData.m_initialFont.Ok()) |
440 | { | |
441 | fontFamily = m_fontData.m_initialFont.GetFamily(); | |
442 | fontWeight = m_fontData.m_initialFont.GetWeight(); | |
443 | fontStyle = m_fontData.m_initialFont.GetStyle(); | |
444 | fontSize = m_fontData.m_initialFont.GetPointSize(); | |
445 | fontUnderline = m_fontData.m_initialFont.GetUnderlined(); | |
446 | } | |
c801d85f | 447 | |
dabbc6a5 DS |
448 | dialogFont = wxFont(fontSize, fontFamily, fontStyle, |
449 | fontWeight, fontUnderline); | |
c801d85f | 450 | |
47e118ba RR |
451 | if (m_previewer) |
452 | m_previewer->SetFont(dialogFont); | |
c801d85f KB |
453 | } |
454 | ||
455 | void wxGenericFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event)) | |
456 | { | |
47e118ba | 457 | if (!m_useEvents) return; |
c35414db | 458 | |
47e118ba RR |
459 | int fontFamily = wxFontFamilyStringToInt(WXSTRINGCAST familyChoice->GetStringSelection()); |
460 | int fontWeight = wxFontWeightStringToInt(WXSTRINGCAST weightChoice->GetStringSelection()); | |
461 | int fontStyle = wxFontStyleStringToInt(WXSTRINGCAST styleChoice->GetStringSelection()); | |
462 | int fontSize = wxAtoi(pointSizeChoice->GetStringSelection()); | |
8ae6cfb6 KH |
463 | // Start with previous underline setting, we want to retain it even if we can't edit it |
464 | // dialogFont is always initialized because of the call to InitializeFont | |
465 | int fontUnderline = dialogFont.GetUnderlined(); | |
466 | ||
467 | if (underLineCheckBox) | |
468 | { | |
469 | fontUnderline = underLineCheckBox->GetValue(); | |
470 | } | |
c801d85f | 471 | |
47e118ba RR |
472 | dialogFont = wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0)); |
473 | m_previewer->SetFont(dialogFont); | |
8ae6cfb6 KH |
474 | |
475 | if ( colourChoice ) | |
c801d85f | 476 | { |
8ae6cfb6 | 477 | if ( !colourChoice->GetStringSelection().empty() ) |
47e118ba | 478 | { |
8ae6cfb6 KH |
479 | wxColour col = wxTheColourDatabase->Find(colourChoice->GetStringSelection()); |
480 | if (col.Ok()) | |
481 | { | |
482 | m_fontData.m_fontColour = col; | |
483 | } | |
47e118ba | 484 | } |
c801d85f | 485 | } |
8ae6cfb6 KH |
486 | // Update color here so that we can also use the color originally passed in |
487 | // (EnableEffects may be false) | |
488 | if (m_fontData.m_fontColour.Ok()) | |
489 | m_previewer->SetForegroundColour(m_fontData.m_fontColour); | |
490 | ||
47e118ba | 491 | m_previewer->Refresh(); |
c801d85f KB |
492 | } |
493 | ||
d0060e77 | 494 | const wxChar *wxFontWeightIntToString(int weight) |
c801d85f KB |
495 | { |
496 | switch (weight) | |
497 | { | |
498 | case wxLIGHT: | |
223d09f6 | 499 | return wxT("Light"); |
c801d85f | 500 | case wxBOLD: |
223d09f6 | 501 | return wxT("Bold"); |
c801d85f KB |
502 | case wxNORMAL: |
503 | default: | |
223d09f6 | 504 | return wxT("Normal"); |
c801d85f | 505 | } |
c801d85f KB |
506 | } |
507 | ||
d0060e77 | 508 | const wxChar *wxFontStyleIntToString(int style) |
c801d85f KB |
509 | { |
510 | switch (style) | |
511 | { | |
512 | case wxITALIC: | |
223d09f6 | 513 | return wxT("Italic"); |
c801d85f | 514 | case wxSLANT: |
223d09f6 | 515 | return wxT("Slant"); |
c801d85f KB |
516 | case wxNORMAL: |
517 | default: | |
223d09f6 | 518 | return wxT("Normal"); |
c801d85f | 519 | } |
c801d85f KB |
520 | } |
521 | ||
d0060e77 | 522 | const wxChar *wxFontFamilyIntToString(int family) |
c801d85f KB |
523 | { |
524 | switch (family) | |
525 | { | |
526 | case wxROMAN: | |
223d09f6 | 527 | return wxT("Roman"); |
c801d85f | 528 | case wxDECORATIVE: |
223d09f6 | 529 | return wxT("Decorative"); |
c801d85f | 530 | case wxMODERN: |
223d09f6 | 531 | return wxT("Modern"); |
c801d85f | 532 | case wxSCRIPT: |
223d09f6 | 533 | return wxT("Script"); |
36b3b54a | 534 | case wxTELETYPE: |
223d09f6 | 535 | return wxT("Teletype"); |
c801d85f KB |
536 | case wxSWISS: |
537 | default: | |
223d09f6 | 538 | return wxT("Swiss"); |
c801d85f | 539 | } |
c801d85f KB |
540 | } |
541 | ||
87138c52 | 542 | int wxFontFamilyStringToInt(wxChar *family) |
c801d85f KB |
543 | { |
544 | if (!family) | |
545 | return wxSWISS; | |
c35414db | 546 | |
223d09f6 | 547 | if (wxStrcmp(family, wxT("Roman")) == 0) |
c801d85f | 548 | return wxROMAN; |
223d09f6 | 549 | else if (wxStrcmp(family, wxT("Decorative")) == 0) |
c801d85f | 550 | return wxDECORATIVE; |
223d09f6 | 551 | else if (wxStrcmp(family, wxT("Modern")) == 0) |
c801d85f | 552 | return wxMODERN; |
223d09f6 | 553 | else if (wxStrcmp(family, wxT("Script")) == 0) |
c801d85f | 554 | return wxSCRIPT; |
223d09f6 | 555 | else if (wxStrcmp(family, wxT("Teletype")) == 0) |
36b3b54a | 556 | return wxTELETYPE; |
c801d85f KB |
557 | else return wxSWISS; |
558 | } | |
559 | ||
87138c52 | 560 | int wxFontStyleStringToInt(wxChar *style) |
c801d85f KB |
561 | { |
562 | if (!style) | |
563 | return wxNORMAL; | |
223d09f6 | 564 | if (wxStrcmp(style, wxT("Italic")) == 0) |
c801d85f | 565 | return wxITALIC; |
223d09f6 | 566 | else if (wxStrcmp(style, wxT("Slant")) == 0) |
c801d85f KB |
567 | return wxSLANT; |
568 | else | |
569 | return wxNORMAL; | |
570 | } | |
571 | ||
87138c52 | 572 | int wxFontWeightStringToInt(wxChar *weight) |
c801d85f KB |
573 | { |
574 | if (!weight) | |
575 | return wxNORMAL; | |
223d09f6 | 576 | if (wxStrcmp(weight, wxT("Bold")) == 0) |
c801d85f | 577 | return wxBOLD; |
223d09f6 | 578 | else if (wxStrcmp(weight, wxT("Light")) == 0) |
c801d85f KB |
579 | return wxLIGHT; |
580 | else | |
581 | return wxNORMAL; | |
582 | } | |
583 | ||
3808e191 JS |
584 | #endif |
585 | // wxUSE_FONTDLG | |
c801d85f | 586 |