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