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