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