]> git.saurik.com Git - wxWidgets.git/blame - src/generic/fontdlgg.cpp
*really* updated the translations (last ommit didn't change anything)
[wxWidgets.git] / src / generic / fontdlgg.cpp
CommitLineData
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
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
c801d85f
KB
13#pragma implementation "fontdlgg.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
47e118ba 23#if wxUSE_FONTDLG && (!defined(__WXGTK__) || defined(__WXGPE__) || defined(__WXUNIVERSAL__))
4234ea8b 24
c801d85f 25#ifndef WX_PRECOMP
53cf79fa
VS
26 #include <stdio.h>
27 #include "wx/utils.h"
28 #include "wx/dialog.h"
29 #include "wx/listbox.h"
30 #include "wx/button.h"
31 #include "wx/stattext.h"
32 #include "wx/layout.h"
33 #include "wx/dcclient.h"
34 #include "wx/choice.h"
35 #include "wx/checkbox.h"
36 #include "wx/intl.h"
c801d85f
KB
37#endif
38
39#include <string.h>
40#include <stdlib.h>
41
42#include "wx/cmndata.h"
53cf79fa 43#include "wx/sizer.h"
c2c59b22 44#include "wx/fontdlg.h"
47e118ba 45#include "wx/settings.h"
c801d85f 46
53cf79fa
VS
47//-----------------------------------------------------------------------------
48// helper class - wxFontPreviewer
49//-----------------------------------------------------------------------------
50
51class WXDLLEXPORT wxFontPreviewer : public wxWindow
52{
53public:
54 wxFontPreviewer(wxWindow *parent) : wxWindow(parent, -1) {}
55
56private:
57 void OnPaint(wxPaintEvent& event);
58 DECLARE_EVENT_TABLE()
59};
60
61BEGIN_EVENT_TABLE(wxFontPreviewer, wxWindow)
62 EVT_PAINT(wxFontPreviewer::OnPaint)
63END_EVENT_TABLE()
64
65void wxFontPreviewer::OnPaint(wxPaintEvent& WXUNUSED(event))
66{
67 wxPaintDC dc(this);
68
69 wxSize size = GetSize();
70 wxFont font = GetFont();
71
72 dc.SetPen(*wxBLACK_PEN);
73 dc.SetBrush(*wxWHITE_BRUSH);
74 dc.DrawRectangle(0, 0, size.x, size.y);
75
76 if ( font.Ok() )
77 {
2b5f62a0 78 dc.SetFont(font);
53cf79fa
VS
79 // Calculate vertical centre
80 long w, h;
2b5f62a0 81 dc.GetTextExtent( wxT("X"), &w, &h);
53cf79fa
VS
82 dc.SetTextForeground(GetForegroundColour());
83 dc.SetClippingRegion(2, 2, size.x-4, size.y-4);
84 dc.DrawText(_("ABCDEFGabcdefg12345"),
2b5f62a0 85 10, size.y/2 - h/2);
53cf79fa
VS
86 dc.DestroyClippingRegion();
87 }
88}
89
90//-----------------------------------------------------------------------------
91// wxGenericFontDialog
92//-----------------------------------------------------------------------------
93
c801d85f
KB
94IMPLEMENT_DYNAMIC_CLASS(wxGenericFontDialog, wxDialog)
95
96BEGIN_EVENT_TABLE(wxGenericFontDialog, wxDialog)
c35414db
VZ
97 EVT_CHECKBOX(wxID_FONT_UNDERLINE, wxGenericFontDialog::OnChangeFont)
98 EVT_CHOICE(wxID_FONT_STYLE, wxGenericFontDialog::OnChangeFont)
99 EVT_CHOICE(wxID_FONT_WEIGHT, wxGenericFontDialog::OnChangeFont)
100 EVT_CHOICE(wxID_FONT_FAMILY, wxGenericFontDialog::OnChangeFont)
101 EVT_CHOICE(wxID_FONT_COLOUR, wxGenericFontDialog::OnChangeFont)
102 EVT_CHOICE(wxID_FONT_SIZE, wxGenericFontDialog::OnChangeFont)
c35414db 103 EVT_CLOSE(wxGenericFontDialog::OnCloseWindow)
c801d85f
KB
104END_EVENT_TABLE()
105
c801d85f
KB
106
107#define NUM_COLS 48
223d09f6
KB
108static wxString wxColourDialogNames[NUM_COLS]={wxT("ORANGE"),
109 wxT("GOLDENROD"),
110 wxT("WHEAT"),
111 wxT("SPRING GREEN"),
112 wxT("SKY BLUE"),
113 wxT("SLATE BLUE"),
114 wxT("MEDIUM VIOLET RED"),
115 wxT("PURPLE"),
116
117 wxT("RED"),
118 wxT("YELLOW"),
119 wxT("MEDIUM SPRING GREEN"),
120 wxT("PALE GREEN"),
121 wxT("CYAN"),
122 wxT("LIGHT STEEL BLUE"),
123 wxT("ORCHID"),
124 wxT("LIGHT MAGENTA"),
125
126 wxT("BROWN"),
127 wxT("YELLOW"),
128 wxT("GREEN"),
129 wxT("CADET BLUE"),
130 wxT("MEDIUM BLUE"),
131 wxT("MAGENTA"),
132 wxT("MAROON"),
133 wxT("ORANGE RED"),
134
135 wxT("FIREBRICK"),
136 wxT("CORAL"),
137 wxT("FOREST GREEN"),
138 wxT("AQUARAMINE"),
139 wxT("BLUE"),
140 wxT("NAVY"),
141 wxT("THISTLE"),
142 wxT("MEDIUM VIOLET RED"),
143
144 wxT("INDIAN RED"),
145 wxT("GOLD"),
146 wxT("MEDIUM SEA GREEN"),
147 wxT("MEDIUM BLUE"),
148 wxT("MIDNIGHT BLUE"),
149 wxT("GREY"),
150 wxT("PURPLE"),
151 wxT("KHAKI"),
152
153 wxT("BLACK"),
154 wxT("MEDIUM FOREST GREEN"),
155 wxT("KHAKI"),
156 wxT("DARK GREY"),
157 wxT("SEA GREEN"),
158 wxT("LIGHT GREY"),
159 wxT("MEDIUM SLATE BLUE"),
160 wxT("WHITE")
c35414db 161 };
c801d85f
KB
162
163/*
164 * Generic wxFontDialog
165 */
166
c2c59b22 167void wxGenericFontDialog::Init()
c801d85f 168{
66bd6b93 169 m_useEvents = FALSE;
53cf79fa 170 m_previewer = NULL;
1bab9242 171 Create( m_parent ) ;
c801d85f
KB
172}
173
c2c59b22 174wxGenericFontDialog::~wxGenericFontDialog()
c801d85f
KB
175{
176}
177
74e3313b 178void wxGenericFontDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
c801d85f 179{
47e118ba 180 EndModal(wxID_CANCEL);
c801d85f 181}
c35414db 182
c2c59b22 183bool wxGenericFontDialog::DoCreate(wxWindow *parent)
c801d85f 184{
1bab9242
SC
185 if ( !wxDialog::Create( parent , -1 , _T("Choose Font") , wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
186 _T("fontdialog") ) )
187 {
188 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
189 return FALSE;
190 }
fc8eba27 191
47e118ba
RR
192 InitializeFont();
193 CreateWidgets();
53cf79fa 194
47e118ba
RR
195 // sets initial font in preview area
196 wxCommandEvent dummy;
197 OnChangeFont(dummy);
2b5f62a0 198
47e118ba 199 return TRUE;
c801d85f
KB
200}
201
c2c59b22 202int wxGenericFontDialog::ShowModal()
c801d85f 203{
1bab9242 204 int ret = wxDialog::ShowModal();
c801d85f
KB
205
206 if (ret != wxID_CANCEL)
207 {
ae500232 208 m_fontData.m_chosenFont = dialogFont;
c801d85f
KB
209 }
210
c35414db 211 return ret;
c801d85f
KB
212}
213
c2c59b22 214void wxGenericFontDialog::CreateWidgets()
c801d85f 215{
47e118ba 216 wxString
36b3b54a 217 *families = new wxString[6],
59043ba2
KB
218 *styles = new wxString[3],
219 *weights = new wxString[3];
47e118ba
RR
220 families[0] = _("Roman");
221 families[1] = _("Decorative");
222 families[2] = _("Modern");
223 families[3] = _("Script");
224 families[4] = _("Swiss" );
225 families[5] = _("Teletype" );
226 styles[0] = _("Normal");
227 styles[1] = _("Italic");
228 styles[2] = _("Slant");
229 weights[0] = _("Normal");
230 weights[1] = _("Light");
231 weights[2] = _("Bold");
232
233 familyChoice = new wxChoice(this, wxID_FONT_FAMILY, wxDefaultPosition, wxDefaultSize, 5, families);
234 styleChoice = new wxChoice(this, wxID_FONT_STYLE, wxDefaultPosition, wxDefaultSize, 3, styles);
235 weightChoice = new wxChoice(this, wxID_FONT_WEIGHT, wxDefaultPosition, wxDefaultSize, 3, weights);
236
237 colourChoice = new wxChoice(this, wxID_FONT_COLOUR, wxDefaultPosition, wxDefaultSize, NUM_COLS, wxColourDialogNames);
238
239 wxString *pointSizes = new wxString[40];
240 int i;
241 for ( i = 0; i < 40; i++)
242 {
243 wxChar buf[5];
244 wxSprintf(buf, wxT("%d"), i + 1);
245 pointSizes[i] = buf;
246 }
c801d85f 247
47e118ba
RR
248 pointSizeChoice = new wxChoice(this, wxID_FONT_SIZE, wxDefaultPosition, wxDefaultSize, 40, pointSizes);
249 underLineCheckBox = new wxCheckBox(this, wxID_FONT_UNDERLINE, _("Underline"));
c801d85f 250
47e118ba 251 m_previewer = new wxFontPreviewer(this);
c801d85f 252
47e118ba
RR
253 wxButton *okButton = new wxButton(this, wxID_OK, _("OK"));
254 wxButton *cancelButton = new wxButton(this, wxID_CANCEL, _("Cancel"));
c801d85f 255
47e118ba
RR
256 familyChoice->SetStringSelection( wxFontFamilyIntToString(dialogFont.GetFamily()) );
257 styleChoice->SetStringSelection(wxFontStyleIntToString(dialogFont.GetStyle()));
258 weightChoice->SetStringSelection(wxFontWeightIntToString(dialogFont.GetWeight()));
259 wxString name(wxTheColourDatabase->FindName(m_fontData.GetColour()));
260 colourChoice->SetStringSelection(name);
c35414db 261
47e118ba
RR
262 underLineCheckBox->SetValue(dialogFont.GetUnderlined());
263 pointSizeChoice->SetSelection(dialogFont.GetPointSize()-1);
c801d85f 264
47e118ba 265 okButton->SetDefault();
c801d85f 266
47e118ba 267 // layout
53cf79fa 268
47e118ba 269 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
53cf79fa 270
47e118ba
RR
271
272 wxSizer *topsizer, *sizer;
273 topsizer = new wxBoxSizer(wxVERTICAL);
274
275 if (!is_pda)
276 {
277 // 2 row design
278 sizer = new wxBoxSizer(wxHORIZONTAL);
279 sizer->Add(familyChoice, 0, wxALIGN_CENTER | wxLEFT, 10);
280 sizer->Add(styleChoice, 0, wxALIGN_CENTER | wxLEFT, 10);
281 sizer->Add(weightChoice, 0, wxALIGN_CENTER | wxLEFT, 10);
282 topsizer->Add(sizer, 0, wxLEFT| wxTOP| wxRIGHT, 10);
283
284 sizer = new wxBoxSizer(wxHORIZONTAL);
285 sizer->Add(colourChoice, 0, wxALIGN_CENTER | wxLEFT, 10);
286 sizer->Add(pointSizeChoice, 0, wxALIGN_CENTER | wxLEFT, 10);
287 sizer->Add(underLineCheckBox, 0, wxALIGN_CENTER | wxLEFT, 10);
288 topsizer->Add(sizer, 0, wxLEFT| wxTOP| wxRIGHT, 10);
289 }
290 else
291 {
292 // 3 row design
293 sizer = new wxBoxSizer(wxHORIZONTAL);
294 sizer->Add(familyChoice, 0, wxALIGN_CENTER | wxLEFT, 10);
295 sizer->Add(styleChoice, 0, wxALIGN_CENTER | wxLEFT, 10);
296 topsizer->Add(sizer, 0, wxLEFT| wxTOP| wxRIGHT, 10);
297
298 sizer = new wxBoxSizer(wxHORIZONTAL);
299 sizer->Add(weightChoice, 0, wxALIGN_CENTER | wxLEFT, 10);
300 sizer->Add(colourChoice, 0, wxALIGN_CENTER | wxLEFT, 10);
301 topsizer->Add(sizer, 0, wxLEFT| wxTOP| wxRIGHT, 10);
302
303 sizer = new wxBoxSizer(wxHORIZONTAL);
304 sizer->Add(pointSizeChoice, 0, wxALIGN_CENTER | wxLEFT, 10);
305 sizer->Add(underLineCheckBox, 0, wxALIGN_CENTER | wxLEFT, 10);
306 topsizer->Add(sizer, 0, wxLEFT| wxTOP| wxRIGHT, 10);
307 }
53cf79fa 308
47e118ba
RR
309 topsizer->Add(m_previewer, 1, wxALL | wxEXPAND, 10);
310 topsizer->SetItemMinSize(m_previewer, 430, 100);
311
312 sizer = new wxBoxSizer(wxHORIZONTAL);
313 sizer->Add(okButton, 0, wxRIGHT, 10);
314 sizer->Add(cancelButton, 0, wxRIGHT, 10);
315 topsizer->Add(sizer, 0, wxALIGN_RIGHT | wxBOTTOM, 10);
316
317 SetAutoLayout(TRUE);
318 SetSizer(topsizer);
319 topsizer->SetSizeHints(this);
320 topsizer->Fit(this);
321
322 Centre(wxBOTH);
323
324 delete[] families;
325 delete[] styles;
326 delete[] weights;
327 delete[] pointSizes;
328
329 // Don't block events any more
330 m_useEvents = TRUE;
c801d85f
KB
331}
332
c2c59b22 333void wxGenericFontDialog::InitializeFont()
c801d85f 334{
47e118ba
RR
335 int fontFamily = wxSWISS;
336 int fontWeight = wxNORMAL;
337 int fontStyle = wxNORMAL;
338 int fontSize = 12;
339 int fontUnderline = FALSE;
53cf79fa 340
47e118ba
RR
341 if (m_fontData.m_initialFont.Ok())
342 {
343 fontFamily = m_fontData.m_initialFont.GetFamily();
344 fontWeight = m_fontData.m_initialFont.GetWeight();
345 fontStyle = m_fontData.m_initialFont.GetStyle();
346 fontSize = m_fontData.m_initialFont.GetPointSize();
347 fontUnderline = m_fontData.m_initialFont.GetUnderlined();
348 }
c801d85f 349
47e118ba 350 dialogFont = wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0));
c801d85f 351
47e118ba
RR
352 if (m_previewer)
353 m_previewer->SetFont(dialogFont);
c801d85f
KB
354}
355
356void wxGenericFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event))
357{
47e118ba 358 if (!m_useEvents) return;
c35414db 359
47e118ba
RR
360 int fontFamily = wxFontFamilyStringToInt(WXSTRINGCAST familyChoice->GetStringSelection());
361 int fontWeight = wxFontWeightStringToInt(WXSTRINGCAST weightChoice->GetStringSelection());
362 int fontStyle = wxFontStyleStringToInt(WXSTRINGCAST styleChoice->GetStringSelection());
363 int fontSize = wxAtoi(pointSizeChoice->GetStringSelection());
364 int fontUnderline = underLineCheckBox->GetValue();
c801d85f 365
47e118ba
RR
366 dialogFont = wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0));
367 m_previewer->SetFont(dialogFont);
368 if (colourChoice->GetStringSelection() != wxT(""))
c801d85f 369 {
47e118ba
RR
370 wxColour col = wxTheColourDatabase->Find(colourChoice->GetStringSelection());
371 if (col.Ok())
372 {
373 m_fontData.m_fontColour = col;
374 m_previewer->SetForegroundColour(col);
375 }
c801d85f 376 }
47e118ba 377 m_previewer->Refresh();
c801d85f
KB
378}
379
d0060e77 380const wxChar *wxFontWeightIntToString(int weight)
c801d85f
KB
381{
382 switch (weight)
383 {
384 case wxLIGHT:
223d09f6 385 return wxT("Light");
c801d85f 386 case wxBOLD:
223d09f6 387 return wxT("Bold");
c801d85f
KB
388 case wxNORMAL:
389 default:
223d09f6 390 return wxT("Normal");
c801d85f 391 }
c801d85f
KB
392}
393
d0060e77 394const wxChar *wxFontStyleIntToString(int style)
c801d85f
KB
395{
396 switch (style)
397 {
398 case wxITALIC:
223d09f6 399 return wxT("Italic");
c801d85f 400 case wxSLANT:
223d09f6 401 return wxT("Slant");
c801d85f
KB
402 case wxNORMAL:
403 default:
223d09f6 404 return wxT("Normal");
c801d85f 405 }
c801d85f
KB
406}
407
d0060e77 408const wxChar *wxFontFamilyIntToString(int family)
c801d85f
KB
409{
410 switch (family)
411 {
412 case wxROMAN:
223d09f6 413 return wxT("Roman");
c801d85f 414 case wxDECORATIVE:
223d09f6 415 return wxT("Decorative");
c801d85f 416 case wxMODERN:
223d09f6 417 return wxT("Modern");
c801d85f 418 case wxSCRIPT:
223d09f6 419 return wxT("Script");
36b3b54a 420 case wxTELETYPE:
223d09f6 421 return wxT("Teletype");
c801d85f
KB
422 case wxSWISS:
423 default:
223d09f6 424 return wxT("Swiss");
c801d85f 425 }
c801d85f
KB
426}
427
87138c52 428int wxFontFamilyStringToInt(wxChar *family)
c801d85f
KB
429{
430 if (!family)
431 return wxSWISS;
c35414db 432
223d09f6 433 if (wxStrcmp(family, wxT("Roman")) == 0)
c801d85f 434 return wxROMAN;
223d09f6 435 else if (wxStrcmp(family, wxT("Decorative")) == 0)
c801d85f 436 return wxDECORATIVE;
223d09f6 437 else if (wxStrcmp(family, wxT("Modern")) == 0)
c801d85f 438 return wxMODERN;
223d09f6 439 else if (wxStrcmp(family, wxT("Script")) == 0)
c801d85f 440 return wxSCRIPT;
223d09f6 441 else if (wxStrcmp(family, wxT("Teletype")) == 0)
36b3b54a 442 return wxTELETYPE;
c801d85f
KB
443 else return wxSWISS;
444}
445
87138c52 446int wxFontStyleStringToInt(wxChar *style)
c801d85f
KB
447{
448 if (!style)
449 return wxNORMAL;
223d09f6 450 if (wxStrcmp(style, wxT("Italic")) == 0)
c801d85f 451 return wxITALIC;
223d09f6 452 else if (wxStrcmp(style, wxT("Slant")) == 0)
c801d85f
KB
453 return wxSLANT;
454 else
455 return wxNORMAL;
456}
457
87138c52 458int wxFontWeightStringToInt(wxChar *weight)
c801d85f
KB
459{
460 if (!weight)
461 return wxNORMAL;
223d09f6 462 if (wxStrcmp(weight, wxT("Bold")) == 0)
c801d85f 463 return wxBOLD;
223d09f6 464 else if (wxStrcmp(weight, wxT("Light")) == 0)
c801d85f
KB
465 return wxLIGHT;
466 else
467 return wxNORMAL;
468}
469
3808e191
JS
470#endif
471 // wxUSE_FONTDLG
c801d85f 472