]>
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" | |
9eddec69 | 33 | #include "wx/settings.h" |
ce5d92e1 | 34 | #include "wx/cmndata.h" |
ed2fbeb8 | 35 | #include "wx/sizer.h" |
c801d85f KB |
36 | #endif |
37 | ||
38 | #include <string.h> | |
39 | #include <stdlib.h> | |
40 | ||
c2c59b22 | 41 | #include "wx/fontdlg.h" |
23c47bc1 | 42 | #include "wx/generic/fontdlgg.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 | { |
cececf4d WS |
177 | m_useEvents = false; |
178 | m_previewer = NULL; | |
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 | { |
2229243b VZ |
193 | parent = GetParentForModalDialog(parent); |
194 | ||
195 | if ( !wxDialog::Create( parent , wxID_ANY , _T("Choose Font") , | |
196 | wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, | |
1bab9242 SC |
197 | _T("fontdialog") ) ) |
198 | { | |
199 | wxFAIL_MSG( wxT("wxFontDialog creation failed") ); | |
dabbc6a5 | 200 | return false; |
1bab9242 | 201 | } |
fc8eba27 | 202 | |
47e118ba RR |
203 | InitializeFont(); |
204 | CreateWidgets(); | |
dabbc6a5 | 205 | |
47e118ba | 206 | // sets initial font in preview area |
cececf4d | 207 | DoChangeFont(); |
dabbc6a5 DS |
208 | |
209 | return true; | |
c801d85f KB |
210 | } |
211 | ||
c2c59b22 | 212 | int wxGenericFontDialog::ShowModal() |
c801d85f | 213 | { |
1bab9242 | 214 | int ret = wxDialog::ShowModal(); |
c801d85f KB |
215 | |
216 | if (ret != wxID_CANCEL) | |
217 | { | |
cececf4d | 218 | m_fontData.m_chosenFont = m_dialogFont; |
c801d85f KB |
219 | } |
220 | ||
c35414db | 221 | return ret; |
c801d85f KB |
222 | } |
223 | ||
4566d7db JS |
224 | // This should be application-settable |
225 | static bool ShowToolTips() { return false; } | |
226 | ||
c2c59b22 | 227 | void wxGenericFontDialog::CreateWidgets() |
c801d85f | 228 | { |
cececf4d WS |
229 | wxString *families = new wxString[6], |
230 | *styles = new wxString[3], | |
231 | *weights = new wxString[3]; | |
47e118ba RR |
232 | families[0] = _("Roman"); |
233 | families[1] = _("Decorative"); | |
234 | families[2] = _("Modern"); | |
235 | families[3] = _("Script"); | |
236 | families[4] = _("Swiss" ); | |
237 | families[5] = _("Teletype" ); | |
238 | styles[0] = _("Normal"); | |
239 | styles[1] = _("Italic"); | |
240 | styles[2] = _("Slant"); | |
241 | weights[0] = _("Normal"); | |
242 | weights[1] = _("Light"); | |
243 | weights[2] = _("Bold"); | |
244 | ||
6b775e66 | 245 | #if !USE_SPINCTRL_FOR_POINT_SIZE |
47e118ba RR |
246 | wxString *pointSizes = new wxString[40]; |
247 | int i; | |
248 | for ( i = 0; i < 40; i++) | |
249 | { | |
250 | wxChar buf[5]; | |
251 | wxSprintf(buf, wxT("%d"), i + 1); | |
252 | pointSizes[i] = buf; | |
253 | } | |
6b775e66 | 254 | #endif |
c801d85f | 255 | |
4566d7db | 256 | // layout |
c801d85f | 257 | |
4566d7db JS |
258 | bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); |
259 | int noCols, noRows; | |
260 | if (is_pda) | |
261 | { | |
262 | noCols = 2; noRows = 3; | |
263 | } | |
264 | else | |
265 | { | |
266 | noCols = 3; noRows = 2; | |
267 | } | |
c801d85f | 268 | |
4566d7db JS |
269 | wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); |
270 | this->SetSizer(itemBoxSizer2); | |
cececf4d WS |
271 | this->SetAutoLayout(true); |
272 | ||
4566d7db JS |
273 | wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL); |
274 | itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5); | |
275 | ||
276 | wxFlexGridSizer* itemGridSizer4 = new wxFlexGridSizer(noRows, noCols, 0, 0); | |
277 | itemBoxSizer3->Add(itemGridSizer4, 0, wxGROW, 5); | |
278 | ||
279 | wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL); | |
280 | itemGridSizer4->Add(itemBoxSizer5, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5); | |
281 | wxStaticText* itemStaticText6 = new wxStaticText( this, wxID_STATIC, _("&Font family:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 282 | itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
4566d7db JS |
283 | |
284 | wxChoice* itemChoice7 = new wxChoice( this, wxID_FONT_FAMILY, wxDefaultPosition, wxDefaultSize, 5, families, 0 ); | |
285 | itemChoice7->SetHelpText(_("The font family.")); | |
286 | if (ShowToolTips()) | |
287 | itemChoice7->SetToolTip(_("The font family.")); | |
288 | itemBoxSizer5->Add(itemChoice7, 0, wxALIGN_LEFT|wxALL, 5); | |
289 | ||
290 | wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxVERTICAL); | |
291 | itemGridSizer4->Add(itemBoxSizer8, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5); | |
292 | wxStaticText* itemStaticText9 = new wxStaticText( this, wxID_STATIC, _("&Style:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 293 | itemBoxSizer8->Add(itemStaticText9, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
4566d7db JS |
294 | |
295 | wxChoice* itemChoice10 = new wxChoice( this, wxID_FONT_STYLE, wxDefaultPosition, wxDefaultSize, 3, styles, 0 ); | |
296 | itemChoice10->SetHelpText(_("The font style.")); | |
297 | if (ShowToolTips()) | |
298 | itemChoice10->SetToolTip(_("The font style.")); | |
299 | itemBoxSizer8->Add(itemChoice10, 0, wxALIGN_LEFT|wxALL, 5); | |
300 | ||
301 | wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxVERTICAL); | |
302 | itemGridSizer4->Add(itemBoxSizer11, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5); | |
303 | wxStaticText* itemStaticText12 = new wxStaticText( this, wxID_STATIC, _("&Weight:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 304 | itemBoxSizer11->Add(itemStaticText12, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
4566d7db JS |
305 | |
306 | wxChoice* itemChoice13 = new wxChoice( this, wxID_FONT_WEIGHT, wxDefaultPosition, wxDefaultSize, 3, weights, 0 ); | |
307 | itemChoice13->SetHelpText(_("The font weight.")); | |
308 | if (ShowToolTips()) | |
309 | itemChoice13->SetToolTip(_("The font weight.")); | |
310 | itemBoxSizer11->Add(itemChoice13, 0, wxALIGN_LEFT|wxALL, 5); | |
311 | ||
312 | wxBoxSizer* itemBoxSizer14 = new wxBoxSizer(wxVERTICAL); | |
313 | itemGridSizer4->Add(itemBoxSizer14, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5); | |
8ae6cfb6 KH |
314 | if (m_fontData.GetEnableEffects()) |
315 | { | |
316 | wxStaticText* itemStaticText15 = new wxStaticText( this, wxID_STATIC, _("C&olour:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 317 | itemBoxSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
cececf4d | 318 | |
94f53923 JS |
319 | wxSize colourSize = wxDefaultSize; |
320 | if (is_pda) | |
321 | colourSize.x = 100; | |
8ae6cfb6 | 322 | |
d6b30150 | 323 | wxChoice* itemChoice16 = new wxChoice( this, wxID_FONT_COLOUR, wxDefaultPosition, colourSize, NUM_COLS, wxColourDialogNames, 0 ); |
8ae6cfb6 KH |
324 | itemChoice16->SetHelpText(_("The font colour.")); |
325 | if (ShowToolTips()) | |
326 | itemChoice16->SetToolTip(_("The font colour.")); | |
327 | itemBoxSizer14->Add(itemChoice16, 0, wxALIGN_LEFT|wxALL, 5); | |
328 | } | |
4566d7db JS |
329 | |
330 | wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxVERTICAL); | |
331 | itemGridSizer4->Add(itemBoxSizer17, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5); | |
332 | wxStaticText* itemStaticText18 = new wxStaticText( this, wxID_STATIC, _("&Point size:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 333 | itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
4566d7db | 334 | |
6b775e66 | 335 | #if USE_SPINCTRL_FOR_POINT_SIZE |
cececf4d | 336 | wxSpinCtrl* spinCtrl = new wxSpinCtrl(this, wxID_FONT_SIZE, wxT("12"), wxDefaultPosition, wxSize(80, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 500, 12); |
6b775e66 JS |
337 | spinCtrl->SetHelpText(_("The font point size.")); |
338 | if (ShowToolTips()) | |
339 | spinCtrl->SetToolTip(_("The font point size.")); | |
cececf4d | 340 | |
6b775e66 JS |
341 | itemBoxSizer17->Add(spinCtrl, 0, wxALIGN_LEFT|wxALL, 5); |
342 | #else | |
4566d7db JS |
343 | wxChoice* itemChoice19 = new wxChoice( this, wxID_FONT_SIZE, wxDefaultPosition, wxDefaultSize, 40, pointSizes, 0 ); |
344 | itemChoice19->SetHelpText(_("The font point size.")); | |
345 | if (ShowToolTips()) | |
346 | itemChoice19->SetToolTip(_("The font point size.")); | |
347 | itemBoxSizer17->Add(itemChoice19, 0, wxALIGN_LEFT|wxALL, 5); | |
6b775e66 | 348 | #endif |
4566d7db | 349 | |
8ae6cfb6 KH |
350 | if (m_fontData.GetEnableEffects()) |
351 | { | |
352 | wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL); | |
353 | itemGridSizer4->Add(itemBoxSizer20, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5); | |
354 | wxCheckBox* itemCheckBox21 = new wxCheckBox( this, wxID_FONT_UNDERLINE, _("&Underline"), wxDefaultPosition, wxDefaultSize, 0 ); | |
cececf4d | 355 | itemCheckBox21->SetValue(false); |
8ae6cfb6 KH |
356 | itemCheckBox21->SetHelpText(_("Whether the font is underlined.")); |
357 | if (ShowToolTips()) | |
358 | itemCheckBox21->SetToolTip(_("Whether the font is underlined.")); | |
359 | itemBoxSizer20->Add(itemCheckBox21, 0, wxALIGN_LEFT|wxALL, 5); | |
360 | } | |
4566d7db | 361 | |
94f53923 JS |
362 | if (!is_pda) |
363 | itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); | |
4566d7db JS |
364 | |
365 | wxStaticText* itemStaticText23 = new wxStaticText( this, wxID_STATIC, _("Preview:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 366 | itemBoxSizer3->Add(itemStaticText23, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
cececf4d | 367 | |
4566d7db JS |
368 | wxFontPreviewer* itemWindow24 = new wxFontPreviewer( this ); |
369 | m_previewer = itemWindow24; | |
370 | itemWindow24->SetHelpText(_("Shows the font preview.")); | |
371 | if (ShowToolTips()) | |
372 | itemWindow24->SetToolTip(_("Shows the font preview.")); | |
6b775e66 | 373 | itemBoxSizer3->Add(itemWindow24, 1, wxGROW|wxALL, 5); |
4566d7db JS |
374 | |
375 | wxBoxSizer* itemBoxSizer25 = new wxBoxSizer(wxHORIZONTAL); | |
376 | itemBoxSizer3->Add(itemBoxSizer25, 0, wxGROW, 5); | |
377 | itemBoxSizer25->Add(5, 5, 1, wxGROW|wxALL, 5); | |
378 | ||
379 | #ifdef __WXMAC__ | |
380 | wxButton* itemButton28 = new wxButton( this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); | |
381 | if (ShowToolTips()) | |
382 | itemButton28->SetToolTip(_("Click to cancel the font selection.")); | |
383 | itemBoxSizer25->Add(itemButton28, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
384 | ||
385 | wxButton* itemButton27 = new wxButton( this, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 ); | |
386 | itemButton27->SetDefault(); | |
387 | itemButton27->SetHelpText(_("Click to confirm the font selection.")); | |
388 | if (ShowToolTips()) | |
389 | itemButton27->SetToolTip(_("Click to confirm the font selection.")); | |
390 | itemBoxSizer25->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
391 | #else | |
392 | wxButton* itemButton27 = new wxButton( this, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 ); | |
393 | itemButton27->SetDefault(); | |
394 | itemButton27->SetHelpText(_("Click to confirm the font selection.")); | |
395 | if (ShowToolTips()) | |
396 | itemButton27->SetToolTip(_("Click to confirm the font selection.")); | |
397 | itemBoxSizer25->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
398 | ||
399 | wxButton* itemButton28 = new wxButton( this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); | |
400 | if (ShowToolTips()) | |
401 | itemButton28->SetToolTip(_("Click to cancel the font selection.")); | |
402 | itemBoxSizer25->Add(itemButton28, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
403 | #endif | |
c801d85f | 404 | |
cececf4d WS |
405 | m_familyChoice = (wxChoice*) FindWindow(wxID_FONT_FAMILY); |
406 | m_styleChoice = (wxChoice*) FindWindow(wxID_FONT_STYLE); | |
407 | m_weightChoice = (wxChoice*) FindWindow(wxID_FONT_WEIGHT); | |
408 | m_colourChoice = (wxChoice*) FindWindow(wxID_FONT_COLOUR); | |
409 | m_underLineCheckBox = (wxCheckBox*) FindWindow(wxID_FONT_UNDERLINE); | |
410 | ||
411 | m_familyChoice->SetStringSelection( wxFontFamilyIntToString(m_dialogFont.GetFamily()) ); | |
412 | m_styleChoice->SetStringSelection(wxFontStyleIntToString(m_dialogFont.GetStyle())); | |
413 | m_weightChoice->SetStringSelection(wxFontWeightIntToString(m_dialogFont.GetWeight())); | |
414 | ||
415 | if (m_colourChoice) | |
8ae6cfb6 KH |
416 | { |
417 | wxString name(wxTheColourDatabase->FindName(m_fontData.GetColour())); | |
418 | if (name.length()) | |
cececf4d | 419 | m_colourChoice->SetStringSelection(name); |
8ae6cfb6 | 420 | else |
cececf4d | 421 | m_colourChoice->SetStringSelection(wxT("BLACK")); |
8ae6cfb6 | 422 | } |
cececf4d WS |
423 | |
424 | if (m_underLineCheckBox) | |
8ae6cfb6 | 425 | { |
cececf4d | 426 | m_underLineCheckBox->SetValue(m_dialogFont.GetUnderlined()); |
8ae6cfb6 KH |
427 | } |
428 | ||
6b775e66 | 429 | #if USE_SPINCTRL_FOR_POINT_SIZE |
cececf4d | 430 | spinCtrl->SetValue(m_dialogFont.GetPointSize()); |
6b775e66 | 431 | #else |
cececf4d WS |
432 | m_pointSizeChoice = (wxChoice*) FindWindow(wxID_FONT_SIZE); |
433 | m_pointSizeChoice->SetSelection(m_dialogFont.GetPointSize()-1); | |
6b775e66 | 434 | #endif |
c801d85f | 435 | |
94f53923 | 436 | GetSizer()->SetItemMinSize(m_previewer, is_pda ? 100 : 430, is_pda ? 40 : 100); |
4566d7db | 437 | GetSizer()->SetSizeHints(this); |
cececf4d | 438 | GetSizer()->Fit(this); |
47e118ba RR |
439 | |
440 | Centre(wxBOTH); | |
441 | ||
442 | delete[] families; | |
443 | delete[] styles; | |
444 | delete[] weights; | |
6b775e66 | 445 | #if !USE_SPINCTRL_FOR_POINT_SIZE |
47e118ba | 446 | delete[] pointSizes; |
6b775e66 | 447 | #endif |
dabbc6a5 | 448 | |
47e118ba | 449 | // Don't block events any more |
dabbc6a5 | 450 | m_useEvents = true; |
4566d7db | 451 | |
c801d85f KB |
452 | } |
453 | ||
c2c59b22 | 454 | void wxGenericFontDialog::InitializeFont() |
c801d85f | 455 | { |
47e118ba RR |
456 | int fontFamily = wxSWISS; |
457 | int fontWeight = wxNORMAL; | |
458 | int fontStyle = wxNORMAL; | |
459 | int fontSize = 12; | |
dabbc6a5 | 460 | bool fontUnderline = false; |
53cf79fa | 461 | |
47e118ba RR |
462 | if (m_fontData.m_initialFont.Ok()) |
463 | { | |
464 | fontFamily = m_fontData.m_initialFont.GetFamily(); | |
465 | fontWeight = m_fontData.m_initialFont.GetWeight(); | |
466 | fontStyle = m_fontData.m_initialFont.GetStyle(); | |
467 | fontSize = m_fontData.m_initialFont.GetPointSize(); | |
468 | fontUnderline = m_fontData.m_initialFont.GetUnderlined(); | |
469 | } | |
c801d85f | 470 | |
cececf4d WS |
471 | m_dialogFont = wxFont(fontSize, fontFamily, fontStyle, |
472 | fontWeight, fontUnderline); | |
c801d85f | 473 | |
47e118ba | 474 | if (m_previewer) |
cececf4d | 475 | m_previewer->SetFont(m_dialogFont); |
c801d85f KB |
476 | } |
477 | ||
478 | void wxGenericFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event)) | |
cececf4d WS |
479 | { |
480 | DoChangeFont(); | |
481 | } | |
482 | ||
483 | void wxGenericFontDialog::DoChangeFont() | |
c801d85f | 484 | { |
47e118ba | 485 | if (!m_useEvents) return; |
c35414db | 486 | |
cececf4d WS |
487 | int fontFamily = wxFontFamilyStringToInt(WXSTRINGCAST m_familyChoice->GetStringSelection()); |
488 | int fontWeight = wxFontWeightStringToInt(WXSTRINGCAST m_weightChoice->GetStringSelection()); | |
489 | int fontStyle = wxFontStyleStringToInt(WXSTRINGCAST m_styleChoice->GetStringSelection()); | |
6b775e66 JS |
490 | #if USE_SPINCTRL_FOR_POINT_SIZE |
491 | wxSpinCtrl* fontSizeCtrl = wxDynamicCast(FindWindow(wxID_FONT_SIZE), wxSpinCtrl); | |
492 | int fontSize = fontSizeCtrl->GetValue(); | |
493 | #else | |
cececf4d | 494 | int fontSize = wxAtoi(m_pointSizeChoice->GetStringSelection()); |
6b775e66 JS |
495 | #endif |
496 | ||
8ae6cfb6 | 497 | // Start with previous underline setting, we want to retain it even if we can't edit it |
cececf4d WS |
498 | // m_dialogFont is always initialized because of the call to InitializeFont |
499 | int fontUnderline = m_dialogFont.GetUnderlined(); | |
8ae6cfb6 | 500 | |
cececf4d | 501 | if (m_underLineCheckBox) |
8ae6cfb6 | 502 | { |
cececf4d | 503 | fontUnderline = m_underLineCheckBox->GetValue(); |
8ae6cfb6 | 504 | } |
c801d85f | 505 | |
cececf4d WS |
506 | m_dialogFont = wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0)); |
507 | m_previewer->SetFont(m_dialogFont); | |
8ae6cfb6 | 508 | |
cececf4d | 509 | if ( m_colourChoice ) |
c801d85f | 510 | { |
cececf4d | 511 | if ( !m_colourChoice->GetStringSelection().empty() ) |
47e118ba | 512 | { |
cececf4d | 513 | wxColour col = wxTheColourDatabase->Find(m_colourChoice->GetStringSelection()); |
8ae6cfb6 KH |
514 | if (col.Ok()) |
515 | { | |
516 | m_fontData.m_fontColour = col; | |
517 | } | |
47e118ba | 518 | } |
c801d85f | 519 | } |
8ae6cfb6 KH |
520 | // Update color here so that we can also use the color originally passed in |
521 | // (EnableEffects may be false) | |
522 | if (m_fontData.m_fontColour.Ok()) | |
523 | m_previewer->SetForegroundColour(m_fontData.m_fontColour); | |
cececf4d | 524 | |
47e118ba | 525 | m_previewer->Refresh(); |
c801d85f KB |
526 | } |
527 | ||
6b775e66 JS |
528 | #if USE_SPINCTRL_FOR_POINT_SIZE |
529 | void wxGenericFontDialog::OnChangeSize(wxSpinEvent& WXUNUSED(event)) | |
530 | { | |
cececf4d | 531 | DoChangeFont(); |
6b775e66 JS |
532 | } |
533 | #endif | |
534 | ||
d0060e77 | 535 | const wxChar *wxFontWeightIntToString(int weight) |
c801d85f | 536 | { |
cececf4d WS |
537 | switch (weight) |
538 | { | |
539 | case wxLIGHT: | |
540 | return wxT("Light"); | |
541 | case wxBOLD: | |
542 | return wxT("Bold"); | |
543 | case wxNORMAL: | |
544 | default: | |
545 | return wxT("Normal"); | |
546 | } | |
c801d85f KB |
547 | } |
548 | ||
d0060e77 | 549 | const wxChar *wxFontStyleIntToString(int style) |
c801d85f | 550 | { |
cececf4d WS |
551 | switch (style) |
552 | { | |
553 | case wxITALIC: | |
554 | return wxT("Italic"); | |
555 | case wxSLANT: | |
556 | return wxT("Slant"); | |
557 | case wxNORMAL: | |
558 | default: | |
559 | return wxT("Normal"); | |
560 | } | |
c801d85f KB |
561 | } |
562 | ||
d0060e77 | 563 | const wxChar *wxFontFamilyIntToString(int family) |
c801d85f | 564 | { |
cececf4d WS |
565 | switch (family) |
566 | { | |
567 | case wxROMAN: | |
568 | return wxT("Roman"); | |
569 | case wxDECORATIVE: | |
570 | return wxT("Decorative"); | |
571 | case wxMODERN: | |
572 | return wxT("Modern"); | |
573 | case wxSCRIPT: | |
574 | return wxT("Script"); | |
575 | case wxTELETYPE: | |
576 | return wxT("Teletype"); | |
577 | case wxSWISS: | |
578 | default: | |
579 | return wxT("Swiss"); | |
580 | } | |
c801d85f KB |
581 | } |
582 | ||
87138c52 | 583 | int wxFontFamilyStringToInt(wxChar *family) |
c801d85f | 584 | { |
cececf4d WS |
585 | if (!family) |
586 | return wxSWISS; | |
587 | ||
588 | if (wxStrcmp(family, wxT("Roman")) == 0) | |
589 | return wxROMAN; | |
590 | else if (wxStrcmp(family, wxT("Decorative")) == 0) | |
591 | return wxDECORATIVE; | |
592 | else if (wxStrcmp(family, wxT("Modern")) == 0) | |
593 | return wxMODERN; | |
594 | else if (wxStrcmp(family, wxT("Script")) == 0) | |
595 | return wxSCRIPT; | |
596 | else if (wxStrcmp(family, wxT("Teletype")) == 0) | |
597 | return wxTELETYPE; | |
598 | else return wxSWISS; | |
c801d85f KB |
599 | } |
600 | ||
87138c52 | 601 | int wxFontStyleStringToInt(wxChar *style) |
c801d85f | 602 | { |
cececf4d WS |
603 | if (!style) |
604 | return wxNORMAL; | |
605 | if (wxStrcmp(style, wxT("Italic")) == 0) | |
606 | return wxITALIC; | |
607 | else if (wxStrcmp(style, wxT("Slant")) == 0) | |
608 | return wxSLANT; | |
609 | else | |
610 | return wxNORMAL; | |
c801d85f KB |
611 | } |
612 | ||
87138c52 | 613 | int wxFontWeightStringToInt(wxChar *weight) |
c801d85f | 614 | { |
cececf4d WS |
615 | if (!weight) |
616 | return wxNORMAL; | |
617 | if (wxStrcmp(weight, wxT("Bold")) == 0) | |
618 | return wxBOLD; | |
619 | else if (wxStrcmp(weight, wxT("Light")) == 0) | |
620 | return wxLIGHT; | |
621 | else | |
622 | return wxNORMAL; | |
c801d85f KB |
623 | } |
624 | ||
3808e191 JS |
625 | #endif |
626 | // wxUSE_FONTDLG |